下载网址http://www.codeproject.com/Articles/21414/Powerful-x86-x64-Mini-Hook-Engine
#include "stdafx.h" #include "NtHookEngine_Test.h" #include <windows.h> #include <tchar.h> #include <stdlib.h> #include <malloc.h> #include <memory.h> #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif BOOL (__cdecl *HookFunction)(ULONG_PTR OriginalFunction, ULONG_PTR NewFunction); VOID (__cdecl *UnhookFunction)(ULONG_PTR Function); ULONG_PTR (__cdecl *GetOriginalFunction)(ULONG_PTR Hook); int WINAPI MyMessageBoxW(HWND hWnd, // handle to owner window LPCTSTR lpText, // text in message box LPCTSTR lpCaption, // message box title UINT uType); int /*APIENTRY*/ main() { // // Retrive hook functions // HMODULE hHookEngineDll = LoadLibrary(_T("NtHookEngine.dll")); HookFunction = (BOOL (__cdecl *)(ULONG_PTR, ULONG_PTR)) GetProcAddress(hHookEngineDll, "HookFunction"); UnhookFunction = (VOID (__cdecl *)(ULONG_PTR)) GetProcAddress(hHookEngineDll, "UnhookFunction"); GetOriginalFunction = (ULONG_PTR (__cdecl *)(ULONG_PTR)) GetProcAddress(hHookEngineDll, "GetOriginalFunction"); if (HookFunction == NULL || UnhookFunction == NULL || GetOriginalFunction == NULL) return 0; // // Hook MessageBoxTimeoutW // //HookFunction((ULONG_PTR) GetProcAddress(LoadLibrary(_T("User32.dll")), // "MessageBoxTimeoutW"), // (ULONG_PTR) &MyMessageBoxW); HookFunction((ULONG_PTR) GetProcAddress(LoadLibrary(_T("User32.dll")), "MessageBoxW"), (ULONG_PTR) &MyMessageBoxW); MessageBoxW(0, L"Hi, this is a message box!", L"This is the title.", MB_ICONINFORMATION); // // Unhook MessageBoxTimeoutW // UnhookFunction((ULONG_PTR) GetProcAddress(LoadLibrary(_T("User32.dll")), "MessageBoxW")); MessageBoxW(0, L"Hi, this is a message box!", L"This is the title.", MB_ICONINFORMATION); return 0; } int WINAPI MyMessageBoxW(HWND hWnd, // handle to owner window LPCTSTR lpText, // text in message box LPCTSTR lpCaption, // message box title UINT uType) { int (WINAPI *pMessageBoxW)(HWND hWnd, // handle to owner window LPCTSTR lpText, // text in message box LPCTSTR lpCaption, // message box title UINT uType); pMessageBoxW = (int (WINAPI *)(HWND, LPCTSTR, LPCTSTR, UINT)) GetOriginalFunction((ULONG_PTR) MyMessageBoxW); //return pMessageBoxW(hWnd, lpText, L"Hooked MessageBox", // uType, wLanguageId, dwMilliseconds); return pMessageBoxW(hWnd, "1", "1", uType); }