如何在c ++中为地址添加偏移量?

时间:2017-10-12 15:36:35

标签: c++ pointers offset

public class Person extends SuperPerson { private static final long serialVersionUID = 1L; } public class SuperPerson { private static final long serialVersionUID = 1L; }

我正在尝试编写进程内存,但我不知道如何向地址添加偏移量。

这就是我想要实现的目标:https://gyazo.com/5768b622f8c7f66c00e5be68aae42c90

1 个答案:

答案 0 :(得分:0)

您需要取消引用第一个地址,即指针。

uintptr_t FindDMAAddy(HANDLE hProc, uintptr_t ptr, std::vector<unsigned int> offsets)
{
    uintptr_t addr = ptr;
    for (unsigned int i = 0; i < offsets.size(); ++i)
    {
        ReadProcessMemory(hProc, (BYTE*)addr, &addr, sizeof(addr), 0);
        addr += offsets[i];
    }
    return addr;
}

uintptr_t finalAddr = FindDMAAddy(hProc, 0x771346D0, {0xc4});

int newAmmoValue = 99999;

WriteProcessMemory(handle, (LPVOID)finalAddr, &newAmmoValue, sizeof(newAmmoValue), 0);