Im通过其函数偏移量在外部过程中 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 *,...)。
最佳答案
该功能可能太小而无法钩住。 Detours必须覆盖钩子(Hook)函数的一部分才能将调用重定向到其他地方,但是该日志记录 stub 中可能没有足够的空间供Detours编写针对替换的JMP指令。
关于c++ - 在 "empty"函数的外部过程中绕弯路,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7131475/