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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 889 - (show annotations) (download)
Wed Sep 17 04:55:52 2014 UTC (7 years, 2 months ago) by william
File size: 30159 byte(s)


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

  ViewVC Help
Powered by ViewVC 1.1.22