//! # prehook
//!
//! A lightweight, flexible library for applying x64 hooks using `LD_PRELOAD`
//! and the `ilhook` engine.
//!
//! ## Features
//! - **4 Hook Types**: `Retn` (Function hooks), `JmpBack`, `JmpToRet`, and `JmpToAddr`.
//! - **Interposition**: Effortlessly override shared library functions with `#[interpose]`.
//! - **`call_original!`**: Easily call the original function from within a hook.
//! - **Reentrant Guard**: Optional `guard = true` to prevent infinite recursion when calling original.
//! - **Symbol-based Hooking**: Automatically resolves symbol addresses using `dlsym`.
//! - **Hook Management**: Registry-based tracking with support for individual or bulk cleanup.
//!
//! ## Basic Usage
//! ```rust
//! use prehook::hook;
//!
//! #[hook(kind = "retn", symbol = "some_function")]
//! fn my_hook(arg1: i32) -> i32 {
//!     println!("Hooked! arg1 = {}", arg1);
//!     let result = call_original!(arg1);
//!     result + 1
//! }
//! ```

pub mod error;
pub mod hook;
pub mod init;

pub use error::PrehookError;
pub use hook::{HOOK_REGISTRY, HookGuard, HookType, Registers, Target};

/// The primary macro for defining hooks.
///
/// ### Attributes
/// - `kind`: The type of hook (`"retn"`, `"jmp_back"`, `"jmp_to_ret"`, `"jmp_to_addr"`). Defaults to `"retn"`.
/// - `symbol`: The name of the symbol to hook (resolved via `dlsym`).
/// - `offset`: The address offset relative to the binary's base address.
/// - `dest`: (Required for `jmp_to_addr`) The destination offset to jump to.
/// - `guard`: (Optional) Set to `true` to prevent reentrant calls when the hook calls the original function.
///
/// ### Usage in `retn` hooks
/// The macro injects a local `call_original!(...)` macro into the function body,
/// allowing you to call the intercepted function with its original signature.
pub use prehook_macros::hook;

/// The macro for defining a symbol interposer.
///
/// This attribute macro transforms a standard Rust function into an
/// exported symbol (via `#[no_mangle]`) and automatically resolves
/// the original function from the next available library using `dlsym(RTLD_NEXT, ...)`.
pub use prehook_macros::interpose;

pub mod prelude {
    pub use crate::hook;
    pub use crate::hook::HookGuard;
    pub use crate::hook::HookType;
    pub use crate::hook::Registers;
    pub use crate::interpose;
    pub use crate::original;
}
