DetourAttach 因非法指令 0xC000001D 而中断

逆向工程 C++ 函数挂钩 dll注入 api-reversing
2021-06-20 18:39:39

我正在尝试以DetourAttach()以下方式绕过一个函数

hooks::logDebug("swresample-3Proxy.log", fmt::format("Try to attach hook. Function {:p}, hook {:p}.",
    *hook.first, hook.second));
writeProtectedMemory(hook.first, hook.second);
auto result = DetourAttach(hook.first, hook.second);

其中 hook.first = 0x00007ff69f119ea0 {Gladius.exe!gladius::Game::main(int,char * *,char * *)} {0x8b4820ec83485340} void * *

钩子.秒 = 0x00007ff818f51ef5 {swresample-3.dll!hooks::gamemainHooked(struct gladius::Game *,int,char * *,char * *)} void *

但结果出现以下错误:

在 Gladius.exe 中的 0x00007FF69F119EA1 处引发异常:0xC000001D:非法指令。

以及跳转指令应该在哪里的问号(见截图)。

绕道函数的记忆

希望得到一些帮助来解决这个问题......

1个回答

修复了使用EasyHook而不是 Detours 的问题。即替换了这段代码:

writeProtectedMemory(hook.first, hook.second);
auto result = DetourAttach(hook.first, hook.second);

有了这个:

HOOK_TRACE_INFO hHook = { NULL }; // keep track of our hook
NTSTATUS result = LhInstallHook(
    hook.first,
    hook.second,
    NULL,
    &hHook);

ULONG ACLEntries[1] = { 0 };
LhSetInclusiveACL(ACLEntries, 1, &hHook);

其中 hook.first = 0x00007ff69f119ea0 {Gladius.exe!gladius::Game::main(int,char * *,char * *)} {0x8b4820ec83485340} void * *

和 hook.second = 0x00007ff818f51ef5 {swresample-3.dll!hooks::gamemainHooked(struct gladius::Game *,int,char * *,char * *)} void *

现在应用程序正确跳转到 Hooked 函数。

PS 不知道 DetoursAttach() 对 x64 的处理是什么。我专门为该环境编译了它。

可能它不知道如何在线程之间传递钩子......稍后会检查该选项。