ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
Revision: 576
Committed: Thu Jun 6 07:49:01 2013 UTC (10 years, 8 months ago) by william
File size: 27746 byte(s)
Log Message:

File Contents

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