【问题标题】:pointer not returning the value correctly指针未正确返回值
【发布时间】:2019-11-01 14:58:20
【问题描述】:

我在我的程序中返回指针的值有问题,指针的值没有被保存,当它读取时它返回null。

标题代码:

class PlayerHK : public Player {
public:
    PlayerHK();

    ULONG player_hp();
    ULONG player_power();
    ULONG player_hp2();
    ULONG player_power2();

private:

    struct CPlayer
    {
        BYTE padding[0x20];
        ULONG hp;
        ULONG power;
    };

    CPlayer *player;
};

主代码:

PlayerHK::PlayerHK() {

        player = reinterpret_cast<CPlayer*>(*reinterpret_cast<DWORD*>(0x00B1C4E5));

    }

    ULONG PlayerHK::player_hp() {
        return player->hp; //does not return the value
    }

    ULONG PlayerHK::player_power() {
        return player->power; //does not return the value
    }

    ULONG PlayerHK::player_hp2() {
        player = reinterpret_cast<CPlayer*>(*reinterpret_cast<DWORD*>(0x00B1C4E5));
        return player->hp; //returns the value
    }

    ULONG PlayerHK::player_power2() {
        player = reinterpret_cast<CPlayer*>(*reinterpret_cast<DWORD*>(0x00B1C4E5));
        return player->power; //returns the value
    }

当我运行的程序读取 PlayerHK 时,值不应该被保存?我是不是忘了做点什么?

【问题讨论】:

  • reinterpret_cast&lt;CPlayer*&gt;(*reinterpret_cast&lt;DWORD*&gt;(0x00B1C4E5)) 你觉得这有什么作用?
  • 几分钟前我评论了这个问题。为什么删了又问?
  • @eerorika 显然它不可移植地读取地址 0x00B1C4E5 处的值并将其视为 CPlayer 结构的地址。
  • 0x00B1C4E5是拾取指针的地址。
  • @user4581301 我相信这段代码被加载到另一个进程中,并想从主程序中读取值(可能是为了在游戏中作弊)。所以这些值的地址是通过对游戏进行逆向工程提前知道的,但是没有其他方法可以引用它们。

标签: c++ pointers reverse-engineering


【解决方案1】:

如果我理解正确,你就是在问为什么

player = reinterpret_cast<CPlayer*>(*reinterpret_cast<DWORD*>(0x00B1C4E5));

在构造函数中运行时将 player 设置为 NULL,但在 player_hp2 或 player_power2 中运行时不会。

显而易见的答案是,这个内存位置 (0x00B1C4E5) 在您构造对象时保持值 NULL,而在调用 player_hp2 或 player_power2 时保持不同的值。可能在构造函数运行时播放器尚未创建,因此指向播放器的指针(您正在读取)为 NULL。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 2018-05-30
    相关资源
    最近更新 更多