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

  ViewVC Help
Powered by ViewVC 1.1.22