10 |
using RomCheater.PluginFramework.Interfaces; |
using RomCheater.PluginFramework.Interfaces; |
11 |
using System.Diagnostics; |
using System.Diagnostics; |
12 |
using System.IO; |
using System.IO; |
13 |
|
using RomCheater.Logging; |
14 |
|
using System.Reflection; |
15 |
|
|
16 |
namespace RomCheater.Docking |
namespace RomCheater.Docking |
17 |
{ |
{ |
75 |
switch (dumpSize) |
switch (dumpSize) |
76 |
{ |
{ |
77 |
case DumpSize.Bytes: |
case DumpSize.Bytes: |
78 |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + start) - BYTE_CORRECTION_VALUE; |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + (double)start) + BYTE_CORRECTION_VALUE; |
79 |
txtEnd.Value = end; |
txtEnd.Value = end; |
80 |
break; |
break; |
81 |
case DumpSize.KiloBytes: |
case DumpSize.KiloBytes: |
82 |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + start) - BYTE_CORRECTION_VALUE; |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + (double)start) + BYTE_CORRECTION_VALUE; |
83 |
txtEnd.Value = end; |
txtEnd.Value = end; |
84 |
break; |
break; |
85 |
case DumpSize.MegaBytes: |
case DumpSize.MegaBytes: |
86 |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + start) - BYTE_CORRECTION_VALUE; |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + (double)start) + BYTE_CORRECTION_VALUE; |
87 |
txtEnd.Value = end; |
txtEnd.Value = end; |
88 |
break; |
break; |
89 |
case DumpSize.GigaBytes: |
case DumpSize.GigaBytes: |
90 |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + start) - BYTE_CORRECTION_VALUE; |
end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + (double)start) + BYTE_CORRECTION_VALUE; |
91 |
txtEnd.Value = end; |
txtEnd.Value = end; |
92 |
break; |
break; |
93 |
} |
} |
158 |
private void DumpRam(ulong start, ulong end, string filename) |
private void DumpRam(ulong start, ulong end, string filename) |
159 |
{ |
{ |
160 |
uint byte_count = (uint)(end - start); |
uint byte_count = (uint)(end - start); |
161 |
|
|
162 |
|
//string arch = ProcessorAssemblyArchitecture.GetProcessorArchitecture(typeof(FloatingRamDumperDialog).Assembly); |
163 |
|
//if (arch == ProcessorAssemblyArchitecture.x86) |
164 |
|
//{ |
165 |
|
if (end > int.MaxValue) |
166 |
|
logger.Warn.WriteLine("Warning: DumpRam(): ending address is greater than 0x{0:x8} and we are running x86, this will exceed the ", int.MaxValue); |
167 |
|
//} |
168 |
|
//else if (arch == ProcessorAssemblyArchitecture.x64) |
169 |
|
//{ |
170 |
|
//} |
171 |
|
//else |
172 |
|
//{ |
173 |
|
// // don't know |
174 |
|
//} |
175 |
|
|
176 |
DumpRam(start, byte_count, filename); |
DumpRam(start, byte_count, filename); |
177 |
} |
} |
178 |
private void DumpRam(ulong start, uint count, string filename) |
private void DumpRam(ulong start, uint count, string filename) |
182 |
reader.ReadProcess = this.AcceptedProcess; |
reader.ReadProcess = this.AcceptedProcess; |
183 |
reader.OpenProcess(); |
reader.OpenProcess(); |
184 |
int bytesReadSize; |
int bytesReadSize; |
185 |
byte[] data = reader.ReadProcessMemory((IntPtr)(uint)start, count, out bytesReadSize); |
reader.DumpMemory(filename, (uint)start, count, out bytesReadSize); |
186 |
reader.CloseHandle(); |
reader.CloseHandle(); |
|
using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) |
|
|
{ |
|
|
BinaryWriter bw = new BinaryWriter(fs); |
|
|
foreach (byte b in data) { bw.Write(b); } |
|
|
bw.Flush(); |
|
|
bw.Close(); |
|
|
} |
|
187 |
} |
} |
188 |
#endregion |
#endregion |
189 |
} |
} |