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

  ViewVC Help
Powered by ViewVC 1.1.22