使用DLL基址读取内存

时间:2013-08-25 16:54:17

标签: c# winforms memory dll readprocessmemory

我正在尝试在一个过程(游戏)中阅读float

查看作弊引擎我可以找到我需要的地址,但它位于wow64cpu.dll + 4720,偏移量为34。

因此我尝试在此过程中找到wow64cpu.dll的基地址,但这是我感到困惑的地方。

我不明白现在如何使用这个地址,因为我所有的尝试似乎都没有了。

        Process[] processes = Process.GetProcessesByName("Napoleon");
        Process process = processes[0];

        ProcessModuleCollection modules = process.Modules;
        ProcessModule dllBaseAdress = null;
        foreach (ProcessModule i in modules)
        {
            if (i.ModuleName == "wow64cpu.dll")
            {
                dllBaseAdress = i;
                break;
            }
        }

        IntPtr dllPtr = dllBaseAdress.BaseAddress;
        int pointer = dllPtr.ToInt32() + 0x4720;
        int offset = 34;

        IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);

        int bytesRead;
        byte[] buffer = new byte[4];

        ReadProcessMemory(hProc, new IntPtr(pointer + offset), buffer, 4, out bytesRead);

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

我的问题是我在使用DLL的基地址或其他地方时出错了,我不确定如何使用它来查找我的地址?

我还在x64中编译了程序,否则它将找不到wow64cpu.dll。

由于

1 个答案:

答案 0 :(得分:4)

您的偏移量必须添加到位置wow64cpu.dll + 4720处读取的指针,因此如果您的地址正确,则浮动位置位于[wow64cpu.dll + 4720] + 30

您的代码将是

// Set the addresses to read
var pointer = dllPtr.ToInt32() + 0x4720;
var offset = 34;
// Initialize the buffers
var buffer = new byte[4];

// Find the pointer
ReadProcessMemory(hProc, new IntPtr(pointer), buffer, 4, out bytesRead);
pointer = BitConverter.ToInt32(buffer, 0);
// Add the offset to the value previously found
ReadProcessMemory(hProc, new IntPtr(pointer + offset), buffer, 4, out bytesRead);
var lightColourScale = BitConverter.ToSingle(buffer, 0);

尽管如此,手动调用所有这些功能真的很痛苦。我强烈建议你使用一个注入库,它包含所有这些调用。

图书馆MemorySharp对你没问题(我是作者)。在您的情况下,您可以编写以下代码。

using (var memory = new MemorySharp(ApplicationFinder.FromProcessName("Napoleon").First()))
{
    var myValue = memory.Read<float>(memory["wow64cpu.dll"].Read<IntPtr>(4720) + 34, false);
}

Cheat Engine以十六进制表示其值。你在使用它们之前是否在十进制中转换它们?

此外,另一个问题与您的问题类似:Find address using pointer and offset C#

相关问题