15,471
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <cstdio>
#include <windows.h>
#include <detours.h>
#pragma comment(lib,"detours.lib")
int (WINAPI *pMessageBoxW)(HWND hWnd ,
LPCWSTR lpText,
LPCWSTR lpCaption,
UINT uType) = MessageBoxW;
int WINAPI MyMessageBoxW(HWND hWnd ,
LPCWSTR lpText,
LPCWSTR lpCaption,
UINT uType)
{
MessageBox(NULL,"MessageBox被拦截","API",MB_OK);
return pMessageBoxW(hWnd,lpText,lpCaption,uType);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
int error;
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pMessageBoxW, MyMessageBoxW);
if(DetourTransactionCommit() == NO_ERROR)
OutputDebugString("send() detoured successfully");
}
break;
case DLL_PROCESS_DETACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)pMessageBoxW, MyMessageBoxW);
DetourTransactionCommit();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}