一直想玩黑客技术,今天正好找到一个detours的库,这是微软的出品的用来搞这类活动的库,下载下来,用了一下,把messagebox给劫持了,感觉各种好happy,23333333333
这里需要特别注意的一点是,一定要在release模式下使用,否则是显示不出效果的。
// ====================== 【API劫持】===========================
// @ author
:
zhyh2010
// @ date
:
20150530
// @ version
:
1.0
// @ description :
劫持 系统API 这里以 MessageBox 为例
//
注意 需要预先配置 detours
// @ detours 配置 :
//
安装后, 使用 nmake 编译源文件,并将相应文件拷贝到工程目录即可
//
【一定要用release模式编译 <^-^>】
// =================== 【end of API劫持】========================
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "detours.h"
#include "detver.h"
#pragma comment(lib, "detours.lib")
static int (WINAPI *OldMessageBoxA)(
HWND hWnd,
LPCWSTR lpText,
LPCWSTR lpCaption,
UINT uType) = MessageBoxA;
int WINAPI NewMessageBoxA(
HWND hWnd,
LPCWSTR lpText,
LPCWSTR lpCaption,
UINT uType)
{
printf(
"哈哈,你的函数被我劫持了哦<^_^>\n");
return 0;
}
VOID Hook()
{
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//这里可以连续多次调用DetourAttach,,表明HOOK多个函数
DetourAttach((
void **)&OldMessageBoxA, NewMessageBoxA);
DetourTransactionCommit();
}
VOID UnHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//这里可以连续多次调用DetourDetach,表明撤销多个函数HOOK
DetourDetach((
void **)&OldMessageBoxA, NewMessageBoxA);
DetourTransactionCommit();
}
void main()
{
MessageBoxA(
0,
"锄禾日当午1",
"学C真辛苦",
0);
Hook();
MessageBoxA(
0,
"锄禾日当午2",
"学C真辛苦",
0);
}