10 |
using RomCheater.Logging; |
using RomCheater.Logging; |
11 |
using RomCheater.PluginFramework.Interfaces; |
using RomCheater.PluginFramework.Interfaces; |
12 |
using System.Diagnostics; |
using System.Diagnostics; |
13 |
|
using Sojaner.MemoryScanner.MemoryProviers; |
14 |
|
|
15 |
namespace RomCheater.Docking.UI |
namespace RomCheater.Docking.UI |
16 |
{ |
{ |
17 |
public partial class UIMemoryViewer : UserControl, IProcessConfig, IAcceptsPlugin<IConfigPlugin>//, IAcceptsMemoryRange |
public partial class UIMemoryViewer : UserControl, IAcceptsProcess<Process>, IAcceptsPlugin<IConfigPlugin>//, IAcceptsMemoryRange |
18 |
{ |
{ |
19 |
public UIMemoryViewer() |
public UIMemoryViewer() |
20 |
{ |
{ |
44 |
|
|
45 |
txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel); |
txtAddresses.MouseWheel += new MouseEventHandler(txtAddresses_MouseWheel); |
46 |
txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel); |
txtData.MouseWheel += new MouseEventHandler(txtData_MouseWheel); |
47 |
} |
} |
48 |
#region IProcessConfig Members |
|
49 |
|
private void GetFirstNonZeroByte() |
50 |
|
{ |
51 |
|
if (!DesignMode) |
52 |
|
{ |
53 |
|
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
54 |
|
uint addr = 0; |
55 |
|
provider.ReadFirstNonZeroByte(MemoryStart, MemorySize, out addr); |
56 |
|
GotoAddress(addr); |
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
|
#region IAcceptsProcess<Process> Members |
61 |
private Process _AcceptedProcess; |
private Process _AcceptedProcess; |
62 |
public Process AcceptedProcess |
public Process AcceptedProcess |
63 |
{ |
{ |
67 |
_AcceptedProcess = value; |
_AcceptedProcess = value; |
68 |
update_timer.Enabled = (value != null); |
update_timer.Enabled = (value != null); |
69 |
UpdateEnabled = update_timer.Enabled; |
UpdateEnabled = update_timer.Enabled; |
70 |
|
if (value != null) |
71 |
|
GetFirstNonZeroByte(); |
72 |
} |
} |
73 |
} |
} |
74 |
#endregion |
#endregion |
76 |
public IConfigPlugin AcceptedPlugin { get; set; } |
public IConfigPlugin AcceptedPlugin { get; set; } |
77 |
#endregion |
#endregion |
78 |
#region IAcceptsMemoryRange members |
#region IAcceptsMemoryRange members |
79 |
private uint MemoryStart { get { return 0; } } |
public uint MemoryStart { get { return 0; } } |
80 |
private uint MemorySize { get { return int.MaxValue; } } |
public uint MemorySize { get { return int.MaxValue; } } |
81 |
#endregion |
#endregion |
82 |
public void GotoTop() { this.CURRENT_TOP_ADDR = 0; } |
public void GotoTop() { this.CURRENT_TOP_ADDR = 0; } |
83 |
public void GotoBottom() { uint size = MemorySize; this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); } |
public void GotoBottom() { uint size = MemorySize; this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); } |
119 |
uint CURRENT_TOP_ADDR |
uint CURRENT_TOP_ADDR |
120 |
{ |
{ |
121 |
get { return _CURRENT_TOP_ADDR; } |
get { return _CURRENT_TOP_ADDR; } |
122 |
set { _CURRENT_TOP_ADDR = value; } |
set { txthexGoto.Value = _CURRENT_TOP_ADDR = value; } |
123 |
} |
} |
124 |
//uint CURRENT_BOITTOM_ADDR() { return CURRENT_TOP_ADDR + max_ram_view; } |
//uint CURRENT_BOITTOM_ADDR() { return CURRENT_TOP_ADDR + max_ram_view; } |
125 |
private void UpdateMaxRamView() |
private void UpdateMaxRamView() |
146 |
editor.ShowDialog(); |
editor.ShowDialog(); |
147 |
if (editor.BytesEdited) |
if (editor.BytesEdited) |
148 |
{ |
{ |
149 |
DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(editor.AsBytes); |
//DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(editor.AsBytes); |
150 |
txtData.ByteProvider = _DynamicByteProvider; |
//txtData.ByteProvider = _DynamicByteProvider; |
151 |
_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed); |
//_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed); |
152 |
this.WriteCurrentBytes(); |
this.WriteCurrentBytes(this.CURRENT_TOP_ADDR, editor.AsBytes); |
153 |
} |
} |
154 |
this.UpdateEnabled = reenable; |
this.UpdateEnabled = reenable; |
155 |
} |
} |
189 |
{ |
{ |
190 |
try |
try |
191 |
{ |
{ |
192 |
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
|
reader.ReadProcess = this.AcceptedProcess; |
|
|
reader.OpenProcess(); |
|
193 |
int bytesReadSize; |
int bytesReadSize; |
194 |
byte[] data = reader.ReadProcessMemory(CURRENT_TOP_ADDR, max_ram_view, out bytesReadSize); |
byte[] data; |
195 |
|
provider.ReadProcessMemory(CURRENT_TOP_ADDR, max_ram_view, out bytesReadSize, out data); |
196 |
//this.Logger.LogDebugMessage(string.Format("GetMemory() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", data.Length)); |
//this.Logger.LogDebugMessage(string.Format("GetMemory() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", data.Length)); |
197 |
return data; |
return data; |
198 |
} |
} |
266 |
} |
} |
267 |
catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
catch (Exception ex) { logger.Error.WriteLine("{0}.UpdateMemroyView():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
268 |
} |
} |
269 |
private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e) |
//private void HexResourceViewerBytes_Changed(object sender, System.EventArgs e) |
270 |
{ |
//{ |
271 |
this.WriteCurrentBytes(); |
// this.WriteCurrentBytes(); |
272 |
} |
//} |
273 |
private void WriteCurrentBytes() |
private void WriteCurrentBytes(uint start_address, byte[] data) |
274 |
{ |
{ |
275 |
try |
try |
276 |
{ |
{ |
277 |
if (AcceptedProcess == null) { return; } |
if (AcceptedProcess == null) { return; } |
278 |
if (AcceptedPlugin == null) { return; } |
if (AcceptedPlugin == null) { return; } |
279 |
// Byte changed |
// Byte changed |
280 |
byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray(); |
//byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray(); |
281 |
|
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
|
|
|
|
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
|
|
reader.ReadProcess = this.AcceptedProcess; |
|
|
reader.OpenProcess(); |
|
282 |
int bytesReadSize; |
int bytesReadSize; |
283 |
|
|
284 |
for (int i = 0; i < data.Length; i += sizeof(uint)) |
for (int i = 0; i < data.Length; i ++) |
285 |
{ |
{ |
286 |
uint addr = (uint)(this.CURRENT_TOP_ADDR + i); |
uint addr = (uint)(start_address + i); |
287 |
uint data_to_write = BitConverter.ToUInt32(data, i); |
byte data_to_write = data[i]; |
288 |
reader.WriteProcessMemory((UIntPtr)addr, data, out bytesReadSize); |
provider.WriteProcessMemory(addr, data_to_write, out bytesReadSize); |
289 |
} |
} |
290 |
} |
} |
291 |
catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
302 |
//this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length)); |
//this.Logger.LogDebugMessage(string.Format("RunWorkerCompeleted() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", RamData.Length)); |
303 |
DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData); |
DynamicByteProvider _DynamicByteProvider = new DynamicByteProvider(RamData); |
304 |
txtData.ByteProvider = _DynamicByteProvider; |
txtData.ByteProvider = _DynamicByteProvider; |
305 |
_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed); |
//_DynamicByteProvider.Changed += new EventHandler(HexResourceViewerBytes_Changed); |
306 |
} |
} |
307 |
catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes) |
catch (ObjectDisposedException) { } // ignore errors aobut disposed objects (usually only happens when the parent closes) |
308 |
catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
catch (Exception ex) { logger.Error.WriteLine("{0}.ResultsUpdateWorkerThread_RunWorkerCompleted():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); } |
318 |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
319 |
|
|
320 |
////if (e.Type == ScrollEventType.EndScroll) return; |
////if (e.Type == ScrollEventType.EndScroll) return; |
321 |
uint size = max_ram_view; |
//uint size = max_ram_view; |
322 |
|
|
323 |
bool haveModifier = false; |
bool haveModifier = false; |
324 |
switch (e.Modifiers) |
switch (e.Modifiers) |
330 |
this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false; |
this.CURRENT_TOP_ADDR = 0; //NonHandledKeysAreBeingPressed = false; |
331 |
break; |
break; |
332 |
case Keys.End: |
case Keys.End: |
333 |
this.CURRENT_TOP_ADDR = (uint)((size - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false; |
this.CURRENT_TOP_ADDR = (uint)((MemorySize - 1) - max_ram_view); //NonHandledKeysAreBeingPressed = false; |
334 |
break; |
break; |
335 |
default: |
default: |
336 |
//NonHandledKeysAreBeingPressed = true; |
//NonHandledKeysAreBeingPressed = true; |
344 |
switch (e.KeyCode) |
switch (e.KeyCode) |
345 |
{ |
{ |
346 |
case Keys.Up: |
case Keys.Up: |
347 |
this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - small_scroll_change > this.CURRENT_TOP_ADDR)) |
348 |
|
{ |
349 |
|
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
350 |
|
} |
351 |
|
else |
352 |
|
{ |
353 |
|
this.CURRENT_TOP_ADDR -= (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
354 |
|
} |
355 |
break; |
break; |
356 |
case Keys.Down: |
case Keys.Down: |
357 |
this.CURRENT_TOP_ADDR += (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
this.CURRENT_TOP_ADDR += (uint)small_scroll_change; //NonHandledKeysAreBeingPressed = false; |
358 |
break; |
break; |
359 |
case Keys.PageUp: |
case Keys.PageUp: |
360 |
this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
if (this.CURRENT_TOP_ADDR == 0 && (this.CURRENT_TOP_ADDR - large_scroll_change > this.CURRENT_TOP_ADDR)) |
361 |
|
{ |
362 |
|
this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
363 |
|
} |
364 |
|
else |
365 |
|
{ |
366 |
|
this.CURRENT_TOP_ADDR -= (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
367 |
|
} |
368 |
break; |
break; |
369 |
case Keys.PageDown: |
case Keys.PageDown: |
370 |
this.CURRENT_TOP_ADDR += (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
this.CURRENT_TOP_ADDR += (uint)(large_scroll_change); //NonHandledKeysAreBeingPressed = false; |
376 |
} |
} |
377 |
if (this.CURRENT_TOP_ADDR < MemoryStart) this.CURRENT_TOP_ADDR = MemoryStart; |
if (this.CURRENT_TOP_ADDR < MemoryStart) this.CURRENT_TOP_ADDR = MemoryStart; |
378 |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view; |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view; |
379 |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (size - 1); |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (MemorySize - max_ram_view); |
380 |
|
|
381 |
//this.UpdateEnabled = reenable; |
//this.UpdateEnabled = reenable; |
382 |
} |
} |
383 |
|
|
434 |
|
|
435 |
this.UpdateMaxRamView(); |
this.UpdateMaxRamView(); |
436 |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
uint ORIGINAL_ADDR = this.CURRENT_TOP_ADDR; |
437 |
uint size = MemorySize; |
//uint size = MemorySize; |
438 |
if (e.Type == ScrollEventType.EndScroll) return; |
if (e.Type == ScrollEventType.EndScroll) return; |
439 |
|
|
440 |
switch (e.Type) |
switch (e.Type) |
476 |
if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0; |
if (this.CURRENT_TOP_ADDR < 0) this.CURRENT_TOP_ADDR = 0; |
477 |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view; |
//if (this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = VTLB_VADDR_SIZE - max_ram_view; |
478 |
//if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
//if (this.CURRENT_TOP_ADDR < 0 || this.CURRENT_TOP_ADDR >= VTLB_VADDR_SIZE) this.CURRENT_TOP_ADDR = ORIGINAL_ADDR; |
479 |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = (size - 1) - max_ram_view; |
if (this.CURRENT_TOP_ADDR + max_ram_view >= MemorySize) this.CURRENT_TOP_ADDR = MemorySize - max_ram_view; |
480 |
//this.UpdateEnabled = reenable; |
//this.UpdateEnabled = reenable; |
481 |
//isScrolling = false; |
//isScrolling = false; |
482 |
} |
} |
483 |
|
|
484 |
} |
} |
485 |
} |
} |