Hook入门之Detour库
2016-01-07 DOCS API detour hook window
一、编译 detour 库
系统环境:WIN7 X64、VS2015、Detours Express 3.0
编译时如果出错,尝试修改Detours src目录下Makefile中CFLAGS:移除 /WX 即可
编译结果为lib.X86版,Detour 3.0 只有detours.lib 没有detoured.lib。
二、使用
复制 Detours目录\include\ 目录所有文件 给VC的include目录
复制 Detours目录\lib.X86\ 目录所有文件 给VC的lib目录
三、例子
#include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <Windows.h> #include <detours.h> void RealFunc( int num ) {printf("Real number: %d\n", num);} //Real Function void HookFunc( int num ) {printf("Hooked number: %d", num*2);} //Hook Function void(*realfunction)(int) = RealFunc; int main(){ //call the real function RealFunc(1014); //hook the real function DetourTransactionBegin(); DetourUpdateThread( GetCurrentThread() ); DetourAttach( &(PVOID&)realfunction, HookFunc ); if (DetourTransactionCommit() != NO_ERROR) return 0; printf( "RealFunc hooked successfully!\n" ); //call the real function agian RealFunc(1024); getchar(); return 0; }
暂无评论