/[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 421 - (show annotations) (download)
Tue May 28 11:21:21 2013 UTC (7 years, 4 months ago) by william
File size: 28241 byte(s)
+ continued previous commit: remove old code that generated the old top toolbar

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

  ViewVC Help
Powered by ViewVC 1.1.22