模板网站建设清单,太原网站制作电话,免费分类信息网站源码,深圳优化百度第一步#xff1a;下载detours3.0#xff0c;安装detours 第二步#xff1a;构建库文件#xff0c;nmake编译 第三步#xff1a;包含库文件和头文件 #include “detours.h” //载入头文件 #pragma comment(lib,”detours.lib”) //表明要使用静态库 第四步#xf…第一步下载detours3.0安装detours 第二步构建库文件nmake编译 第三步包含库文件和头文件 #include “detours.h” //载入头文件 #pragma comment(lib,”detours.lib”) //表明要使用静态库 第四步定义旧函数指针指向原来的函数 static int (oldsystem)(const char _Command)system; 第五步声明一个和原函数参数相同的新函数 int newsystemA( char * _Command) { char *pstrstr(_Command,”tasklist”); if(pNULL) { oldsystem(_Command); } else { printf(“%s”,_Command); //找到了禁止执行 return 0; } return 0; }
第六步开始拦截 //开始拦截 void Hook() {
DetourRestoreAfterWith();//恢复原来状态,
DetourTransactionBegin();//拦截开始
DetourUpdateThread(GetCurrentThread());//刷新当前线程
//这里可以连续多次调用DetourAttach表明HOOK多个函数DetourAttach((void **)oldsystem, newsystemA);//实现函数拦截DetourTransactionCommit();//拦截生效} 第七步取消拦截 //取消拦截 void UnHook() {
DetourTransactionBegin();//拦截开始
DetourUpdateThread(GetCurrentThread());//刷新当前线程
//这里可以连续多次调用DetourDetach,表明撤销多个函数HOOK
DetourDetach((void **)oldsystem, newsystemA); //撤销拦截函数
DetourTransactionCommit();//拦截生效}
第八步:main函数运行大功告成 void main() { system(“calc”); Hook(); system(“calc”); system(“tasklist”); //UnHook(); getchar(); }
注意一定要在realse模式,而不是在debug模式下运行不然得不到想要的结果。