我正在尝试了解 VEH Hooks,我玩了几个小时,但我被困在挂钩非 WINAPI 函数上,我的意思是我自己定义的函数。我写了一个简单的程序,它调用一个带有 2 个 int 参数的 void 函数,这是一个应该被挂钩的函数,另一个是我们自己的挂钩回调函数。问题是我试图将“永远不会被调用”的函数挂在钩子上,但它已经在一个while循环中被调用,但我试图钩住一个像消息框和睡眠这样的winapi函数,它工作正常,我在做什么错误的?
我正在为 VEHHook 使用公共图书馆,即:https ://github.com/hoangprod/LeoSpecial-VEH-Hook
这是我为学习而做的代码。
#include <Windows.h>
#include <stdio.h>
#include "../HookDLL/LeoSpecial/VEHHook.h"
void FunctionHook(int a1, int a2)
{
printf("FunctionStart %p\r\n", FunctionHook);
printf("a1 %i && a2 %i\r\n", a1, a2);
printf("FunctionEnd\r\n");
}
void hkFunctionHook(int a1, int a2)
{
printf("hooked\r\n");
}
int main()
{
bool init = false;
while (true)
{
FunctionHook(26, 17);
Sleep(1000);
if (!init)
{
LeoHook vHook;
auto pAddress = (DWORD)GetModuleHandle(nullptr) + 0x1050;//Memory address of the function
/*
* push ebp <---- GetModuleHandle(nullptr) + 0x1050;
* mov ebp,esp
* and esp,-08
* push ecx
* push esi
* push HookTesting.exe+1050
* push HookTesting.exe+2100
* call HookTesting.exe+1010
* push [ebp+0C]
* mov esi,[ebp+08]
* push esi
* push HookTesting.exe+2114
* call HookTesting.exe+1010
* add esp,14
* push HookTesting.exe+2130
* call HookTesting.exe+1010
* add esp,04
* mov esp,ebp
* pop ebp
* ret
*/
auto IsHooked = vHook.Hook((uintptr_t)&pAddress, (uintptr_t)hkFunctionHook);
if (IsHooked)
printf("Successfully Hooked!\r\n");
else
printf("Failed to Hook!\r\n");
init = true;
}
}
getchar();
system("PAUSE");
return 0;
}