A simple wrapper for the detour-rs library that makes making hooks much more concise

Overview

quick_detour

A simple wrapper for the detour-rs library that makes making hooks much more concise.

Example

isize { let module = LoadLibraryW(module_name); if let Err(x) = module.ok() { panic!("Failed to load {}! {}", module_name, x); } GetProcAddress(module, export) .unwrap_or_else(|| panic!("Failed to load export {} from {}!", export, module_name)) } pub unsafe fn install_hooks() -> Result<(), Box > { make_hook!( std::mem::transmute(get_api("user32.dll", "SetWindowTextA")), unsafe extern "system" fn(HWND, *const u8) -> BOOL, |hook, hwnd, text| -> BOOL { if !text.is_null() && let Ok(cstr) = CStr::from_ptr(text as _).to_str() { let new_str = cstr.to_string() + " (hooked!)"; let new_cstr = CString::new(new_str).unwrap(); hook.call(hwnd, new_cstr.as_ptr() as _) } else { hook.call(hwnd, text) } } ); Ok(()) }">
use std::ffi::{CStr, CString};

use quick_detour::make_hook;
use windows::Win32::{
    Foundation::{BOOL, HWND},
    System::LibraryLoader::{GetProcAddress, LoadLibraryW},
};

unsafe fn get_api(
    module_name: &'static str,
    export: &'static str,
) -> unsafe extern "system" fn() -> isize {
    let module = LoadLibraryW(module_name);
    if let Err(x) = module.ok() {
        panic!("Failed to load {}! {}", module_name, x);
    }
    GetProcAddress(module, export)
        .unwrap_or_else(|| panic!("Failed to load export {} from {}!", export, module_name))
}

pub unsafe fn install_hooks() -> Result<(), Box<dyn std::error::Error>> {
    make_hook!(
        std::mem::transmute(get_api("user32.dll", "SetWindowTextA")),
        unsafe extern "system" fn(HWND, *const u8) -> BOOL,
        |hook, hwnd, text| -> BOOL {
            if !text.is_null() && let Ok(cstr) = CStr::from_ptr(text as _).to_str() {
                let new_str = cstr.to_string() + " (hooked!)";
                let new_cstr = CString::new(new_str).unwrap();
                hook.call(hwnd, new_cstr.as_ptr() as _)
            } else {
                hook.call(hwnd, text)
            }
        }
    );

    Ok(())
}
You might also like...
Another attempt at creating a wrapper for fastcdc in node.js

Another attempt at creating a wrapper for fastcdc in node.js. This time using wasmbindgen instead of neon.

Convenience wrapper for cargo buildscript input/output

A convenience wrapper for cargo buildscript input/output. Why? The cargo buildscript API is (necessarily) stringly-typed.

Rust SDK wrapper for the Mystic Light SDK

mystic_light_sdk Rust SDK wrapper for the Mystic Light SDK Requirements Any MSI device with RGB support Only Windows 7+ Dragon Center or Msi Center in

A Rust wrapper of pmem/syscall_intercept.

syscall-intercept-rs A Rust wrapper of pmem/syscall_intercept, a system call intercepting library on x86_64 Linux. Usage Install dependencies: sudo ap

Thin wrapper around [`tokio::process`] to make it streamable

This library provide ProcessExt to create your own custom process

Rust wrapper for the Google Places API. Access their hundreds of millions of places, reviews, and ratings.

Google Places API Working Examples cargo run --example nearby_search cargo run --example place_details cargo run --example find_place cargo run --exam

Cargo wrapper for working with Webassembly wasi(x).

cargo-wasix A cargo subcommand that wraps regular cargo commands for compiling Rust code to wasix, a superset of Websassembly wasi with additional fun

A Wasm component optimizer (mostly a wrapper around wasm-opt)

component-opt An optimizer for Wasm Components Current Status This project currently only offers one optimization and does not allow it to be configur

A Diablo II library for core and simple client functionality, written in Rust for performance, safety and re-usability

A Diablo II library for core and simple client functionality, written in Rust for performance, safety and re-usability

Owner
Khangaroo
no commits head empty
Khangaroo
Massayo is a small proof-of-concept Rust library which removes AV/EDR hooks in a given system DLL

Massayo Massayo is a small proof-of-concept Rust library based on UnhookingPOC, which removes AV/EDR hooks in a given system DLL. I tried to reduce fi

null 53 Dec 21, 2022
A rust library that makes reading and writing memory of the Dolphin emulator easier.

dolphin-memory-rs A crate for reading from and writing to the emulated memory of Dolphin in rust. A lot of internals here are directly based on aldela

Madison Barry 4 Jul 19, 2022
My bot Roseline for AGTH hooks and VN related stuff

Roseline Web interface My IRC Bot to store AGTH hooks. Commands ping - Obviously send you back pong. vn <title> - Search VN by title. hook <title> - G

Douman 37 Nov 16, 2022
hado-rshado — A little macro for writing haskell-like do expressions without too much ceremony

hado Monadic haskell-like expressions brought to rust via the hado! macro What? A little macro for writing haskell-like do expressions without too muc

Lucas David Traverso 44 Jul 31, 2022
A memory-based evasion technique which makes shellcode invisible from process start to end.

phantom A memory-based evasion technique which makes shellcode invisible from process start to end. Motivation ShellGhost Offensive Edition, and rust!

B1-TEAM 5 Sep 15, 2023
A Rust utility library, making easier by taking the hassle out of working. :octocat:

reddish A Rust utility library, making easier by taking the hassle out of working. Usage Add this to your Cargo.toml: [dependencies] reddish = "0.2.0"

Rogério Araújo 12 Jan 21, 2023
🦸‍♂️ Recast migrates your old extensions to AndroidX, making them compatible with the latest version of Kodular.

Recast Recast helps make your old extensions compatible with Kodular Creator version 1.5.0 or above. Prerequisites To use Recast, you need to have Jav

Shreyash Saitwal 13 Dec 28, 2022
Rust crate for making Read streams peekable.

peekread This crate allows you to take an arbitrary Read stream and 'peek ahead' into the stream without consuming the original stream. This is done t

Orson Peters 21 Oct 29, 2022
Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient.

Bolt ⚡ Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient. Quick start ??‍??

0xHiro 6 Mar 26, 2023
An implementation of the SMP protocol as used in zephyr, mcuboot, mcumgr, and more.

SMP An implementation of the SMP protocol in pure Rust. This repository contains: ./mcumgr-smp: A SMP library implementation to be used in your own pr

Gessler GmbH 3 Dec 10, 2023