ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
Revision: 374
Committed: Sun Jun 10 06:21:47 2012 UTC (11 years, 5 months ago) by william
File size: 29408 byte(s)
Log Message:
+ handle keydown and scroll for ascii data

File Contents

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