DetourHook库使用

来源:互联网 发布:好孩子淘宝店是正品吗 编辑:程序博客网 时间:2024/06/09 14:54
如果公司比较大 千万不要用他 容易引来官司
红色的版本和下面的版本 是一样的 的但是红色的部分是收费的 都是开源的
自己用没有问题
https://www.microsoft.com/en-us/research/project/detours/?from=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fprojects%2Fdetours%2F
官方资料
下载文件


src 是他所有的源码
samples 是他的实例

detours.chm 是帮助信息


用法 有两种
1 把源码直接拷过去
2 生成 dll 使用头文件
找到vs 的工具 主要有 x64和 x68

先转入 当前路径
输入 nmake 自动查找当前路径的Makefile
生成 x86的 x64 同上
include 是头文件
lib 是lib 没有dll只能使用静态库

用来做 不同的


测试代码


#include "../Detours/include/detours.h"#ifdef  _WIN32#pragma  comment(lib,"../Detours/lib.X86/detours.lib")#else#pragma  comment(lib,"../Detours/lib.X64/detours.lib")#endif //_WIN32static  int(WINAPI *OLDMessageBoxW)(HWND, LPCTSTR, LPCWSTR, UINT)=MessageBoxW;int WINAPI NewMessageBox(_In_opt_ HWND    hWnd,_In_opt_ LPCTSTR lpText,_In_opt_ LPCTSTR lpCaption,_In_     UINT    uType){return  OLDMessageBoxW(nullptr, L"bbbb", lpCaption, uType);}void Hook(){int error = DetourTransactionBegin();//检测开始if (error !=NO_ERROR){printf("BeginError");}DetourUpdateThread(GetCurrentThread());//执行线程准备DetourAttach(&(PVOID&)OLDMessageBoxW, NewMessageBox);//挂钩DetourTransactionCommit();//检测}int _tmain(int argc, _TCHAR* argv[]){MessageBoxW(nullptr, L"aa", L"aa", MB_OK);Hook();MessageBoxW(nullptr, L"aa", L"aa", MB_OK);return 0;}

下载demo

http://download.csdn.net/download/w739639550/10124949


原创粉丝点击