又是一个apihook库正如谁对Windows API钩子感兴趣,有一个很好的库由微软出的Detours。它是非常有用的,但是它的免费版(“Express”)不支持64位环境。虽然它的商业版(“Professional”)支持的X64,它太昂贵,我负担不起的。它的费用约1万美元!
所以我决定写我自己的库或穷人的Detours。但我没有把我的库设计成为Detours的克隆产品。它只是API钩子的功能,因为这就是我想要的。
截至2015年1月,该库是用在一些项目:7+ Taskbar Tweaker, Better Explorer, DxWnd, NonVisual Desktop Access, Open Broadcaster Software, QTTabBar, x360ce 等……我很高兴我的项目可以帮助大家
hook MessageBoxW()示例
#include <Windows.h> #include “MinHook.h”
#if defined _M_X64
#pragma comment(lib, “libMinHook.x64.lib”)
#elif defined _M_IX86
#pragma comment(lib, “libMinHook.x86.lib”)
#endiftypedef int (WINAPI *MESSAGEBOXW)(HWND, LPCWSTR, LPCWSTR, UINT);
// Pointer for calling original MessageBoxW. MESSAGEBOXW fpMessageBoxW = NULL;
// Detour function which overrides MessageBoxW. int WINAPI DetourMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
return fpMessageBoxW(hWnd, L“Hooked!”, lpCaption, uType);
}int main()
{
// Initialize MinHook. if (MH_Initialize() != MH_OK)
{
return 1;
}// Create a hook for MessageBoxW, in disabled state. if (MH_CreateHook(&MessageBoxW, &DetourMessageBoxW,
reinterpret_cast<LPVOID*>(&fpMessageBoxW)) != MH_OK)
{
return 1;
}// or you can use the new helper funtion like this. //if (MH_CreateHookApiEx( // L”user32″, “MessageBoxW”, &DetourMessageBoxW, &fpMessageBoxW) != MH_OK) //{ // return 1; //}
// Enable the hook for MessageBoxW. if (MH_EnableHook(&MessageBoxW) != MH_OK)
{
return 1;
}// Expected to tell “Hooked!”. MessageBoxW(NULL, L“Not hooked…”, L“MinHook Sample”, MB_OK);
// Disable the hook for MessageBoxW. if (MH_DisableHook(&MessageBoxW) != MH_OK)
{
return 1;
}// Expected to tell “Not hooked…”. MessageBoxW(NULL, L“Not hooked…”, L“MinHook Sample”, MB_OK);
// Uninitialize MinHook. if (MH_Uninitialize() != MH_OK)
{
return 1;
}return 0;
}
更详细说明请看作者原文(E文滴):http://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra
暂无评论内容