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