Git Product home page Git Product logo

minhook-rs's Introduction

minhook-rs

Build status

Documentation

A function hooking library for the Rust programming language. This library provides efficient and safe bindings to the MinHook library.

It currently supports the x86 and x86_64 architectures and the GCC (MinGW) and MSVC toolchains on Windows. Requires the Rust Nightly compiler. The supported target triples are:

  • i686-pc-windows-msvc
  • x86_64-pc-windows-msvc
  • i686-pc-windows-gnu
  • x86_64-pc-windows-gnu

Usage

First, add the following lines to your Cargo.toml:

[dependencies]
minhook = { git = "https://github.com/Jascha-N/minhook-rs" }

Next, add this to your crate root:

#[macro_use]
extern crate minhook;

Features

The minhook-rs library has the following feature:

  • increased_arity - If there is a need to hook functions with an arity greater than 12, this will allow functions of up to 26 arguments to be hooked.

Example

Example using a static hook.

Cargo.toml:

[dependencies]
minhook = { git = "https://github.com/Jascha-N/minhook-rs" }
winapi = "0.2"
user32-sys = "0.1"

src/main.rs:

#![feature(const_fn, recover)]

#[macro_use]
extern crate minhook;
extern crate winapi;
extern crate user32;

use std::ptr;

use winapi::{HWND, LPCSTR, UINT, c_int};

static_hooks! {
    // Create a hook for user32::MessageBoxA.
    impl MessageBoxA for user32::MessageBoxA: unsafe extern "system" fn(HWND, LPCSTR, LPCSTR, UINT) -> c_int;
}

fn main() {
    // Create a detour closure. This closure can capture any Sync variables.
    let detour = |wnd, text, caption, flags| unsafe { MessageBoxA.call_real(wnd, caption, text, flags) };

	// Install the hook.
    unsafe { MessageBoxA.initialize(detour).unwrap(); }

    let hello = b"Hello\0".as_ptr() as LPCSTR;
    let world = b"World\0".as_ptr() as LPCSTR;

    // Call the function.
    unsafe { user32::MessageBoxA(ptr::null_mut(), hello, world, winapi::MB_OK); }

    // Enable the hook.
    MessageBoxA.enable().unwrap();

    // Call the - now hooked - function.
    unsafe { user32::MessageBoxA(ptr::null_mut(), hello, world, winapi::MB_OK); }
}

minhook-rs's People

Contributors

jascha-n avatar pycckue-bnepeg avatar richinseattle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.