ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
Revision: 399
Committed: Wed Jun 20 13:24:49 2012 UTC (10 years ago) by william
File size: 27842 byte(s)
Log Message:

File Contents

# Content
1 //#define DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS // when defined will not call GetFirstNonZeroByte() when AcceptedProcess is updated and is not null
2 #define DISABLE_GETFIRSTNONZERO_BYTE // when defined will make GetFirstNonZeroByte() an empty void method
3 using System;
4 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 using Sojaner.MemoryScanner.MemoryProviers;
16 using System.Runtime.InteropServices;
17 using RomCheater.PluginFramework.Events;
18 using Sojaner.MemoryScanner;
19
20 namespace RomCheater.Docking.UI
21 {
22 public partial class UIMemoryViewer : UserControl,
23 IAcceptsPlugin<IConfigPlugin>,
24 IAcceptsProcess<Process>,
25 IAcceptsProcessAndConfig,
26 IAcceptsMemoryRange,
27 IBrowseMemoryRegion,
28 IAcceptPEData
29 {
30
31
32 public delegate void SetTextDelegate(string text);
33 public void SetAsciiData(string text)
34 {
35 if (txtAscii.InvokeRequired)
36 {
37 SetTextDelegate std = new SetTextDelegate(SetAsciiData);
38 txtAscii.Invoke(std, text);
39 return;
40 }
41 txtAscii.Text = text;
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 (uint 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
63
64 lblAddressMarker.Text = "";
65 for (uint i = 0; i < max_address_width; i++)
66 {
67 lblAddressMarker.Text = lblAddressMarker.Text + string.Format("{0:X2} ", i);
68 }
69 this.AcceptedPlugin = null; this.AcceptedProcess = null;
70
71 txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel);
72 txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel);
73 txtAscii.MouseWheel += new MouseEventHandler(txtAscii_MouseWheel);
74 }
75
76 private void GetFirstNonZeroByte()
77 {
78 #if !DISABLE_GETFIRSTNONZERO_BYTE
79 if (!DesignMode)
80 {
81 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
82 provider.OpenProvider();
83 int addr = 0;
84 provider.ReadFirstNonZeroByte(MemoryRangeStart, MemoryRangeSize, out addr);
85 provider.CloseProvider();
86 GotoAddress(addr);
87 }
88 #else
89 this.GotoImageBase();
90 #endif
91 }
92 #region IBrowseMemoryRegion
93 public bool BrowseMemoryRegion(uint MemoryRegion)
94 {
95 try
96 {
97 if (!((MemoryRangeStart <= MemoryRegion) && (MemoryRegion <= (MemoryRangeStart + MemoryRangeSize)))) { return false; }
98 GotoAddress(MemoryRegion);
99 return true;
100 }
101 catch (Exception ex)
102 {
103 logger.Error.WriteLine("UIMemoryViewer.BrowseMemoryRegion(int MemoryRegion): Failed to Browse Memory Region: 0x{0:x8}", MemoryRegion);
104 logger.Error.WriteLine(ex.ToString());
105 return false;
106 }
107 }
108 #endregion
109 #region IAcceptsProcess<Process> Members
110 private Process _AcceptedProcess;
111 public Process AcceptedProcess
112 {
113 get { return _AcceptedProcess; }
114 set
115 {
116 _AcceptedProcess = value;
117 update_timer.Enabled = (value != null);
118 UpdateEnabled = update_timer.Enabled;
119 #if !DISABLE_GETFIRSTNONZEROBYTE_ONUPDATE_ACCEPTEDPROCESS
120 if (value != null)
121 GetFirstNonZeroByte();
122 #endif
123 }
124 }
125 #endregion
126 #region IAcceptsPlugin<IConfigPlugin> Members
127 public IConfigPlugin AcceptedPlugin { get; set; }
128 #endregion
129 #region IAcceptsMemoryRange members
130 public uint MemoryRangeStart { get { return MemorySizeConstants.MinimumAddress; } set { } }
131 public uint MemoryRangeSize { get { return MemoryRangeStart + MemorySizeConstants.MaximumAddressSize; } set { } }
132 #endregion
133 #region IAcceptPEData members
134 private IPEDData peData { get; set; }
135 public void SetPEViewerData(IPEDData peData) { this.peData = peData; }
136 #endregion
137 public void GotoTop() { this.CURRENT_TOP_ADDR = 0; }
138 public void GotoBottom() { uint size = (uint)MemoryRangeSize; this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); }
139 public void GotoAddress(uint addr)
140 {
141 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoAddress(0x{0:x8})", addr);
142 this.CURRENT_TOP_ADDR = (uint)(addr & 0xFFFFFFF0);
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 uint _CURRENT_TOP_ADDR;
178 uint 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 int 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(uint address)
299 {
300 try
301 {
302 if (AcceptedProcess == null) { return; }
303 if (AcceptedPlugin == null) { return; }
304
305 byte[] data = GetMemory();
306 RamData = data;
307 #region old ascii-code
308 try
309 {
310 AddressList = "";
311 AsciiData = "";
312 // write the addreses out
313 for (uint i = address; i < (address + max_ram_view); i += max_address_width) { AddressList = AddressList + string.Format("{0:X8}:\n", i); }
314 StringBuilder builder = new StringBuilder();
315 int count = 0;
316 // write ascii text
317 for (uint i = 0; i < (0 + max_ram_view); i += max_address_width)
318 {
319 try
320 {
321 for (uint j = 0; j < max_address_width; j++)
322 {
323 uint current_real_address = address + j + i;
324 uint current_addr = i + j;
325 if (current_addr >= MemoryRangeSize) break;
326 byte ascii_value_raw = data[current_addr];
327 char ascii_value;
328 char c = (char)data[current_addr];
329 if (char.IsControl(c)) { ascii_value = '.'; }
330 else { ascii_value = c; }
331 using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
332 {
333 gmp.OpenProvider();
334 byte t;
335 if (!gmp.ReadMemory(current_real_address, out t)) { ascii_value = '?'; }
336 gmp.CloseProvider();
337 }
338 builder.Append(ascii_value.ToString());
339 }
340 builder.AppendLine();
341 }
342 catch (Exception ex)
343 {
344 logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
345 return;
346 }
347 count++;
348 }
349 AsciiData = builder.ToString();
350 }
351 catch (Exception ex)
352 {
353 logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
354 return;
355 }
356 #endregion
357 }
358 catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
359 }
360 //private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e)
361 //{
362 // this.WriteCurrentBytes();
363 //}
364 private void WriteCurrentBytes(uint start_address, byte[] data)
365 {
366 try
367 {
368 if (AcceptedProcess == null) { return; }
369 if (AcceptedPlugin == null) { return; }
370 // Byte changed
371 //byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
372 using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this))
373 {
374 provider.OpenProvider();
375 uint bytesReadSize;
376
377 provider.WriteProcessMemory(start_address, data, out bytesReadSize);
378 //for (int i = 0; i < data.Length; i ++)
379 //{
380 // int addr = (int)(start_address + i);
381 // byte data_to_write = data[i];
382
383 //}
384 provider.CloseProvider();
385 }
386 }
387 catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
388 }
389
390 private void update_timer_Tick(object sender, EventArgs e) { this.UpdateGui(); }
391 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()); } }
392 private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
393 {
394 try
395 {
396 txtAddresses.Text = AddressList;
397 txtAscii.Text = AsciiData;
398 //this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length));
399 DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData);
400 txtData.ByteProvider = _DynamicByteProvider;
401 //_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed);
402 }
403 catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes)
404 catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
405 }
406 private void Handle_KeyDown(object sender, KeyEventArgs e)
407 {
408 //isScrolling = false;
409 //bool reenable = false;
410 //if (this.UpdateEnabled) reenable = true;
411 //this.UpdateEnabled = false;
412
413 this.UpdateMaxRamView();
414 uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
415
416 ////if (e.Type == ScrollEventType.EndScroll) return;
417 //uint size = max_ram_view;
418
419 bool haveModifier = false;
420 switch (e.Modifiers)
421 {
422 case Keys.Control:
423 switch (e.KeyCode)
424 {
425 case Keys.Home:
426 this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false;
427 break;
428 case Keys.End:
429 this.CURRENT_TOP_ADDR = (uint)((MemoryRangeSize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false;
430 break;
431 default:
432 //NonHandledKeysAreBeingPressed = true;
433 break;
434 }
435 break;
436 }
437
438 if (!haveModifier)
439 {
440 switch (e.KeyCode)
441 {
442 case Keys.Up:
443 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR))
444 {
445 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
446 }
447 else
448 {
449 this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
450 }
451 break;
452 case Keys.Down:
453 this.CURRENT_TOP_ADDR += (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false;
454 break;
455 case Keys.PageUp:
456 if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR))
457 {
458 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
459 }
460 else
461 {
462 this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
463 }
464 break;
465 case Keys.PageDown:
466 this.CURRENT_TOP_ADDR += (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false;
467 break;
468 default:
469 //NonHandledKeysAreBeingPressed = true;
470 break;
471 }
472 }
473 if (this.CURRENT_TOP_ADDR < MemoryRangeStart) this.CURRENT_TOP_ADDR = MemoryRangeStart;
474 //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view;
475 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (uint)(MemoryRangeSize - max_ram_view);
476
477 //this.UpdateEnabled = reenable;
478 }
479
480 private void UIMemoryViewer_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
481 private void txtAddresses_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
482 private void txtData_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
483 private void txtAscii_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); }
484 private void ramScroll_Scroll(object sender, ScrollEventArgs e) { this.Handle_Scroll(sender, e); }
485
486 private ScrollEventArgs GetMouseWheelScrollChange(int WheelDelta)
487 {
488 ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
489 if (WheelDelta < 0)
490 {
491 //// negative: scroll down
492 //// SmallDecrement -or- LargeDecrement
493 //if (WheelDelta <= small_scroll_change)
494 //{
495 // args = new ScrollEventArgs(ScrollEventType.SmallDecrement,(int)small_scroll_change);
496 //}
497 //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
498 //{
499 // args = new ScrollEventArgs(ScrollEventType.LargeDecrement, (int)large_scroll_change);
500 //}
501 args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1);
502 }
503 else
504 {
505 //// positive: scroll up
506 //// SmallIncrement -or- LargeIncrement
507 //if (WheelDelta <= small_scroll_change)
508 //{
509 // args = new ScrollEventArgs(ScrollEventType.SmallIncrement, (int)small_scroll_change);
510 //}
511 //if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change)
512 //{
513 // args = new ScrollEventArgs(ScrollEventType.LargeIncrement, (int)large_scroll_change);
514 //}
515 args = new ScrollEventArgs(ScrollEventType.SmallDecrement, 1);
516 }
517 return args;
518 }
519
520 void txtAddresses_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
521 void txtData_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
522 void txtAscii_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); }
523 private void Handle_Scroll(object sender, ScrollEventArgs e)
524 {
525 //isScrolling = true;
526 //bool reenable = false;
527 //if (this.UpdateEnabled) reenable = true;
528 //this.UpdateEnabled = false;
529
530 this.UpdateMaxRamView();
531 uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR;
532 //uint size = MemorySize;
533 if (e.Type == ScrollEventType.EndScroll) return;
534
535 switch (e.Type)
536 {
537 case ScrollEventType.SmallDecrement:
538 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - small_scroll_change) > this.CURRENT_TOP_ADDR))
539 {
540 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
541 }
542 else
543 {
544 this.CURRENT_TOP_ADDR -= (small_scroll_change);
545 }
546 break;
547 case ScrollEventType.SmallIncrement:
548 this.CURRENT_TOP_ADDR += (small_scroll_change);
549 break;
550
551 case ScrollEventType.LargeDecrement:
552 if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - large_scroll_change) > this.CURRENT_TOP_ADDR))
553 {
554 this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
555 }
556 else
557 {
558 this.CURRENT_TOP_ADDR -= (large_scroll_change);
559 }
560 break;
561 case ScrollEventType.LargeIncrement:
562 this.CURRENT_TOP_ADDR += (large_scroll_change);
563 break;
564 case ScrollEventType.ThumbPosition:
565 //this.CURRENT_TOP_ADDR = (uint)e.NewValue;
566 //break;
567 default:
568 this.CURRENT_TOP_ADDR = (uint)(e.NewValue & 0xFFFFFFF0);
569 break;
570 }
571 if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0;
572 //if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view;
573 //if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR;
574 if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (uint)(MemoryRangeSize - max_ram_view);
575 //this.UpdateEnabled = reenable;
576 //isScrolling = false;
577 }
578 private void GotoImageBase()
579 {
580 if (this.peData == null) return;
581 object ImageBase = 0;
582 bool x86 = this.peData.Is32bitAssembly();
583 if (x86)
584 {
585 ImageBase = this.peData.NTHeader.OptionalHeader32._ImageBase;
586 uint ib = Convert.ToUInt32(ImageBase);
587 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x8})", ib);
588 txthexGoto.Value = ib;
589 }
590 else
591 {
592 ImageBase = this.peData.NTHeader.OptionalHeader64._ImageBase;
593 ulong ib = Convert.ToUInt64(ImageBase);
594 logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x16})", ib);
595 txthexGoto.Value = (long)ib;
596 }
597
598 this.GotoAddress(txthexGoto.ToUInt32());
599 }
600 private void btnGotoImageBase_Click(object sender, EventArgs e)
601 {
602
603 this.GotoImageBase();
604 }
605
606 }
607 }