我已經下載並編譯了Microsoft繞道庫。在我的項目中,我已經包含了頭文件並添加了.lib文件作爲依賴項。一切編譯沒有錯誤。現在我一直試圖繞過DrawText,但由於某種原因,繞道函數根本不會被調用。我很熟悉地嘗試繞行睡眠功能,並且按照預期工作,並且我繞過的功能被調用。迂迴DrawText
我並不十分精通API編程的業務,也沒有任何其他低級別的活動。我懷疑它可能與我試圖在控制檯應用程序中執行此操作而不是在DLL中執行繞行有關。在這種情況下,我覺得很奇怪它可以繞過睡眠。
我的方法有問題嗎?或者錯誤在代碼中?
#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;
}
主要是你打電話睡眠,而不是DrawTextA,這只是一個複製/粘貼錯誤,或者這是你用過的一個真實例子? – 2009-09-09 18:21:10
如果我自己調用DrawTextA而不是睡眠,那麼調用我的路由函數來代替函數。我感興趣的是至少在全球範圍或其他窗口發生這種情況。 我希望有另一種方式比注入我的庫到應用程序。 – 2009-09-09 18:36:01