stevemk14ebr / PolyHook_2_0

C++20, x86/x64 Hooking Libary v2.0
MIT License
1.58k stars 222 forks source link

MessageBoxW & EatHook #163

Closed rxznve closed 1 year ago

rxznve commented 1 year ago

Hello. I can't install the EAT hook on MessageBoxW. What am I doing wrong?

#include <Windows.h>

#include <iostream>
using std::cout, std::endl;

#include "PolyHook 2/Include/polyhook2/PE/EatHook.hpp"
#pragma comment(lib, "PolyHook 2/Library/PolyHook_2.lib")

decltype(&MessageBoxW) fpMessageBoxW = nullptr;

int WINAPI myMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
    return fpMessageBoxW(hWnd, L"Hooked!", lpCaption, uType);
}

int main()
{
    PLH::EatHook msgHook("MessageBoxW", L"user32.dll", (uint64_t)myMessageBoxW, (uint64_t*)&fpMessageBoxW);

    if (!msgHook.hook())
        cout << "[EAT] EAT hooking MessageBoxW failed!" << endl;

    MessageBoxW(nullptr, L"Hello World!", L"Notify", MB_OK);

    return 0;
}