Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “外部过程中的弯道挂钩”;“空的”;函数不起作用_C++_Assembly_Detours - Fatal编程技术网

C++ “外部过程中的弯道挂钩”;“空的”;函数不起作用

C++ “外部过程中的弯道挂钩”;“空的”;函数不起作用,c++,assembly,detours,C++,Assembly,Detours,Im通过函数偏移将函数挂接到外部进程中。到目前为止,这对我挂接的函数很有效-但是我发现一个“debugLog(char…)函数仍然存在于二进制文件中,但不进行任何打印-它看起来像这样 debugMessage proc near ; xor eax, eax ; Logical Exclusive OR retn ; Return Near from P

Im通过函数偏移将函数挂接到外部进程中。到目前为止,这对我挂接的函数很有效-但是我发现一个“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
就这样叫

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


你知道为什么这个钩子不起作用吗?可能是因为函数可能有var args?我已经尝试使用const char*,…)。

该函数可能太小而无法钩住。Detours必须覆盖hooked函数的一部分,以便将调用重定向到其他位置,但该日志存根中可能没有足够的空间来编写针对替换对象的JMP指令。

一个“Detours”至少需要5个字节才能工作(x86)-
debugMessage
只有3个字节。

谢谢您的具体回答,您知道其他解决方案吗?您可以使用软件或硬件断点。看看是的,至少软件断点可能会有帮助。您可以将0xcc(int3)替换为要挂接的函数的第一个字节,并提供一个陷阱处理程序。这里提到的向量异常处理(VEH)Noergaard可能会有所帮助。唯一的其他方法是绕道所有调用站点