[DllImport("Kernel32.dll")]
public static extern unsafe int ReadProcessMemory(int hProcess, int lpBaseAddress, int lpBuffer, int nSize, int* lpNumberOfBytesRead);
这样对吗?如果要读0c0890c0这个地址,
Hbf1=ReadProcessMemory(pro2,&0c0890c0,参数三,参数四);
对吗?后两个参数要怎么写。如果函数成功,那函数的返回值就是那个地址的值吧,,

解决方案 »

  1.   

    用PerformanceCounter吧,速度也很快的。
      

  2.   

    [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); // 读取数据
      

  3.   

    谢谢
    PerformanceCounter那它又怎么用呢,能讲讲吗,
    没找着
      

  4.   

    有错误,想半天,想不出哪错了错误 1 应输入 ) C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 47 WindowsApplication1
    错误 2 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 54 WindowsApplication1
    错误 3 无效的表达式项“,” C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 54 WindowsApplication1
    错误 4 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 55 WindowsApplication1
    错误 5 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 68 WindowsApplication1
    错误 6 无效的表达式项“,” C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 68 WindowsApplication1
    错误 7 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 69 WindowsApplication1
    错误 8 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 89 WindowsApplication1
    错误 9 无效的表达式项“,” C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 89 WindowsApplication1
    错误 10 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 90 WindowsApplication1
    错误 11 无效的表达式项“ref” C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 90 WindowsApplication1
    错误 12 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 94 WindowsApplication1
    错误 13 应输入 ; C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 112 WindowsApplication1
    错误 14 无效的表达式项“)” C:\Documents and Settings\angel\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\Form1.cs 31 112 WindowsApplication1
      

  5.   

    别忘记引用using System.Runtime.InteropServices;别贴一堆错误提示,只有第一条就成了
    贴你的调试代码才是最重要的
      

  6.   

    看MSDN先学会C++里怎么掉你才清楚
      

  7.   

    using System.Runtime.InteropServices有这个,
    MSDN看了,英文,看得不是太懂?就加了这段段后出的错误
    [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); // 读取数据
      

  8.   

    ReadProcessMemory(pro2, (IntPtr)0c0890c0, vBytesAddress, vBytesAddress.Length, ref vNumberOfBytesRead);
    出在这句,后四个参数上,不明白哪错了 ???
      

  9.   

    //参考这样写
    [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); // 读取数据
    }
      

  10.   

    谢谢,可以了,不过读出来的int vInt = Marshal.ReadInt32(vBytesAddress); // 读取数据
    总是0另外,Marshal是什么意思?
    Marshal.UnsafeAddrOfPinnedArrayElement
    Marshal.ReadInt32(vBytesAddress);
      

  11.   

    首先你要确定0xc0890c0这个地址有值
    你可以先用其他内存分析器看看推荐一个我自己写的
    http://download.csdn.net/source/160423这些东西自己查MSDN吧,搜也可以,比我给你贴的更详细
    Marshal 成员 提供了一个方法集,这些方法用于分配非托管内存、复制非托管内存块、将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法。下表列出了由 Marshal 类型公开的成员。 
      

  12.   

    想问一下  如果地址不是给定的地址 如楼主提出来的 地址为0c0890c0   我想把地址存放到一个Uint的变量里 又改怎么写这个readProcessmemory 函数