25.Detours劫持技术

Detours可以用来实现劫持,他是微软亚洲研究院开发出来的工具,要实现它首先需要安装Detours.

安装地址链接:https://pan.baidu.com/s/1eTolVZs 密码:uy8x

1 //取消拦截  
2 _declspec(dllexport) void UnHook()
3 {
4     DetourTransactionBegin();//拦截开始  
5     DetourUpdateThread(GetCurrentThread());//刷新当前线程  
6     //这里可以连续多次调用DetourDetach,表明撤销多个函数HOOK  
7     DetourDetach((void **)&oldsystem, newsystem); //撤销拦截函数  
8     DetourTransactionCommit();//拦截生效  
9 }
  • 劫持自己
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <Windows.h>
 4 #include "detours.h"//包含头文件必须包含detours.h
 5 #pragma comment(lib,"detours.lib") //包含库文件
 6 
 7 int  (*poldsystem)(const char * _Command) = system;//存放老的函数地址
 8 
 9 
10 int my_system(const char * _Command)
11 {
12     printf("%s", _Command);//打印
13     return 1;
14 }
15 
16 void hook()
17 {
18     DetourRestoreAfterWith();//恢复之前的状态,避免反复拦截
19     DetourTransactionBegin();//开始劫持
20     DetourUpdateThread(GetCurrentThread());//刷新当前的线程
21     DetourAttach((void **)&poldsystem,my_system);//劫持
22     DetourTransactionCommit();//立刻生效
23 }
24 
25 void main()
26 {
27     system("notepad");
28     hook();
29     system("notepad");
30 
31     getchar();
32 }
View Code
posted @ 2018-01-13 10:46  喵小喵~  阅读(205)  评论(0编辑  收藏  举报