15 |
using System.Threading; |
using System.Threading; |
16 |
using RomCheater.Logging; |
using RomCheater.Logging; |
17 |
using System.IO; |
using System.IO; |
18 |
|
using Sojaner.MemoryScanner.MemoryProviers; |
19 |
|
|
20 |
namespace RomCheater.Docking |
namespace RomCheater.Docking |
21 |
{ |
{ |
22 |
public partial class FloatingMemorySearcher : DockContent, |
public partial class FloatingMemorySearcher : DockContent, |
23 |
IAcceptsProcess<Process>, |
IAcceptsPlugin<IConfigPlugin>, |
24 |
IAcceptsPlugin<IConfigPlugin>, |
IAcceptsProcess<Process>, |
25 |
|
IAcceptsProcessAndConfig, |
26 |
ISearchInProgress |
ISearchInProgress |
27 |
{ |
{ |
28 |
private bool DefaultUnsignedState = true; // set unsigned to true |
private bool DefaultUnsignedState = true; // set unsigned to true |
31 |
public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; } |
public FloatingMemorySearcher(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; } |
32 |
|
|
33 |
#region IAcceptsProcess<Process> Members |
#region IAcceptsProcess<Process> Members |
34 |
public Process AcceptedProcess { get; set; } |
private Process _AcceptedProcess; |
35 |
|
public Process AcceptedProcess { get { return _AcceptedProcess; } set { _AcceptedProcess = value; UpdateAcceptedProcessAndConfig(AcceptedPlugin, value); } } |
36 |
#endregion |
#endregion |
37 |
#region IAcceptsPlugin<IConfigPlugin> Members |
#region IAcceptsPlugin<IConfigPlugin> Members |
38 |
public IConfigPlugin AcceptedPlugin { get; set; } |
private IConfigPlugin _AcceptedPlugin; |
39 |
|
public IConfigPlugin AcceptedPlugin { get { return _AcceptedPlugin; } set { _AcceptedPlugin = value; UpdateAcceptedProcessAndConfig(value, AcceptedProcess); } } |
40 |
#endregion |
#endregion |
41 |
|
private void UpdateAcceptedProcessAndConfig(IConfigPlugin config, Process process) |
42 |
|
{ |
43 |
|
this.lstResults.AcceptedPlugin = config; |
44 |
|
this.lstResults.AcceptedProcess = process; |
45 |
|
this.lstPatchList.AcceptedPlugin = config; |
46 |
|
this.lstPatchList.AcceptedProcess = process; |
47 |
|
} |
48 |
#region ISearchInProgress members |
#region ISearchInProgress members |
49 |
public bool SearchInProgess { get; private set; } |
public bool SearchInProgess { get; private set; } |
50 |
#endregion |
#endregion |
327 |
ResultDataType _result = (ResultDataType)ResultItems[i].Tag; |
ResultDataType _result = (ResultDataType)ResultItems[i].Tag; |
328 |
|
|
329 |
Address = Convert.ToUInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16); |
Address = Convert.ToUInt32(ResultItems[i].SubItems[col_Found_Address].Text, 16); |
330 |
//r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
//r_ms.BaseStream.Seek(Address, SeekOrigin.Begin); |
331 |
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
|
reader.ReadProcess = Process.GetProcessById(this.AcceptedProcess.Id); |
|
|
if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", this.AcceptedProcess.Id); return; } |
|
|
reader.OpenProcess(); |
|
332 |
int bytesReadSize; |
int bytesReadSize; |
333 |
byte[] data; |
byte[] data; |
334 |
uint bytesToRead = 0; |
uint bytesToRead = 0; |
335 |
switch (_result.ValueType) |
switch (_result.ValueType) |
336 |
{ |
{ |
347 |
bytesToRead = 8; |
bytesToRead = 8; |
348 |
break; |
break; |
349 |
} |
} |
350 |
reader.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
351 |
MemoryStream ms = new MemoryStream(data); |
MemoryStream ms = new MemoryStream(data); |
352 |
BinaryReader r_ms = new BinaryReader(ms); |
BinaryReader r_ms = new BinaryReader(ms); |
353 |
switch (_result.ValueType) |
switch (_result.ValueType) |
370 |
break; |
break; |
371 |
} |
} |
372 |
r_ms.Close(); |
r_ms.Close(); |
|
reader.CloseHandle(); |
|
373 |
Application.DoEvents(); |
Application.DoEvents(); |
374 |
} |
} |
375 |
#endregion |
#endregion |
402 |
uint Address = 0; |
uint Address = 0; |
403 |
ResultDataType _result = (ResultDataType)AddedItems[i].Tag; |
ResultDataType _result = (ResultDataType)AddedItems[i].Tag; |
404 |
Address = Convert.ToUInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16); |
Address = Convert.ToUInt32(AddedItems[i].SubItems[col_Added_Address].Text, 16); |
405 |
Sojaner.MemoryScanner.ProcessMemoryReader reader = new Sojaner.MemoryScanner.ProcessMemoryReader(); |
GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this); |
|
reader.ReadProcess = Process.GetProcessById(this.AcceptedProcess.Id); |
|
|
if (reader.ReadProcess == null) { logger.Error.WriteLine("Could not attach to process: {0}", this.AcceptedProcess.Id); return; } |
|
|
reader.OpenProcess(); |
|
406 |
int bytesReadSize; |
int bytesReadSize; |
407 |
byte[] data; |
byte[] data; |
408 |
uint bytesToRead = 0; |
uint bytesToRead = 0; |
421 |
bytesToRead = 8; |
bytesToRead = 8; |
422 |
break; |
break; |
423 |
} |
} |
424 |
reader.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
provider.ReadProcessMemory(Address, bytesToRead, out bytesReadSize, out data); |
425 |
MemoryStream ms = new MemoryStream(data); |
MemoryStream ms = new MemoryStream(data); |
426 |
BinaryReader r_ms = new BinaryReader(ms); |
BinaryReader r_ms = new BinaryReader(ms); |
427 |
switch (_result.ValueType) |
switch (_result.ValueType) |
444 |
break; |
break; |
445 |
} |
} |
446 |
r_ms.Close(); |
r_ms.Close(); |
|
reader.CloseHandle(); |
|
447 |
Application.DoEvents(); |
Application.DoEvents(); |
448 |
} |
} |
449 |
#endregion |
#endregion |
725 |
if (_result.IsUnsigned) |
if (_result.IsUnsigned) |
726 |
{ |
{ |
727 |
byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16); |
byte value = Convert.ToByte(item.SubItems[col_Found_Value].Text, 16); |
728 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
729 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
730 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
731 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
736 |
else |
else |
737 |
{ |
{ |
738 |
sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16); |
sbyte value = Convert.ToSByte(item.SubItems[col_Found_Value].Text, 16); |
739 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
740 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
741 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
742 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
749 |
if (_result.IsUnsigned) |
if (_result.IsUnsigned) |
750 |
{ |
{ |
751 |
ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16); |
ushort value = Convert.ToUInt16(item.SubItems[col_Found_Value].Text, 16); |
752 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
753 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
754 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
755 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
760 |
else |
else |
761 |
{ |
{ |
762 |
short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16); |
short value = Convert.ToInt16(item.SubItems[col_Found_Value].Text, 16); |
763 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
764 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
765 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
766 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
773 |
if (_result.IsUnsigned) |
if (_result.IsUnsigned) |
774 |
{ |
{ |
775 |
uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
uint value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
776 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
777 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
778 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
779 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
784 |
else |
else |
785 |
{ |
{ |
786 |
int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
int value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
787 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
788 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
789 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
790 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
797 |
if (_result.IsUnsigned) |
if (_result.IsUnsigned) |
798 |
{ |
{ |
799 |
ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
ulong value = Convert.ToUInt32(item.SubItems[col_Found_Value].Text, 16); |
800 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
801 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
802 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
803 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
808 |
else |
else |
809 |
{ |
{ |
810 |
long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
long value = Convert.ToInt32(item.SubItems[col_Found_Value].Text, 16); |
811 |
patcher = new SearchPatcher(this.AcceptedProcess.Id, Address, value); |
patcher = new SearchPatcher((IAcceptsProcessAndConfig)this, Address, value); |
812 |
timer_update_results.Enabled = false; |
timer_update_results.Enabled = false; |
813 |
patcher.ShowDialog(); |
patcher.ShowDialog(); |
814 |
timer_update_results.Enabled = true; |
timer_update_results.Enabled = true; |
830 |
|
|
831 |
if (patch_list.Count > 0) |
if (patch_list.Count > 0) |
832 |
{ |
{ |
833 |
SearchRangePatcher rangePatcher = new SearchRangePatcher(this.AcceptedProcess.Id, patch_list); |
SearchRangePatcher rangePatcher = new SearchRangePatcher((IAcceptsProcessAndConfig)this, patch_list); |
834 |
rangePatcher.ShowDialog(); |
rangePatcher.ShowDialog(); |
835 |
} |
} |
836 |
|
|