学习笔记之劫持自身:
#pragma comment(lib,"detours.lib")//包含头文件
int(*plodsystem)(char const* _Command) = system;
int newsystem(_In_opt_z_ char const* _Command)
{
//下面的代码可以记录输入的system指令并执行
printf("你输入是:%s\n", _Command);
plodsystem(_Command);
//下面这句代码可以将输入的system指令直接打印出来,并不执行
//printf("%s", _Command);
return 0;
}
void hook()
{
DetourRestoreAfterWith(); //恢复之前的状态,避免反复拦截
DetourTransactionBegin();//开始劫持
DetourUpdateThread(GetCurrentThread()); //刷新当前线程
DetourAttach((void**)&plodsystem,newsystem); //劫持
DetourTransactionCommit();//立刻生效
}
void main()
{
system("notepad");//劫持之前
hook(); 开始劫持
system("notepad");查看劫持之后效果
system("tasklist");查看劫持之后效果
getchar();
return;
}