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