#include <windows.h> #include <stdio.h> #include "NtHookEngine\\NtHookEngine.h" #pragma comment(lib, "NtHookEngine\\NtHookEngine.lib") VOID HookAPI(); VOID UnHookAPI(); typedef int (WINAPI *pfnMessageBoxW)(IN HWND hWnd, IN LPCWSTR lpText, IN LPCWSTR lpCaption, IN UINT uType); pfnMessageBoxW Kernel_MessageBoxW = MessageBoxW; int WINAPI MyMessageBoxW( IN HWND hWnd, IN LPCWSTR lpText, IN LPCWSTR lpCaption, IN UINT uType) { MessageBoxA(hWnd, "Hooked!!", "hi", MB_OK); Kernel_MessageBoxW = (pfnMessageBoxW)GetOriginalFunction((ULONG_PTR) MyMessageBoxW); return Kernel_MessageBoxW(hWnd, lpText, lpCaption, uType); } VOID HookAPI() { NtHookEngineInit(); HookFunction((ULONG_PTR)Kernel_MessageBoxW, (ULONG_PTR) &MyMessageBoxW); } VOID UnHookAPI() { UnhookFunction((ULONG_PTR)Kernel_MessageBoxW); } VOID main() { printf("NtHookEngine Test By PiaoYun/P.Y.G...\n"); MessageBoxW(NULL, L"开始!", L"P.Y.G", MB_OK); HookAPI(); MessageBoxW(NULL, L"测试1", L"P.Y.G", MB_OK); MessageBoxW(NULL, L"测试2", L"P.Y.G", MB_OK); UnHookAPI(); MessageBoxW(NULL, L"UnHooked!!", L"hi", MB_OK); system("pause"); }
头文件:
/* NtHookEngine.h 由飘云修改为静态库,并添加头文件 http://bbs.chinapyg.com http://www.dllhook.com */ #ifdef __cplusplus extern "C" { #endif VOID __cdecl NtHookEngineInit(); ULONG_PTR __cdecl GetOriginalFunction(ULONG_PTR Hook); BOOL __cdecl HookFunction(ULONG_PTR OriginalFunction, ULONG_PTR NewFunction); VOID __cdecl UnhookFunction(ULONG_PTR Function); #ifdef __cplusplus } #endif
发表评论