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