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 |
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 (uint i = address; i < (address + max_ram_view); i += max_address_width) { AddressList = AddressList + string.Format("{0:X8}:\n", i); } |
317 |
StringBuilder builder = new StringBuilder(); |
318 |
int count = 0; |
319 |
// write ascii text |
320 |
for (uint i = 0; i < (0 + max_ram_view); i += max_address_width) |
321 |
{ |
322 |
try |
323 |
{ |
324 |
for (uint j = 0; j < max_address_width; j++) |
325 |
{ |
326 |
uint current_real_address = address + j + i; |
327 |
uint current_addr = i + j; |
328 |
if (current_addr >= MemoryRangeSize) break; |
329 |
byte ascii_value_raw = data[current_addr]; |
330 |
char ascii_value; |
331 |
char c = (char)data[current_addr]; |
332 |
if (char.IsControl(c)) { ascii_value = '.'; } |
333 |
else { ascii_value = c; } |
334 |
using (GenericMemoryProvider gmp = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) |
335 |
{ |
336 |
gmp.OpenProvider(); |
337 |
byte t; |
338 |
if (!gmp.ReadMemory(current_real_address, out t)) { ascii_value = '?'; } |
339 |
gmp.CloseProvider(); |
340 |
} |
341 |
builder.Append(ascii_value.ToString()); |
342 |
} |
343 |
builder.AppendLine(); |
344 |
} |
345 |
catch (Exception ex) |
346 |
{ |
347 |
logger.Error.WriteLine("{0}.UpdateMemroyView().BuildingAsciiString:{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); |
348 |
return; |
349 |
} |
350 |
count++; |
351 |
} |
352 |
AsciiData = builder.ToString(); |
353 |
} |
354 |
catch (Exception ex) |
355 |
{ |
356 |
logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); |
357 |
return; |
358 |
} |
359 |
#endregion |
360 |
} |
361 |
catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
362 |
} |
363 |
//private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e) |
364 |
//{ |
365 |
// this.WriteCurrentBytes(); |
366 |
//} |
367 |
private void WriteCurrentBytes(uint start_address, byte[] data) |
368 |
{ |
369 |
try |
370 |
{ |
371 |
if (AcceptedProcess == null) { return; } |
372 |
if (AcceptedPlugin == null) { return; } |
373 |
// Byte changed |
374 |
//byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray(); |
375 |
using (GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this)) |
376 |
{ |
377 |
provider.OpenProvider(); |
378 |
uint bytesReadSize; |
379 |
|
380 |
provider.WriteProcessMemory(start_address, data, out bytesReadSize); |
381 |
//for (int i = 0; i < data.Length; i ++) |
382 |
//{ |
383 |
// int addr = (int)(start_address + i); |
384 |
// byte data_to_write = data[i]; |
385 |
|
386 |
//} |
387 |
provider.CloseProvider(); |
388 |
} |
389 |
} |
390 |
catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
391 |
} |
392 |
|
393 |
private void update_timer_Tick(object sender, EventArgs e) { this.UpdateGui(); } |
394 |
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()); } } |
395 |
private void ResultsUpdateWorkerThread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
396 |
{ |
397 |
try |
398 |
{ |
399 |
txtAddresses.Text = AddressList; |
400 |
txtAscii.Text = AsciiData; |
401 |
//this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length)); |
402 |
DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData); |
403 |
txtData.ByteProvider = _DynamicByteProvider; |
404 |
//_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed); |
405 |
} |
406 |
catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes) |
407 |
catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
408 |
} |
409 |
private void Handle_KeyDown(object sender, KeyEventArgs e) |
410 |
{ |
411 |
//isScrolling = false; |
412 |
//bool reenable = false; |
413 |
//if (this.UpdateEnabled) reenable = true; |
414 |
//this.UpdateEnabled = false; |
415 |
|
416 |
this.UpdateMaxRamView(); |
417 |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
418 |
|
419 |
////if (e.Type == ScrollEventType.EndScroll) return; |
420 |
//uint size = max_ram_view; |
421 |
|
422 |
bool haveModifier = false; |
423 |
switch (e.Modifiers) |
424 |
{ |
425 |
case Keys.Control: |
426 |
switch (e.KeyCode) |
427 |
{ |
428 |
case Keys.Home: |
429 |
this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false; |
430 |
break; |
431 |
case Keys.End: |
432 |
this.CURRENT_TOP_ADDR = (uint)((MemoryRangeSize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false; |
433 |
break; |
434 |
default: |
435 |
//NonHandledKeysAreBeingPressed = true; |
436 |
break; |
437 |
} |
438 |
break; |
439 |
} |
440 |
|
441 |
if (!haveModifier) |
442 |
{ |
443 |
switch (e.KeyCode) |
444 |
{ |
445 |
case Keys.Up: |
446 |
if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR)) |
447 |
{ |
448 |
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
449 |
} |
450 |
else |
451 |
{ |
452 |
this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
453 |
} |
454 |
break; |
455 |
case Keys.Down: |
456 |
this.CURRENT_TOP_ADDR += (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
457 |
break; |
458 |
case Keys.PageUp: |
459 |
if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR)) |
460 |
{ |
461 |
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
462 |
} |
463 |
else |
464 |
{ |
465 |
this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
466 |
} |
467 |
break; |
468 |
case Keys.PageDown: |
469 |
this.CURRENT_TOP_ADDR += (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
470 |
break; |
471 |
default: |
472 |
//NonHandledKeysAreBeingPressed = true; |
473 |
break; |
474 |
} |
475 |
} |
476 |
if (this.CURRENT_TOP_ADDR < MemoryRangeStart) this.CURRENT_TOP_ADDR = MemoryRangeStart; |
477 |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view; |
478 |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (uint)(MemoryRangeSize - max_ram_view); |
479 |
|
480 |
//this.UpdateEnabled = reenable; |
481 |
} |
482 |
|
483 |
private void UIMemoryViewer_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); } |
484 |
private void txtAddresses_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); } |
485 |
private void txtData_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); } |
486 |
private void txtAscii_KeyDown(object sender, KeyEventArgs e) { this.Handle_KeyDown(sender, e); } |
487 |
private void ramScroll_Scroll(object sender, ScrollEventArgs e) { this.Handle_Scroll(sender, e); } |
488 |
|
489 |
private ScrollEventArgs GetMouseWheelScrollChange(int WheelDelta) |
490 |
{ |
491 |
ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1); |
492 |
if (WheelDelta < 0) |
493 |
{ |
494 |
//// negative: scroll down |
495 |
//// SmallDecrement -or- LargeDecrement |
496 |
//if (WheelDelta <= small_scroll_change) |
497 |
//{ |
498 |
// args = new ScrollEventArgs(ScrollEventType.SmallDecrement,(int)small_scroll_change); |
499 |
//} |
500 |
//if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change) |
501 |
//{ |
502 |
// args = new ScrollEventArgs(ScrollEventType.LargeDecrement, (int)large_scroll_change); |
503 |
//} |
504 |
args = new ScrollEventArgs(ScrollEventType.SmallIncrement, 1); |
505 |
} |
506 |
else |
507 |
{ |
508 |
//// positive: scroll up |
509 |
//// SmallIncrement -or- LargeIncrement |
510 |
//if (WheelDelta <= small_scroll_change) |
511 |
//{ |
512 |
// args = new ScrollEventArgs(ScrollEventType.SmallIncrement, (int)small_scroll_change); |
513 |
//} |
514 |
//if (WheelDelta > small_scroll_change && WheelDelta <= large_scroll_change) |
515 |
//{ |
516 |
// args = new ScrollEventArgs(ScrollEventType.LargeIncrement, (int)large_scroll_change); |
517 |
//} |
518 |
args = new ScrollEventArgs(ScrollEventType.SmallDecrement, 1); |
519 |
} |
520 |
return args; |
521 |
} |
522 |
|
523 |
void txtAddresses_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); } |
524 |
void txtData_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); } |
525 |
void txtAscii_MouseWheel(object sender, MouseEventArgs e) { this.Handle_Scroll(sender, GetMouseWheelScrollChange(e.Delta)); } |
526 |
private void Handle_Scroll(object sender, ScrollEventArgs e) |
527 |
{ |
528 |
//isScrolling = true; |
529 |
//bool reenable = false; |
530 |
//if (this.UpdateEnabled) reenable = true; |
531 |
//this.UpdateEnabled = false; |
532 |
|
533 |
this.UpdateMaxRamView(); |
534 |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
535 |
//uint size = MemorySize; |
536 |
if (e.Type == ScrollEventType.EndScroll) return; |
537 |
|
538 |
switch (e.Type) |
539 |
{ |
540 |
case ScrollEventType.SmallDecrement: |
541 |
if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - small_scroll_change) > this.CURRENT_TOP_ADDR)) |
542 |
{ |
543 |
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
544 |
} |
545 |
else |
546 |
{ |
547 |
this.CURRENT_TOP_ADDR -= (small_scroll_change); |
548 |
} |
549 |
break; |
550 |
case ScrollEventType.SmallIncrement: |
551 |
this.CURRENT_TOP_ADDR += (small_scroll_change); |
552 |
break; |
553 |
|
554 |
case ScrollEventType.LargeDecrement: |
555 |
if (this.CURRENT_TOP_ADDR == 0 && ((this.CURRENT_TOP_ADDR - large_scroll_change) > this.CURRENT_TOP_ADDR)) |
556 |
{ |
557 |
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
558 |
} |
559 |
else |
560 |
{ |
561 |
this.CURRENT_TOP_ADDR -= (large_scroll_change); |
562 |
} |
563 |
break; |
564 |
case ScrollEventType.LargeIncrement: |
565 |
this.CURRENT_TOP_ADDR += (large_scroll_change); |
566 |
break; |
567 |
case ScrollEventType.ThumbPosition: |
568 |
//this.CURRENT_TOP_ADDR = (uint)e.NewValue; |
569 |
//break; |
570 |
default: |
571 |
this.CURRENT_TOP_ADDR = (uint)(e.NewValue & 0xFFFFFFF0); |
572 |
break; |
573 |
} |
574 |
if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0; |
575 |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view; |
576 |
//if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
577 |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemoryRangeSize) this.CURRENT_TOP_ADDR = (uint)(MemoryRangeSize - max_ram_view); |
578 |
//this.UpdateEnabled = reenable; |
579 |
//isScrolling = false; |
580 |
} |
581 |
private void GotoImageBase() |
582 |
{ |
583 |
if (this.peData == null) return; |
584 |
object ImageBase = 0; |
585 |
bool x86 = this.peData.Is32bitAssembly(); |
586 |
if (x86) |
587 |
{ |
588 |
ImageBase = this.peData.NTHeader.OptionalHeader32._ImageBase; |
589 |
uint ib = Convert.ToUInt32(ImageBase); |
590 |
logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x8})", ib); |
591 |
txthexGoto.Value = ib; |
592 |
} |
593 |
else |
594 |
{ |
595 |
ImageBase = this.peData.NTHeader.OptionalHeader64._ImageBase; |
596 |
ulong ib = Convert.ToUInt64(ImageBase); |
597 |
logger.VerboseDebug.WriteLine("UIMemoryViewer::GotoImageBase(0x{0:x16})", ib); |
598 |
txthexGoto.Value = (long)ib; |
599 |
} |
600 |
|
601 |
this.GotoAddress(txthexGoto.ToUInt32()); |
602 |
} |
603 |
private void btnGotoImageBase_Click(object sender, EventArgs e) |
604 |
{ |
605 |
|
606 |
this.GotoImageBase(); |
607 |
} |
608 |
|
609 |
} |
610 |
} |