72 |
public bool DumpMemory(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead) |
public bool DumpMemory(string filename, uint MemoryAddress, uint bytesToRead, out int bytesRead) |
73 |
{ |
{ |
74 |
bytesRead = 0; |
bytesRead = 0; |
75 |
uint byte_alignment = 512; // 4mb alignment |
uint byte_alignment = 16; // 16 byte alignment |
76 |
uint address = MemoryAddress; |
uint address = MemoryAddress; |
77 |
try |
try |
78 |
{ |
{ |
86 |
byte[] buffer = new byte[byte_alignment]; |
byte[] buffer = new byte[byte_alignment]; |
87 |
uint bytes_to_read = byte_alignment; |
uint bytes_to_read = byte_alignment; |
88 |
IntPtr ptrBytesRead; |
IntPtr ptrBytesRead; |
89 |
ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, bytes_to_read, out ptrBytesRead); |
ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, bytes_to_read, out ptrBytesRead); |
90 |
bytesRead = ptrBytesRead.ToInt32(); |
bytesRead = ptrBytesRead.ToInt32(); |
91 |
bw.Write(buffer); |
bw.Write(buffer); |
92 |
bw.Flush(); |
bw.Flush(); |
124 |
byte[] buffer = new byte[byte_alignment]; |
byte[] buffer = new byte[byte_alignment]; |
125 |
uint bytes_to_read = byte_alignment; |
uint bytes_to_read = byte_alignment; |
126 |
IntPtr ptrBytesRead; |
IntPtr ptrBytesRead; |
127 |
ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (IntPtr)address, buffer, bytes_to_read, out ptrBytesRead); |
ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, (UIntPtr)address, buffer, bytes_to_read, out ptrBytesRead); |
128 |
bytesRead = ptrBytesRead.ToInt32(); |
bytesRead = ptrBytesRead.ToInt32(); |
129 |
aligned_array_list.Add(buffer); |
aligned_array_list.Add(buffer); |
130 |
address += byte_alignment; |
address += byte_alignment; |
148 |
return new byte[] { }; |
return new byte[] { }; |
149 |
} |
} |
150 |
|
|
151 |
public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten) |
public void WriteProcessMemory(UIntPtr MemoryAddress, byte[] bytesToWrite, out int bytesWritten) |
152 |
{ |
{ |
153 |
IntPtr ptrBytesWritten; |
IntPtr ptrBytesWritten; |
154 |
ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten); |
ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten); |
203 |
// SIZE_T * lpNumberOfBytesRead // number of bytes read |
// SIZE_T * lpNumberOfBytesRead // number of bytes read |
204 |
// ); |
// ); |
205 |
[DllImport("kernel32.dll")] |
[DllImport("kernel32.dll")] |
206 |
public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead); |
public static extern Int32 ReadProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead); |
207 |
|
|
208 |
// BOOL WriteProcessMemory( |
// BOOL WriteProcessMemory( |
209 |
// HANDLE hProcess, // handle to process |
// HANDLE hProcess, // handle to process |
213 |
// SIZE_T * lpNumberOfBytesWritten // count of bytes written |
// SIZE_T * lpNumberOfBytesWritten // count of bytes written |
214 |
// ); |
// ); |
215 |
[DllImport("kernel32.dll")] |
[DllImport("kernel32.dll")] |
216 |
public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten); |
public static extern Int32 WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten); |
217 |
|
|
218 |
|
|
219 |
} |
} |