ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
Revision: 351
Committed: Sat Jun 9 20:52:19 2012 UTC (10 years, 5 months ago) by william
File size: 26876 byte(s)
Log Message:

File Contents

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