Detours简单hook
#include <windows.h> #include "../Detours/include/detours.h" #pragma comment(lib, "F:/小海在Po学校学习/小海的项目/Detours_Test/Detours/lib.X86/detours.lib") static int (WINAPI *OLDMessageBox)(HWND, LPCTSTR, LPCTSTR, UINT) = MessageBox; int WINAPI NewMessageBox( _In_opt_ HWND hWnd, _In_opt_ LPCTSTR lpText, _In_opt_ LPCTSTR lpCaption, _In_ UINT uType ) {
//这里可以实现你自己的功能。 return OLDMessageBox(hWnd, L"xiaohaige", lpCaption, uType); } void Hook() { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&(PVOID&)OLDMessageBox, NewMessageBox); //Hook DetourTransactionCommit(); } int _tmain(int argc, _TCHAR* argv[]) { MessageBox(nullptr, L"Detours_Test", L"Detours_test", MB_OK); Hook(); MessageBox(nullptr, L"Detours_Test", L"Detours_test", MB_OK); return 0; }