我通过函数偏移量在外部进程中 Hook 函数。到目前为止,这对于我 Hook 的函数来说效果很好——但是我发现一个“debugLog(char...)”函数仍然存在于二进制文件中但不进行任何打印——它看起来像这样
debugMessage proc near ;
xor eax, eax ; Logical Exclusive OR
retn ; Return Near from Procedure
debugMessage endp
它是这样称呼的
push offset debugString ; "This is a debug message"...
call debugMessage ; Call Procedure
现在调试消息显然已被禁用,我想连接到它,因为我已经能够简单地连接到二进制文件中的类似 func(char..)。
这是代码:
typedef void (__stdcall* DebugLog)(const char*);
DebugLog Real_DebugLog = (DebugLog)(0xCAFEBABE);
extern "C"
{
static void __stdcall Hook_DebugLog(const char*);
}
void __stdcall Hook_DebugLog(const char* text) {
MessageBox(NULL, text, "MyDebugLog", MB_OK);
return Real_DebugLog(text);
}
// in dll main attach..
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_DebugLog, (PVOID)Hook_DebugLog);
类似的方法适用于我目前已连接到此二进制文件中的所有其他功能。我还确保甚至使用调试器调用 debugMessage。
知道为什么这个钩子(Hook)根本不起作用吗?也许是因为函数可以有 var args?我已经尝试过使用 const char*,...)。
最佳答案
“绕行”需要至少 5 个字节才能工作 (x86) - debugMessage
只有 3 个字节。
关于c++ - "empty"函数的外部进程中的 Detours Hook 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7131475/