Minhook,全局变量的问题. C++ [关闭]

vfhzx4xs  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(120)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
3天前关闭。
Improve this question
我有以下代码:https://github.com/DisassemblyIDA/GlobalVarribleHelp/blob/main/main.cpp(由于stackoverflow说问题没有得到充分描述,所以被转发到github)
这将挂钩“build”函数,获取其参数,并将其分配给以下变量:

DWORD* fisrtarg = __this;
DWORD* secondarg = BuildingDef;
DWORD* thirdarg = method;

字符串
然后我禁用钩子(手动)并使用接收到的参数调用“buildcall”,但由于某些未知原因,所有三个参数都有地址00000000。我如何才能使它们具有我在钩子时分配给它们的地址?
我一直在试图找出问题所在,但我还没有找到关于我的问题的有用信息。

41zrol4v

41zrol4v1#

在此程式码中:

DWORD* fisrtarg;
DWORD* secondarg;
DWORD* thirdarg;

bool __cdecl build_h(DWORD* __this, DWORD* BuildingDef, DWORD* method) {
    DWORD* fisrtarg = __this;
    DWORD* secondarg = BuildingDef;
    DWORD* thirdarg = method;
    std::cout << fisrtarg << BuildingDef << method << std::endl;
    std::cout << "Values gotten!!!" << std::endl;
    return true;
}

字符串
有局部变量firstargsecondargthirdarg隐藏全局变量,因此全局变量永远不会被设置
你希望你的build_h函数看起来像这样:

bool __cdecl build_h(DWORD* __this, DWORD* BuildingDef, DWORD* method) {
    fisrtarg = __this;
    secondarg = BuildingDef;
    thirdarg = method;


也就是说,只分配给全局变量,不要将它们重新声明为本地副本。

相关问题