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