C# ReadProcessMemory: How to read a 64 bit memory address?

前端 未结 1 414
傲寒
傲寒 2020-12-03 02:00

I am getting into reading application memory. I am using CheatEngine to get a memory address and then trying to return it\'s value. However, CheatEngine seems to be return

相关标签:
1条回答
  • 2020-12-03 02:43

    You can path lpBaseAddress as Int64. Try replace your

    [DllImport("kernel32.dll")]
        public static extern bool ReadProcessMemory(int hProcess,
        int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
    

    to

    [DllImport("kernel32.dll")] 
    public static extern bool ReadProcessMemory(int hProcess,
        Int64 lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead); 
    

    But most correct implementation:

    [DllImport("kernel32.dll")]
    static extern bool ReadProcessMemory(IntPtr hProcess,
        IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);
    
    0 讨论(0)
提交回复
热议问题