c语言编写劫持dll,c语言-----劫持自己02
在上一節?c語言-----劫持原理01 已經敘述了劫持原理,下邊正式進入劫持實戰
1. 需要實現的功能
在c語言中
system("notepad") 可以打開一個記事本
system("mspaint") 可以打開畫圖工具
所以這次我們需要把 可以打開一個記事本? 這個功能更改為 在控制臺打印 "notepad"
可以打開畫圖工具????? 這個功能更改為 在控制臺打印 "mspaint"? ,即實現監控的日志功能
2. 需要的工具
vs2017
Detours
3.? 劫持原理實現
(1) 查看system()函數定義
_DCRTIMP int __cdecl system(
_In_opt_z_ char const* _Command
);
去掉一些不需要的符號
int system( char const* _Command );
(2) 獲取原system()的地址
int (*plodsystem)(char const* _Command) = system;
(3) 劫持后system()函數
int newsystem(char const* _Command){
printf("你執行的是:%s", _Command);
}
(4) 劫持函數
void hook(){
DetourRestoreAfterWith(); //恢復之前的狀態
DetourTransactionBegin(); //開始劫持
DetourUpdateThread(GetCurrentThread());//更新當前線程
DetourAttach((void **)&plodsystem, newsystem);//劫持
DetourTransactionCommit(); //提交
}
(5) 修改vs配置? Debug -> Release
(6) 完整源代碼
#include
#include
#include
#include "detours.h"
#pragma comment(lib,"detours.lib")
int (*plodsystem)(char const* _Command) = system;
int newsystem(char const* _Command){
printf("你執行的是:%s", _Command);
}
void hook(){
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((void **)&plodsystem, newsystem);
DetourTransactionCommit();
}
int main(){
system("notepad");
hook();
system("notepad");
return 0;
}
3. 解釋說明
system()函數是一個int類型的函數?int system( char const*_Command );
所以需要一個一級函數指針plodsystem
獲取plodsystem的地址 &plodsystem,需要一個二級指針
總結
以上是生活随笔為你收集整理的c语言编写劫持dll,c语言-----劫持自己02的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux进去网卡,Linux上使用so
- 下一篇: linux lanmp 安装教程,lin