From ca6b22a2b58a6571c9fb993e4a6ca32d4ec74603 Mon Sep 17 00:00:00 2001 From: nexusverypro Date: Fri, 3 Jul 2026 15:50:34 +0100 Subject: [PATCH] refact: redo README --- README.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65895f0..2724256 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,93 @@ # 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. -minimal hooking library for x64 and aarch64 \ No newline at end of file +## 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. \ No newline at end of file