retour-utils

Crates.ioretour-utils
lib.rsretour-utils
version0.2.1
sourcesrc
created_at2023-02-16 11:10:08.787153
updated_at2023-07-05 04:34:16.063767
descriptionUtility crate for creating hooks with `retour`
homepagehttps://github.com/Hpmason/retour-utils
repositoryhttps://github.com/Hpmason/retour-utils
max_upload_size
id786666
size34,801
Mason Ginter (Hpmason)

documentation

https://docs.rs/retour-utils

README

retour-utils

This crate is meant to help creating detours with the retour crate. If you're creating lots of detours, it's very repetitive, so this crate adds some a few helper functions and macro to greatly simplify/streamline the process.

Example

use retour_utils::hook_module;

#[hook_module("lua52.dll")]
mod lua {
    // #[hook_module] will create this
    // const MODULE_NAME: &str = "lua52.dll"
    // and
    // pub unsafe init_detours() -> crate::Result<()> {..}
    // which will initialize all the StaticDetours generated by the macro inside this module

    #[allow(non_camel_case_types)]
    type lua_State = ();
    #[allow(non_camel_case_types)]
    type lua_Alloc = ();
    
    // Creates a StaticDetour called Lua_newstate with the same function type as our function 
    // (minus abi/unsafe to work with retour crate)
    #[hook(unsafe extern "C" Lua_newstate, symbol = "Lua_newstate")]
    pub fn newstate(f: *mut lua_Alloc, ud: *mut std::ffi::c_void) -> *mut lua_State {
        unsafe {
            Lua_newstate.call(f, ud)
        }
    }
    // More lua hooks
}


// #[hook_module] creates a `init_hooks` function that initializes and enables all the hooks
lua::init_hooks().unwrap()

This is very much in the early stages, with some noticable rough areas

  • Only supports windows atm
  • No docs yet
  • Naming of macros and fns likely to change for consistency/clarity
Commit count: 43

cargo fmt