ZenWinHook is a high performance, thread safe Windows hooking library built for reliability and modern C++ workflows, it provides a unified API across multiple hooking techniques, allowing you to choose the right method for your use case without sacrificing safety or stability.
Designed for systems programming, debugging, instrumentation, and runtime modification.
Most hooking libraries focus on a single technique or leave edge cases undefined.
ZenWinHook is built to handle the tricky parts:
- Thread-safe by design: avoids race conditions during patching
- Instruction-aware inline hooks: works on complex functions
- Multiple hook types: no need to mix libraries
- RAII-based API: predictable lifetime and cleanup
| Feature | ZenWinHook | MinHook | PolyHook 2 |
|---|---|---|---|
| Thread-safe patching | ✅ | ❌ | |
| Instruction relocation | ✅ | ✅ | |
| Multiple hook types | ✅ | ❌ | |
| RAII API | ✅ | ❌ | ❌ |
| VEH / guard page hooks | ✅ | ❌ | ❌ |
Uses instruction pointer redirection and controlled thread suspension to prevent:
- instruction tearing
- partially applied patches
- crashes from concurrent execution
- instruction parsing + relocation
- supports relative branches and short functions
- avoids unsafe byte overwrites
- no code modification
- based on page protection + exceptions
- useful when patching isn't possible
- instance-level method overrides
- very low overhead
- useful for C++ interfaces
- INT3-based interception
- lightweight
- useful for tracing and debugging
scoped_hook automatically installs and removes hooks:
scoped_hook<inline_hook> hook(target, detour, &original);- no manual cleanup
- no dangling hooks
- safer in larger systems
#include "zenwinhook/hook_inline.h"
int main() {
using namespace zenwinhook;
void* original_fn = nullptr;
{
scoped_hook<inline_hook> hook(
&TargetFunction,
&DetourFunction,
&original_fn
);
if (hook.success()) {
TargetFunction(1337);
}
} // automatically restored here
}Approximate overhead (depends on CPU and usage):
| Hook Type | Overhead |
|---|---|
| Inline | ~ few ns |
| VTable | ~ minimal |
| VEH | ~100–200ns |
- runtime instrumentation
- debugging and tracing
- reverse engineering tools
- game modding
MIT — see LICENSE.
built by talkingtogod
