将ReadProcessMemory与进程模块基址和偏移一起使用

时间:2017-05-19 07:44:46

标签: c# pointers memory process memory-address

如何使用过程模块的基址和偏移读取内存?我已经使用以下内容获取了所需模块的基址:

        Process process = Process.GetProcessesByName("process")[0];
        ProcessModule bClient;
        ProcessModuleCollection bModules = process.Modules;
        IntPtr processHandle = OpenProcess(0x10, false, process.Id);
        int firstOffset = 0xA4C58C;
        int anotherOffset = 0xFC;

        for (int i = 0; i < bModules.Count; i++)
        {
            bClient = bModules[i];
            if (bClient.ModuleName == "module.dll")
            {
                IntPtr baseAddress = bClient.BaseAddress;
                Console.WriteLine("Base address: " + baseAddress);
            }
        }

之后我将第一个偏移量添加到基地址:

IntPtr firstPointer = IntPtr.Add(baseAddress, (int)firstOffset);

这给了我一个指针;在这种情况下为440911244。

例如,我可以在Cheat Engine中使用此指针来浏览其内存区域并找到anotherPointer指向的值但我找不到将偏移量添加到{{{0}的正确方法然而,1}}。

我的问题是,在将最终firstPointer添加到指针之前,是否必须使用ReadProcessMemory?如果是这样,在这种情况下使用它的正确方法是什么?

anotherOffset

1 个答案:

答案 0 :(得分:0)

将ReadProcessMemory lpBuffer参数更改为:

byte[] lpBuffer,

然后

byte[] buffer = new byte[sizeof(float)];
IntPtr bytesRead = IntPtr.Zero;

IntPtr readAddress = IntPtr.Add(baseAddress, firstOffset);
readAddress = IntPtr.Add(readAddress, anotherOffset)

ReadProcessMemory(processHandle, readAddress, buffer, buffer.Length, out bytesRead);

float value = BitConverter.ToSingle(buffer, 0);