简体   繁体   中英

How can I find the value of what a memory address currently holds?

How do you read the address of a program and return the value of what ever the data the address holds? I have the following code which reads an offset address of a program, but I would like to return the value of the address that I'm checking to do some other stuff with it.

inline Mem *Read(DWORD64 address)
{
    this->value = address;
    return (this->r(0));
}

inline Mem *r(DWORD64 ofs)
{
    if (!this || !value)
        return 0;

    if (!ReadProcessMemory(Handle, (void*)(value + ofs), &value, sizeof(DWORD64), 0))
        return 0;

    return this;
}



m.Read(0x1428003C0)->r(0x100);

For example, so I read the offset 0x100 inside the address 0x1428003C0, I know it holds the value of vehicle speed how can I return the speed value from that address? I would like to find out the speed and depends on the speed I would apply breaks or accelerate. I have tried to cout the m.read command, and I get weird garbage that I do not understand. I'm guessing it's the static memory address of the program that I'm currently reading?

On successful return value should contain the content of the memory. You need to check the documentation to determine what format that is.

However, as a first guess I would try:

Mem m;
if (m.Read(0x1428003C0)->r(0x100) )
{
    double* val = (double*)(&m.value);
    if (val != nullptr)
    std::cout << *val << std::endl;
}

If you know you have a valid address you can simply cast it to the right pointer type to read the memory. Note that this is dangerous if you don't have a valid address the result is undefined behavior, and you could just be reading garbage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM