【发布时间】:2026-02-05 00:55:01
【问题描述】:
我已经下载并编译了 Microsoft detouring 库。在我的项目中,我包含了头文件并添加了 .lib 文件作为依赖项。一切都编译没有错误。现在我一直在尝试绕过 DrawText,但由于某种原因,根本没有调用 detoured 函数。类似地,我尝试绕过 Sleep 函数,它按预期工作,并且调用了我绕过的函数。
我不太精通 API 编程业务或任何其他低级活动。我怀疑这可能与我试图在控制台应用程序中执行此操作而不是在 DLL 中完成绕行这一事实有关。我只是觉得奇怪的是,在这种情况下它能够绕过 Sleep。
我的方法有问题还是代码有问题?
#include <windows.h>
#include <stdio.h>
#include "detours.h"
int ( WINAPI *Real_DrawText )(HDC a0, LPCSTR a1, int a2, LPRECT a3, UINT a4) = DrawTextA;
int Mine_DrawText(HDC hdc, LPCSTR text, int nCount, LPRECT lpRect, UINT uOptions)
{
printf("TEST");
return Real_DrawText(hdc, text, nCount, lpRect, uOptions);
}
int main(int argc, char **argv)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourTransactionCommit();
printf("Calling Sleep\n");
Sleep(1000);
printf("Second callout");
Sleep(5000);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourTransactionCommit();
return 0;
}
【问题讨论】:
-
在 main 中,您调用的是 Sleep 而不是 DrawTextA,这只是复制/粘贴错误还是您使用过的真实示例?
-
如果我自己调用 DrawTextA 而不是 sleep,那么我的路由函数会被调用来代替函数。我有兴趣在全球范围内或至少在另一个窗口中发生这种情况。我希望有另一种方法,而不是将我的库注入应用程序。