我的目标是创建一个方法,该方法将获取进程句柄并返回表示该进程内存的字节数组。这是我拥有的:
[DllImport("Kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, UInt32 nSize, ref UInt32 lpNumberOfBytesRead);
public static byte[] MemRead(IntPtr handle, IntPtr address, UInt32 size, ref UInt32 bytes)
{
byte[] buffer = new byte[size];
ReadProcessMemory(handle, address, buffer, size, ref bytes);
return buffer;
}
我不知道将什么作为参数传递给包装器方法。我可以找到一个 handle
并且 bytes
是一个输出变量,但是 address
和 size
呢?我可以从哪里获取这些数据?
最佳答案
在调用 MemRead 之前,使用 VirtualQuery 查明地址是否已实际分配。 从零开始作为地址,64K 作为页面大小,然后在每次迭代中将指针递增 64K,直到达到系统上的最大内存大小。
关于c# - 获取进程内存的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6077182/