An open-source x64 hooking library for Windows.
- Download and install Visual Studio 2017 Community Edition or a higher version.
- Clone this repository.
- Extract the content of PREMAKE 5 into Premake directory.
- Go to the Premake directory and run GenerateVisualStudioProjects.bat.
- Open the solution (RenHook.sln) located in Premake/Projects directory.
- Build the projects.
#include <RenHook/RenHook.hpp>
int IsDebuggerPresentFunction()
{
return 0;
}
int main()
{
RenHook::Hook::Create(L"kernel32", L"IsDebuggerPresent", &IsDebuggerPresentFunction);
std::cout << IsDebuggerPresent() << std::endl;
return 0;
}
#include <RenHook/RenHook.hpp>
MessageBoxWFunction(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
auto Hook = RenHook::Hook::Get(L"user32", L"MessageBoxW");
using MessageBoxW_t = int(*)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
return Hook->Call<MessageBoxW_t>(hWnd, L"Hello from the hook!", L"Hooked MessageBoxW", MB_OK);
}
int main()
{
RenHook::Hook::Create(L"user32", L"MessageBoxW", &MessageBoxWFunction);
MessageBoxW(nullptr, L"Hello", L"MessageBoxW", MB_OK);
return 0;
}
Trampolines (with std::shared_ptr)
#include <RenHook/RenHook.hpp>
std::shared_ptr<RenHook::Hook> MessageBoxWHook;
int MessageBoxWFunction(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
using MessageBoxW_t = int(WINAPI*)(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
return MessageBoxWHook->Call<int, MessageBoxW_t>(hWnd, L"Hello from the hook!", L"Hooked MessageBoxW", MB_OK);
}
int main()
{
MessageBoxWHook = RenHook::Hook::Create(L"user32", L"MessageBoxW", &MessageBoxWFunction);
MessageBoxW(nullptr, L"Hello", L"MessageBoxW", MB_OK);
return 0;
}