walter

Crates.iowalter
lib.rswalter
version0.1.13
sourcesrc
created_at2021-07-23 23:22:47.760728
updated_at2021-07-29 15:54:51.676434
descriptionA simple Rust library for 32 and 64 bit hooking.
homepage
repositoryhttps://github.com/Justfr33z/walter
max_upload_size
id426524
size16,915
JustFr33z (Justfr33z)

documentation

https://docs.rs/walter

README

walter

Crate API

Walter is a simple hooking library.

Walter supports both 32 and 64 bit.

View the examples on how to hook.

Example hook

wgl_swap_buffers

mod bindings {
    windows::include_bindings!();
}

use std::ffi::c_void;
use walter::{
    TrampolineHook64,
};
use bindings::Windows::Win32::{
    System::{
        SystemServices::DLL_PROCESS_ATTACH,
        LibraryLoader::{
            GetProcAddress,
            GetModuleHandleA,
        },
    },
    Foundation::{
        BOOL,
        HANDLE,
        HINSTANCE,
    },
};
use once_cell::sync::Lazy;
use std::sync::Mutex;

static HOOK: Lazy<Mutex<Option<TrampolineHook64>>> = Lazy::new(|| {
    Mutex::new(None)
});

pub extern "stdcall" fn wgl_swap_buffers(hdc: HANDLE) -> BOOL {
    let gateway = HOOK
        .lock()
        .unwrap()
        .as_ref()
        .unwrap()
        .gateway();

    let gateway_call: extern "stdcall" fn (hdc: HANDLE) -> BOOL;
    gateway_call = unsafe { std::mem::transmute(gateway) };
    gateway_call(hdc);

    BOOL::from(true)
}

#[no_mangle]
pub extern "stdcall" fn DllMain(_module: HINSTANCE, reason: u32, _reserved: *mut c_void) -> BOOL {
    match reason {
        DLL_PROCESS_ATTACH => {
            let module = unsafe { GetModuleHandleA("opengl32.dll") };
            let src_wgl_swap_buffers = unsafe {
                GetProcAddress(module, "wglSwapBuffers")
            }.unwrap();

            let hook = TrampolineHook64::hook(
                src_wgl_swap_buffers as *mut c_void,
                wgl_swap_buffers as *mut c_void,
                20
            ).unwrap();

            *HOOK.lock().unwrap() = Some(hook);
        }
        _ => {}
    }

    BOOL::from(true)
}
Commit count: 0

cargo fmt