Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Library:MinHook

From ReverseEngineering.wiki
Library
Developer Tsuda Kageyu
Platforms Windows x86, x64
License BSD-2-Clause
Website https://github.com/TsudaKageyu/minhook
On this wiki Facts · Code · Notes · Topics

MinHook is a small BSD-2-Clause inline API hooking library for Windows x86 and x64 (C, about 2000 lines plus a bundled Hacker Disassembler Engine), used by many game mods and injected DLLs.

Overview

MinHook implements the inline hook described in Technique:Function hooking. The public API is in include/MinHook.h: MH_Initialize / MH_Uninitialize (call exactly once), MH_CreateHook(pTarget, pDetour, ppOriginal), MH_CreateHookApi(module, procName, ...), MH_CreateHookApiEx, MH_RemoveHook, MH_EnableHook / MH_DisableHook (MH_ALL_HOOKS = NULL for all), MH_QueueEnableHook / MH_QueueDisableHook / MH_ApplyQueued (apply many hooks with one thread suspension), MH_StatusToString. Hooks are created disabled.

Status codes

MH_UNKNOWN -1, MH_OK 0, then ALREADY_INITIALIZED, NOT_INITIALIZED, ALREADY_CREATED, NOT_CREATED, ENABLED, DISABLED, NOT_EXECUTABLE, UNSUPPORTED_FUNCTION, MEMORY_ALLOC, MEMORY_PROTECT, MODULE_NOT_FOUND, FUNCTION_NOT_FOUND (1..12).

Recognising it in a binary

  • The patch written to a hooked function is E9 rel32; when the function has a hot-patch area above it, an EB F9 short jump is placed on the first instruction and the E9 in the 5 bytes above (patchAbove).
  • Trampoline slots are 64 bytes (x64) or 32 bytes (x86), allocated in 4 KiB RWX blocks, and a free slot is filled with CC; so an injected module with many RWX pages full of CC bytes near the game image suggests MinHook.
  • Exported/known strings: the MH_* function names when built as a DLL; status names from MH_StatusToString.

Internals

See Fact:MinHook/struct/Hook patch layouts. The disassembler is the bundled HDE (src/hde/hde32.c, hde64.c) used to measure instruction lengths and fix relative operands in src/trampoline.c. src/buffer.c allocates executable slots within 0x40000000 bytes of the target. src/hook.c suspends all other threads (SuspendThread via a toolhelp snapshot) while patching.

Code & repositories

https://github.com/TsudaKageyu/minhook (read at commit 8af6b4acae5a9388fd742b56fa79ece89d96f823).

  • https://github.com/TsudaKageyu/minhook @ 8af6b4acae5a9388fd742b56fa79ece89d96f823 · license: BSD-2-Clause (declared by the contributor; GitHub's detector did not recognize LICENSE.txt)
    MinHook source repository (inline API hooking for Windows x86/x64)
    Tested on: source read, not run: source read only · checked 2026-10-18