简体   繁体   English

如何找到当前存储地址的值?

[英]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? 例如,因此我读取了地址0x1428003C0内的偏移量0x100,我知道它保存了车辆速度值,如何从该地址返回速度值? 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. 我试图coutm.read命令,我得到奇怪的垃圾,我不明白。 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. 成功返回value应包含内存的内容。 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. 请注意,如果您没有有效的地址,这将是危险的,结果是未定义的行为,并且您可能只是在读取垃圾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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