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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 812 - (show annotations) (download)
Tue Apr 15 14:52:10 2014 UTC (5 years, 9 months ago) by william
File size: 30190 byte(s)
+ update logging to use Enterpise.Logging -- more work is still needed

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

  ViewVC Help
Powered by ViewVC 1.1.22