# 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 `RadHookCreate` for 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 ```sh 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: ```powershell ./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 ```cpp #include 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(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` | 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](LICENSE) for details.