mirror of
https://git.recroomarchive.org/Radium/libradhook.git
synced 2026-08-07 09:10:59 +00:00
ca6b22a2b58a6571c9fb993e4a6ca32d4ec74603
libradhook
A minimal, cross-platform inline function hooking library for x86-64 and AArch64, targeting Windows and Android, built as a lightweight alternative to libraries like MinHook and Dobby with a flat, C-style, handle-based API.
Features
- Inline hooking on x86-64 and AArch64
- Windows and Android support
- Flat C API with opaque handles
- Typed convenience overload of
RadHookCreatefor function pointers - Trampolines to call the original function from within a detour
- Enable / disable / destroy individual hooks, or all hooks at once
- Hook enumeration and introspection (target, detour, trampoline, enabled state)
- Human-readable status strings
- Builds as a static or shared library via CMake
Requirements
- CMake 3.21+
- A C++20 compiler (msvc, gcc, or clang)
- Android NDK (only if targeting android)
Building
CMake
cmake -S . -B build
cmake --build build
Useful options:
| Option | Default | Description |
|---|---|---|
BUILD_SHARED_LIBS |
ON |
Build radhook as a shared library instead of static |
RADHOOK_BUILD_TESTS |
ON when top-level |
Build the test suite |
Build.ps1
A helper PowerShell script is provided for common build targets:
./Build.ps1 -Target msvc -Config Release # msvc, release, shared lib
./Build.ps1 -Target gcc -Config Release # mingw/gcc via ninja
./Build.ps1 -Target android -Config Release # android
./Build.ps1 -Target msvc -Static -RunTests # static build with tests
Usage
#include <radhook/radhook.h>
int TargetFunction() { return 42; }
int DetourFunction() { return 1337; }
int main() {
RadHookHandle handle = nullptr;
// create and install the hook
RadHookResult result = RadHookCreate(TargetFunction, (void*)DetourFunction, &handle);
if (result != RadHookResult::Success) {
// handle error
}
// call through the trampoline
using Fn = int(*)();
Fn original = RadHookGetOriginalAs<Fn>(handle);
original();
RadHookDisable(handle);
RadHookEnable(handle);
RadHookDestroy(handle);
return 0;
}
API overview
| Function Name | Description |
|---|---|
RadHookCreate |
Create and install a hook, enabled by default |
RadHookEnable |
Enable an installed hook |
RadHookDisable |
Disable an installed hook, restoring original bytes |
RadHookDestroy |
Disable, release, and invalidate a hook |
RadHookEnableAll / RadHookDisableAll |
Enable or disable every registered hook |
RadHookGetCount |
Number of currently registered hooks |
RadHookGetHandles / RadHookEnumerate |
Enumerate registered hook handles |
RadHookIsValid |
Check whether a handle refers to a registered hook |
RadHookIsEnabled |
Check whether a hook is currently enabled |
RadHookGetTarget |
Get the hooked target function pointer |
RadHookGetDetour |
Get the detour function pointer |
RadHookGetOriginal / RadHookGetOriginalAs<T> |
Get the trampoline to call the original implementation |
RadHookResultToString |
Human-readable name for a RadHookResult |
License
Licensed under the GNU Lesser General Public License v3 (LGPLv3). See LICENSE for details.
Languages
C++
88.4%
CMake
5.2%
PowerShell
3.8%
C
2.2%
SWIG
0.4%