日期:2014-05-20  浏览次数:21084 次

ReadProcessMemory在C#中怎么用?
[DllImport( "Kernel32.dll ")]
public   static   extern   unsafe   int   ReadProcessMemory(int   hProcess,   int   lpBaseAddress,   int   lpBuffer,   int   nSize,   int*   lpNumberOfBytesRead);
这样对吗?

如果要读0c0890c0这个地址,
Hbf1=ReadProcessMemory(pro2,&0c0890c0,参数三,参数四);
对吗?后两个参数要怎么写。

如果函数成功,那函数的返回值就是那个地址的值吧,,



------解决方案--------------------
[DllImport( "kernel32.dll ")]
static extern bool ReadProcessMemory(uint hProcess, IntPtr lpBaseAddress,
IntPtr lpBuffer, uint nSize, ref uint lpNumberOfBytesRead);

//....
byte[] vBuffer = new byte[4];
IntPtr vBytesAddress = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0); // 得到缓冲区的地址
uint vNumberOfBytesRead = 0;

ReadProcessMemory(pro2, (IntPtr)0c0890c0, vBytesAddress, vBytesAddress.Length, ref vNumberOfBytesRead);

int vInt = Marshal.ReadInt32(vBytesAddress); // 读取数据
------解决方案--------------------
//参考这样写
[DllImport( "kernel32.dll ")]
static extern bool ReadProcessMemory(uint hProcess, IntPtr lpBaseAddress,
IntPtr lpBuffer, uint nSize, ref uint lpNumberOfBytesRead);

private void button1_Click(object sender, EventArgs e)
{

byte[] vBuffer = new byte[4];
IntPtr vBytesAddress = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0); // 得到缓冲区的地址
uint vNumberOfBytesRead = 0;
uint pro2 = 1; // 这里换成你的数值
ReadProcessMemory(pro2, (IntPtr)0xc0890c0, vBytesAddress,
(uint)vBuffer.Length, ref vNumberOfBytesRead);

int vInt = Marshal.ReadInt32(vBytesAddress); // 读取数据
}
------解决方案--------------------
首先你要确定0xc0890c0这个地址有值
你可以先用其他内存分析器看看

推荐一个我自己写的
http://download.csdn.net/source/160423

这些东西自己查MSDN吧,搜也可以,比我给你贴的更详细
Marshal 成员

提供了一个方法集,这些方法用于分配非托管内存、复制非托管内存块、将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法。

下表列出了由 Marshal 类型公开的成员。