GelHook is a single-header, advanced user-mode hook library written in pure C for x86-64 on Windows and Linux. It is designed to be portable, minimal in dependencies, and competitive with established user-mode detour libraries while keeping the codebase approachable and auditable.
- Single-header (
gelhook.h) implementation - x86-64 inline detours with safe prologue relocation
- Relative and absolute jump patches with near-trampoline allocation
- Optional code-cave detours (5-byte patch to a nearby cave)
- Hotpatch-friendly detours (2-byte prologue + 5-byte prelude)
- Rehook support (repair overwritten detours)
- Windows IAT/EAT hooks + delay-load IAT + Linux PLT/GOT hooks
- Module-scoped IAT/EAT utilities and export forwarder resolution
- Export enumeration helpers (Windows)
- TLS callback hook helper (Windows)
- Module enumeration (Windows PEB) and code-cave scanners
- Thread-local reentrancy guards
- VTable/VFunc pointer swaps + deep-copy VTable swap
- Mid-function/site hooks (patch arbitrary address)
- User-mode software breakpoint hooks
- User-mode hardware breakpoint hooks (Windows, per-thread)
- Guard-page hooks (Windows)
- Hook manager API (batch enable/disable)
- Optional external disassembler backend via a small decoder interface (templates for Capstone/Zydis)
This repo contains a full user-mode feature set focused on Windows + Linux x86-64. It does not implement kernel-mode or stealth/anti-anti-cheat behavior.
cmake -S . -B build -DGELHOOK_BUILD_EXAMPLES=ON
cmake --build build --config Releaseexamples/basic.cinline detourexamples/breakpoint.csoftware breakpoint hookexamples/iat.cIAT hook (Windows)examples/eat.cEAT hook (Windows)examples/hw_breakpoint.chardware breakpoint hook (Windows)examples/guard_page.cguard-page hook (Windows)examples/hotpatch.chotpatch detour (Windows)examples/plt.cPLT/GOT hook (Linux)examples/vtable.cppvtable swap (C++)examples/vtable_swap.cppdeep-copy vtable swap (C++)examples/site_hook.csite (mid-function) hookexamples/manager.cmanager atomic enableexamples/reentry.creentrancy guardexamples/rehook.crehook stress testexamples/python/Python ctypes demo
extras/decoder_capstone.cadapter template (requires Capstone)extras/decoder_zydis.cadapter template (requires Zydis)
#define GELHOOK_IMPLEMENTATION
#include "gelhook.h"
// See examples/basic.c// Inline hook
gh_hook hook;
if (gh_init_hook(&hook, (void*)target, (void*)replacement) == GH_OK) {
gh_enable_hook(&hook);
}
// Manager
gh_hook_manager mgr;
gh_manager_init(&mgr, 8);
gh_manager_add(&mgr, &hook);
gh_manager_enable_all(&mgr);- x86-64 only
- User-mode only
- Inlined decoder is intentionally conservative; you can plug in Capstone/Zydis by providing a decoder callback
- Thread-safety during patching depends on suspend strategy
MIT