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