Skip to content
/ RenHook Public

An open-source x86 / x86-64 hooking library for Windows.

License

Notifications You must be signed in to change notification settings

wopss/RenHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Apr 17, 2022
4f3a060 · Apr 17, 2022
Apr 17, 2022
Apr 17, 2022
Aug 21, 2021
Apr 17, 2022
Nov 5, 2019
Nov 5, 2019
Nov 5, 2019
Nov 5, 2019
Aug 21, 2021
Nov 5, 2019
Apr 17, 2022

Repository files navigation

RenHook

Build Status

An open-source x86 / x86-64 hooking library for Windows.

Features

  • Supports x86 and x86-64 (uses Zydis as diassembler)
  • Completely written in C++11
  • Safe and easy to use
  • Hooking methods
    • Inline hook - Patches the prologue of a function to redirect its code flow, also allocates a trampoline to that can be used to execute the original function.

Quick examples

Hooking by address

#include <Windows.h>
#include <renhook/renhook.hpp>

void func_detour();

using func_t = void(*)();
renhook::inline_hook<func_t> func_hook(0x14000000, &func_detour);

void func_detour()
{
    OutputDebugStringA("Hello from the hook!\n");
    func_hook();
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
    func_hook.attach();
    func_hook();
    func_hook.detach();

    func_hook();
    return 0;
}

Hooking by pattern

#include <Windows.h>
#include <renhook/renhook.hpp>

void func_detour();

using func_t = void(*)();
renhook::inline_hook<func_t> func_hook({ 0x89, 0x79, 0xF8, 0xE8, 0xCC, 0xCC, 0xCC, 0xCC, 0x8B, 0x0D, 0xCC, 0xCC, 0xCC, 0xCC }, &func_detour, 0xCC, 3);

void func_detour()
{
    OutputDebugStringA("Hello from the hook!\n");
    func_hook();
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
    func_hook.attach();
    func_hook();
    func_hook.detach();

    func_hook();
    return 0;
}

Hooking a function from a module

#include <Windows.h>
#include <renhook/renhook.hpp>

int WINAPI msgbox_detour(HWND wnd, LPCWSTR text, LPCWSTR caption, UINT type);

using MessageBoxW_t = int(WINAPI*)(HWND, LPCWSTR, LPCWSTR, UINT);
renhook::inline_hook<MessageBoxW_t> msgbox_hook("user32", "MessageBoxW", &msgbox_detour);

int WINAPI msgbox_detour(HWND wnd, LPCWSTR text, LPCWSTR caption, UINT type)
{
    return msgbox_hook(wnd, L"Hello from the hook!", L"RenHook", MB_OK | MB_ICONINFORMATION);
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
    msgbox_hook.attach();
    MessageBoxW(nullptr, L"Hello", L"Message", MB_OK);
    msgbox_hook.detach();

    MessageBoxW(nullptr, L"Hello", L"Message", MB_OK);
    return 0;
}

Build instructions

Requirements

Windows

  1. Download and install Visual Studio 2019 Community Edition or a higher version.
  2. Download and install the Requirements.
  3. Clone this repository.
  4. Clone the dependencies (git submodule update --init --recursive).
  5. Create a directory named build and run CMake in it.
  6. Open the solution (RenHook.sln) located in build directory.
  7. Build the projects.

About

An open-source x86 / x86-64 hooking library for Windows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published