/[RomCheater]/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
ViewVC logotype

Contents of /trunk/RomCheater/Docking/UI/UIMemoryViewer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 370 - (show annotations) (download)
Sun Jun 10 05:40:24 2012 UTC (8 years, 9 months ago) by william
File size: 28791 byte(s)
+ add support to write ascii character when memory region cannot be read

1 //#define DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS // when defined will not call GetFirstNonZeroByte() when AcceptedProcess is updated and is not null
2 #define DISABLE_GETFIRSTNONZERO_BYTE // when defined will make GetFirstNonZeroByte() an empty void method
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Drawing;
7 using System.Data;
8 using System.Linq;
9 using System.Text;
10 using System.Windows.Forms;
11 using Be.Windows.Forms;
12 using RomCheater.Logging;
13 using RomCheater.PluginFramework.Interfaces;
14 using System.Diagnostics;
15 using Sojaner.MemoryScanner.MemoryProviers;
16 using System.Runtime.InteropServices;
17 using RomCheater.PluginFramework.Events;
18 using Sojaner.MemoryScanner;
19
20 namespace RomCheater.Docking.UI
21 {
22 public partial class UIMemoryViewer : UserControl,
23 IAcceptsPlugin<IConfigPlugin>,
24 IAcceptsProcess<Process>,
25 IAcceptsProcessAndConfig,
26 IAcceptsMemoryRange,
27 IBrowseMemoryRegion,
28 IAcceptPEData
29 {
30
31 public delegate void SetTextDelegate(string text);
32 public void SetAsciiData(string text)
33 {
34 if (txtAscii.InvokeRequired)
35 {
36 SetTextDelegate std = new SetTextDelegate(SetAsciiData);
37 txtAscii.Invoke(std, text);
38 return;
39 }
40 txtAscii.Text = text;
41 }
42
43 public UIMemoryViewer()
44 {
45 InitializeComponent();
46 SetStyle(ControlStyles.UserPaint, true);
47 SetStyle(ControlStyles.DoubleBuffer, true);
48 SetStyle(ControlStyles.AllPaintingInWmPaint, true);
49 SetStyle(ControlStyles.ResizeRedraw, true);
50
51 //this.OnPCSX2ProcessCallback = new UIEvents.PCSX2ProcessCallback(this.PCSX2ProcessCallback);
52 //if (this.OnPCSX2ProcessCallback != null) { this.OnPCSX2ProcessCallback.Invoke(out procdata); }
53 this.UpdateEnabled = false;
54 txtData.BytesPerLine = (int)max_address_width;
55 txtData.UseFixedBytesPerLine = true;
56 //txtData.StringViewVisible = true;
57 ramScroll.Minimum = (int)MemoryRangeStart;
58 for (int i = MemoryRangeStart; i < (MemoryRangeStart + max_ram_view); i += max_address_width) { ramScroll.Maximum += (int)max_address_width; }
59 ramScroll.Value = ramScroll.Minimum;
60 this.CanChangeUpdateInterval = false;
61
62
63 lblAddressMarker.Text = "";
64 for (uint i = 0; i < max_address_width; i++)
65 {
66 lblAddressMarker.Text = lblAddressMarker.Text + string.Format("{0:X2} ", i);
67 }
68 this.AcceptedPlugin = null; this.AcceptedProcess = null;
69
70 txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel);
71 txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel);
72 }
73
74 private void GetFirstNonZeroByte()
75 {
76 #if !DISABLE_GETFIRSTNONZERO_BYTE
77 if (!DesignMode)
78 {
79 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
80 provider.OpenProvider();
81 int addr = 0;
82 provider.ReadFirstNonZeroByte(MemoryRangeStart, MemoryRangeSize, out addr);
83 provider.CloseProvider();
84 GotoAddress(addr);
85 }
86 #else
87 this.GotoImageBase();
88 #endif
89 }
90 #region IBrowseMemoryRegion
91 public bool BrowseMemoryRegion(int MemoryRegion)
92 {
93 try
94 {
95 if (!((MemoryRangeStart <= MemoryRegion) && (MemoryRegion <= (MemoryRangeStart + MemoryRangeSize)))) { return false; }
96 GotoAddress(MemoryRegion);
97 return true;
98 }
99 catch (Exception ex)
100 {
101 logger.Error.WriteLine("UIMemoryViewer.BrowseMemoryRegion(int MemoryRegion): Failed to Browse Memory Region: 0x{0:x8}", MemoryRegion);
102 logger.Error.WriteLine(ex.ToString());
103 return false;
104 }
105 }
106 #endregion
107 #region IAcceptsProcess<Process> Members
108 private Process _AcceptedProcess;
109 public Process AcceptedProcess
110 {
111 get { return _AcceptedProcess; }
112 set
113 {
114 _AcceptedProcess = value;
115 update_timer.Enabled = (value != null);
116 UpdateEnabled = update_timer.Enabled;
117 #if !DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS
118 if (value != null)
119 GetFirstNonZeroByte();
120 #endif
121 }
122 }
123 #endregion
124 #region IAcceptsPlugin<IConfigPlugin> Members
125 public IConfigPlugin AcceptedPlugin { get; set; }
126 #endregion
127 #region IAcceptsMemoryRange members
128 public int MemoryRangeStart { get { return MemorySizeConstants.MinimumAddress; } set { } }
129 public uint MemoryRangeSize { get { if (MemoryRangeStart > 0) { return (uint)(MemorySizeConstants.MaximumAddress - MemoryRangeStart); } return MemorySizeConstants.MaximumAddress; } set { } }
130 #endregion
131 #region IAcceptPEData members
132 private IPEDData peData { get; set; }
133 public void SetPEViewerData(IPEDData peData) { this.peData = peData; }
134 #endregion
135 public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
136 public void GotoBottom() { uint size = (uint)MemoryRangeSize; this.CURRENT_TOP_ADDR = (int)((size - 1) - max_ram_view); }
137 public void GotoAddress(int addr)
138 {
139 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoAddress(0x{0:x8})", addr);
140 this.CURRENT_TOP_ADDR = (int)(addr & 0xFFFFFFF0);
141 }
142 private bool _UpdateEnabled;
143 public bool UpdateEnabled
144 {
145 get { return _UpdateEnabled; }
146 set
147 {
148 _UpdateEnabled = value;
149 if (value) { this.update_timer.Enabled = true; }
150 else { this.update_timer.Enabled = false; }
151 }
152 }
153 private bool _CanChangeUpdateInterval;
154 public bool CanChangeUpdateInterval
155 {
156 get { return _CanChangeUpdateInterval; }
157 set { _CanChangeUpdateInterval = value; }
158 }
159
160 public int UpdateInterval
161 {
162 get { return this.update_timer.Interval; }
163 set { if (CanChangeUpdateInterval) this.update_timer.Interval = value; }
164 }
165 private string AddressList = "";
166 private string AsciiData = "";
167 private byte[] RamData = new byte[] { };
168
169 const int max_address_width = 16;
170 static int max_ram_view = max_address_width * 20;
171
172 static int small_scroll_change = max_address_width * 1; // scrolls one line (when you clikc the up or down arrows)
173 static int medium_scroll_change = max_ram_view / 2; // scrolls half a page
174 static int large_scroll_change = max_ram_view; // scrolls a full page
175 private int _CURRENT_TOP_ADDR;
176 int CURRENT_TOP_ADDR
177 {
178 get { return _CURRENT_TOP_ADDR; }
179 set { txthexGoto.Value = _CURRENT_TOP_ADDR = value; }
180 }
181 //uint CURRENT_BOITTOM_ADDR() { return CURRENT_TOP_ADDR + max_ram_view; }
182 private void UpdateMaxRamView()
183 {
184 if (this.IsDisposed) return;
185 Graphics g = this.CreateGraphics();
186 Size size = g.MeasureString("00", txtData.Font).ToSize();
187 int ByteHeight = size.Height;
188 int TotalHeight = txtData.Height;
189 int NumberOfBytes = (int)((TotalHeight / ByteHeight) * max_address_width) - max_address_width;
190 int byte_width = (max_address_width * 2);
191 max_ram_view = NumberOfBytes + (byte_width);
192 }
193 private void btnGotoAddress_Click(object sender, EventArgs e)
194 {
195 logger.VerboseDebug.WriteLine("UIMemoryViewer::btnGotoAddress_Click(0x{0:x8})", txthexGoto.ToInt32());
196 this.GotoAddress(txthexGoto.ToInt32());
197 }
198
199 private void btnEditBytes_Click(object sender, EventArgs e)
200 {
201 byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
202 logger.Info.WriteLine("UIMemoryViewer :: editing {0} bytes", data.Length);
203 bool reenable = false;
204 if (this.UpdateEnabled) reenable = true;
205 this.UpdateEnabled = false;
206 ByteEditor editor = new ByteEditor(data, this.CURRENT_TOP_ADDR);
207 editor.ShowDialog();
208 int changed_byte_count = 0;
209 if (editor.BytesEdited)
210 {
211
212 if (editor.AsBytes.Length == data.Length)
213 {
214
215 for (int i = 0; i < data.Length; i++)
216 {
217 if (data[i] != editor.AsBytes[i])
218 changed_byte_count++;
219 }
220 }
221 //DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(editor.AsBytes);
222 //txtData.ByteProvider = _DynamicByteProvider;
223 //_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed);
224 this.WriteCurrentBytes(this.CURRENT_TOP_ADDR, editor.AsBytes);
225 }
226 logger.Info.WriteLine("UIMemoryViewer :: changed {0} bytes", changed_byte_count);
227 this.UpdateEnabled = reenable;
228 }
229 private bool ForceUpdate = false;
230 private bool ShouldUpdateResults()
231 {
232 //if (ResultsUpdateWorkerThread.IsBusy) { return false; }
233 if (ForceUpdate) return true;
234 //else if (TextIsBeingSelected) return false;
235 //else if (NonHandledKeysAreBeingPressed) return false;
236 else if (this.UpdateEnabled) return true;
237 else { return false; }
238 }
239 private void UpdateGui(bool force)
240 {
241 if (AcceptedProcess == null) { return; }
242 if (AcceptedPlugin == null) { return; }
243
244 if (!this.ShouldUpdateResults()) { return; }// this.Logger.LogDebugMessage(string.Format("ShouldUpdateResults() -> returning false")); return; }
245 this.UpdateMaxRamView();
246 //if (!force)
247 //{
248 if (!ResultsUpdateWorkerThread.IsBusy)
249 ResultsUpdateWorkerThread.RunWorkerAsync();
250 //}
251 //else
252 //{
253 // while (!ResultsUpdateWorkerThread.IsBusy) { ResultsUpdateWorkerThread.CancelAsync(); Application.DoEvents(); }
254 // ResultsUpdateWorkerThread.RunWorkerAsync();
255 //}
256 }
257 private void UpdateGui()
258 {
259 this.UpdateGui(false);
260 }
261 private byte[] GetMemory()
262 {
263 byte[] data = new byte[max_ram_view];
264 try
265 {
266 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
267 provider.OpenProvider();
268 int bytesReadSize;
269 provider.ReadProcessMemory(CURRENT_TOP_ADDR, (uint)max_ram_view, out bytesReadSize, out data);
270 try
271 {
272 provider.CloseProvider();
273 }
274 catch (SEHException ex)
275 {
276 logger.Error.WriteLine("UIMemoryViewer.GetMemory(): SEHException: (0x{0:x8} {1}", ex.ErrorCode, ex.Message);
277 logger.Error.WriteLine(ex.ToString());
278 }
279 catch (Exception ex)
280 {
281 logger.Error.WriteLine("UIMemoryViewer.GetMemory(): Exception: {0}", ex.Message);
282 logger.Error.WriteLine(ex.ToString());
283 }
284 }
285 catch (Exception ex)
286 {
287 logger.Error.WriteLine("{0}.GetMemory():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
288 }
289 finally
290 {
291 if (data.Length == 0)
292 {
293 data = new byte[max_ram_view];
294 for (int i = 0; i < data.Length; i++) { data[i] = 0x0; }
295 }
296 }
297 return data;
298 }
299 private void UpdateMemroyView() { this.UpdateMemroyView(this.CURRENT_TOP_ADDR); }
300 private void UpdateMemroyView(int address)
301 {
302 try
303 {
304 if (AcceptedProcess == null) { return; }
305 if (AcceptedPlugin == null) { return; }
306
307 byte[] data = GetMemory();
308 RamData = data;
309 #region old ascii-code
310 try
311 {
312 AddressList = "";
313 AsciiData = "";
314 // write the addreses out
315 for (int i = address; i < (address + max_ram_view); i += max_address_width)
316 {
317 AddressList = AddressList + string.Format("{0:X8}:\n", i);
318 }
319 //// write out the ascii data
320 StringBuilder builder = new StringBuilder();
321 int count = 0;
322 for (int i = 0; i < (0 + max_ram_view); i += max_address_width)
323 {
324 try
325 {
326 //bool NoAccessRegion = false;
327 //// preprocess line
328 //for (int j = 0; j < max_address_width; j++)
329 //{
330 // byte t = data[j];
331 // NoAccessRegion = (t == 0);
332 //}
333 for (int j = 0; j < max_address_width; j++)
334 {
335 int current_real_address = address + j +i;
336 int current_addr = i + j;
337 if (current_addr >= MemoryRangeSize) break;
338
339 byte ascii_value_raw = data[current_addr];
340 char ascii_value;
341 //if (ascii_value_raw == (byte)'?')
342 //{
343 // ascii_value_raw = 0;
344 // ascii_value = '?';
345 // RamData[count] = 0;
346 //}
347 //else
348 //{
349 // ascii_value = (char)data[j];
350 //}
351
352 if (ascii_value_raw >= 0x20 && ascii_value_raw <= 0x7e)
353 {
354 ascii_value = (char)data[current_addr];
355 }
356 else
357 {
358 ascii_value = '.';
359 }
360
361 GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
362 gmp.OpenProvider();
363 byte t;
364 if (!gmp.ReadMemory(current_real_address, out t)) { ascii_value = '?'; }
365 gmp.CloseProvider();
366
367
368 builder.Append(ascii_value.ToString());
369 }
370 builder.AppendLine();
371 }
372 catch (Exception ex)
373 {
374 logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
375 return;
376 }
377 count++;
378 }
379 AsciiData = builder.ToString();
380 }
381 catch (Exception ex)
382 {
383 logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
384 return;
385 }
386 #endregion
387 }
388 catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
389 }
390 //private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e)
391 //{
392 // this.WriteCurrentBytes();
393 //}
394 private void WriteCurrentBytes(int start_address, byte[] data)
395 {
396 try
397 {
398 if (AcceptedProcess == null) { return; }
399 if (AcceptedPlugin == null) { return; }
400 // Byte changed
401 //byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
402 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
403 provider.OpenProvider();
404 int bytesReadSize;
405
406 provider.WriteProcessMemory(start_address, data, out bytesReadSize);
407 //for (int i = 0; i < data.Length; i ++)
408 //{
409 // int addr = (int)(start_address + i);
410 // byte data_to_write = data[i];
411
412 //}
413 provider.CloseProvider();
414 }
415 catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
416 }
417
418 private void update_timer_Tick(object sender, EventArgs e) { this.UpdateGui(); }
419 private void ResultsUpdateWorkerThread_DoWork(object sender, DoWorkEventArgs e) { try { this.UpdateMemroyView(); } catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_DoWork():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } }
420 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
421 {
422 try
423 {
424 txtAddresses.Clear(); txtAddresses.Text = AddressList;
425 txtAscii.Clear(); txtAscii.Text = AsciiData;
426 //this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length));
427 DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData);
428 txtData.ByteProvider = _DynamicByteProvider;
429 //_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed);
430 }
431 catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes)
432 catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
433 }
434 private void Handle_KeyDown(object sender, KeyEventArgs e)
435 {
436 //isScrolling = false;
437 //bool reenable = false;
438 //if (this.UpdateEnabled) reenable = true;
439 //this.UpdateEnabled = false;
440
441 this.UpdateMaxRamView();
442 int ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
443
444 ////if (e.Type == ScrollEventType.EndScroll) return;
445 //uint size = max_ram_view;
446
447 bool haveModifier = false;
448 switch (e.Modifiers)
449 {
450 case Keys.Control:
451 switch (e.KeyCode)
452 {
453 case Keys.Home:
454 this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false;
455 break;
456 case Keys.End:
457 this.CURRENT_TOP_ADDR = (int)((MemoryRangeSize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false;
458 break;
459 default:
460 //NonHandledKeysAreBeingPressed = true;
461 break;
462 }
463 break;
464 }
465
466 if (!haveModifier)
467 {
468 switch (e.KeyCode)
469 {
470 case Keys.Up:
471 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR))
472 {
473 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
474 }
475 else
476 {
477 this.CURRENT_TOP_ADDR -= (int)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
478 }
479 break;
480 case Keys.Down:
481 this.CURRENT_TOP_ADDR += (int)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
482 break;
483 case Keys.PageUp:
484 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR))
485 {
486 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
487 }
488 else
489 {
490 this.CURRENT_TOP_ADDR -= (int)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
491 }
492 break;
493 case Keys.PageDown:
494 this.CURRENT_TOP_ADDR += (int)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
495 break;
496 default:
497 //NonHandledKeysAreBeingPressed = true;
498 break;
499 }
500 }
501 if (this.CURRENT_TOP_ADDR < MemoryRangeStart) this.CURRENT_TOP_ADDR = MemoryRangeStart;
502 //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
503 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
504
505 //this.UpdateEnabled = reenable;
506 }
507
508 private void UIMemoryViewer_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
509 private void txtAddresses_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
510 private void txtData_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
511
512 private void ramScroll_Scroll(object sender, ScrollEventArgs e) { this.Handle_Scroll(sender, e); }
513
514 private ScrollEventArgs GetMouseWheelScrollChange(int WheelDelta)
515 {
516 ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
517 if (WheelDelta < 0)
518 {
519 //// negative: scroll down
520 //// SmallDecrement -or- LargeDecrement
521 //if (WheelDelta <= small_scroll_change)
522 //{
523 // args = new ScrollEventArgs(ScrollEventType.SmallDecrement,(int)small_scroll_change);
524 //}
525 //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
526 //{
527 // args = new ScrollEventArgs(ScrollEventType.LargeDecrement, (int)large_scroll_change);
528 //}
529 args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
530 }
531 else
532 {
533 //// positive: scroll up
534 //// SmallIncrement -or- LargeIncrement
535 //if (WheelDelta <= small_scroll_change)
536 //{
537 // args = new ScrollEventArgs(ScrollEventType.SmallIncrement, (int)small_scroll_change);
538 //}
539 //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
540 //{
541 // args = new ScrollEventArgs(ScrollEventType.LargeIncrement, (int)large_scroll_change);
542 //}
543 args = new ScrollEventArgs(ScrollEventType.SmallDecrement, 1);
544 }
545 return args;
546 }
547
548 void txtAddresses_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
549 void txtData_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
550
551
552 private void Handle_Scroll(object sender, ScrollEventArgs e)
553 {
554 //isScrolling = true;
555 //bool reenable = false;
556 //if (this.UpdateEnabled) reenable = true;
557 //this.UpdateEnabled = false;
558
559 this.UpdateMaxRamView();
560 int ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
561 //uint size = MemorySize;
562 if (e.Type == ScrollEventType.EndScroll) return;
563
564 switch (e.Type)
565 {
566 case ScrollEventType.SmallDecrement:
567 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - small_scroll_change) > this.CURRENT_TOP_ADDR))
568 {
569 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
570 }
571 else
572 {
573 this.CURRENT_TOP_ADDR -= (small_scroll_change);
574 }
575 break;
576 case ScrollEventType.SmallIncrement:
577 this.CURRENT_TOP_ADDR += (small_scroll_change);
578 break;
579
580 case ScrollEventType.LargeDecrement:
581 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - large_scroll_change) > this.CURRENT_TOP_ADDR))
582 {
583 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
584 }
585 else
586 {
587 this.CURRENT_TOP_ADDR -= (large_scroll_change);
588 }
589 break;
590 case ScrollEventType.LargeIncrement:
591 this.CURRENT_TOP_ADDR += (large_scroll_change);
592 break;
593 case ScrollEventType.ThumbPosition:
594 //this.CURRENT_TOP_ADDR = (uint)e.NewValue;
595 //break;
596 default:
597 this.CURRENT_TOP_ADDR = (int)(e.NewValue & 0xFFFFFFF0);
598 break;
599 }
600 if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0;
601 //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view;
602 //if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
603 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (int)(MemoryRangeSize - max_ram_view);
604 //this.UpdateEnabled = reenable;
605 //isScrolling = false;
606 }
607 private void GotoImageBase()
608 {
609 if (this.peData == null) return;
610 object ImageBase = 0;
611 bool x86 = this.peData.Is32bitAssembly();
612 if (x86)
613 {
614 ImageBase = this.peData.NTHeader.OptionalHeader32._ImageBase;
615 uint ib = Convert.ToUInt32(ImageBase);
616 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x8})", ib);
617 txthexGoto.Value = ib;
618 }
619 else
620 {
621 ImageBase = this.peData.NTHeader.OptionalHeader64._ImageBase;
622 ulong ib = Convert.ToUInt64(ImageBase);
623 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x16})", ib);
624 txthexGoto.Value = (long)ib;
625 }
626
627 this.GotoAddress(txthexGoto.ToInt32());
628 }
629 private void btnGotoImageBase_Click(object sender, EventArgs e)
630 {
631
632 this.GotoImageBase();
633 }
634
635 }
636 }

  ViewVC Help
Powered by ViewVC 1.1.22