/[RomCheater]/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Docking/UI/UIMemoryViewer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 370 - (hide annotations) (download)
Sun Jun 10 05:40:24 2012 UTC (9 years, 11 months ago) by william
File size: 28791 byte(s)
+ add support to write ascii character when memory region cannot be read

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

  ViewVC Help
Powered by ViewVC 1.1.22