An open-source x86-64 hooking library for Windows.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dependencies
source
tests
.clang-format
.gitignore
.gitmodules
CMakeLists.txt
LICENSE.md
README.md
appveyor.yml

README.md

RenHook

Build status

An open-source x64 hooking library for Windows.

Build instructions

Requirements

Windows

  1. Download and install Visual Studio 2017 Community Edition or a higher version.
  2. Clone this repository.
  3. Extract the content of PREMAKE 5 into Premake directory.
  4. Go to the Premake directory and run GenerateVisualStudioProjects.bat.
  5. Open the solution (RenHook.sln) located in Premake/Projects directory.
  6. Build the projects.

Examples

Basic usage

#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;
}

Trampolines

#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;
}