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