All Projects → darfink → Detour Rs

darfink / Detour Rs

Licence: other
A cross-platform detour library written in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Detour Rs

Antdfront
using next generation data manager and hook、pure function component 、webpack to build antd design pro microfrontend project without umi, cra,dva or rematch
Stars: ✭ 105 (-28.08%)
Mutual labels:  hook
Easyprotector
一行代码检测XP/调试/多开/模拟器/root
Stars: ✭ 1,732 (+1086.3%)
Mutual labels:  hook
Webpack Internal Plugin Relation
🔎 a tiny tool to show the relation of webpack internal plugins & hooks
Stars: ✭ 135 (-7.53%)
Mutual labels:  hook
Hfunc
java implement Higher-order function ,support map,filter , reduce with parallel, android
Stars: ✭ 112 (-23.29%)
Mutual labels:  function
Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-19.86%)
Mutual labels:  hook
Git Code Format Maven Plugin
A maven plugin that automatically deploys https://github.com/google/google-java-format code formatter as a pre-commit git hook
Stars: ✭ 121 (-17.12%)
Mutual labels:  hook
Icmethoddigger
An easy way to print almost methods including private methods (supported arm64 architecture devices).
Stars: ✭ 103 (-29.45%)
Mutual labels:  hook
Elfhooker
兼容Android 32位和64位。基于EFL文件格式Hook的demo,hook了SurfaceFlinger进程的eglSwapBuffers函数,替换为new_eglSwapBuffers
Stars: ✭ 138 (-5.48%)
Mutual labels:  hook
React Timer Hook
React timer hook
Stars: ✭ 118 (-19.18%)
Mutual labels:  hook
Flutter hooks
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
Stars: ✭ 1,973 (+1251.37%)
Mutual labels:  hook
React Smooth Scroll Hook
A React Hook for using smooth scroll in React Component
Stars: ✭ 114 (-21.92%)
Mutual labels:  hook
Next Sanity
Sanity.io toolkit for Next.js
Stars: ✭ 115 (-21.23%)
Mutual labels:  hook
Misakahookfinder
御坂Hook提取工具—Galgame/文字游戏文本钩子提取
Stars: ✭ 125 (-14.38%)
Mutual labels:  hook
Playwright Aws Lambda
Support for running Microsoft's Playwright on AWS Lambda and Google Cloud Functions
Stars: ✭ 107 (-26.71%)
Mutual labels:  function
Git Multimail
Send notification emails for pushes to a git repository (an improved version of post-receive-mail)
Stars: ✭ 135 (-7.53%)
Mutual labels:  hook
Spek
🎏 Function builder BDD testing framework in Swift
Stars: ✭ 104 (-28.77%)
Mutual labels:  function
Utils.js
Useful JavaScript Functions Collection 一些很实用的JavaScript函数封装集合
Stars: ✭ 121 (-17.12%)
Mutual labels:  function
Cargo Husky
Setup Git hooks automatically for cargo projects with 🐶
Stars: ✭ 141 (-3.42%)
Mutual labels:  hook
Hookwormforandroid
一个基于Magisk&Riru的Module,可以助你用超低成本开发各种Hook插件,无须Xposed
Stars: ✭ 136 (-6.85%)
Mutual labels:  hook
Freereflection
A library that lets you use reflection without any restriction above Android P
Stars: ✭ 2,090 (+1331.51%)
Mutual labels:  hook

detour-rs

Azure build Status crates.io version Documentation Language (Rust)

This is a cross-platform detour library developed in Rust. Beyond the basic functionality, this library handles branch redirects, RIP-relative instructions, hot-patching, NOP-padded functions, and allows the original function to be called using a trampoline whilst hooked.

This is one of few cross-platform detour libraries that exists, and to maintain this feature, not all desired functionality can be supported due to lack of cross-platform APIs. Therefore EIP relocation is not supported.

NOTE: Nightly is currently required for static_detour! and is enabled by default.

Platforms

This library provides CI for these targets:

  • Linux
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
    • x86_64-unknown-linux-musl
  • Windows
    • i686-pc-windows-gnu
    • i686-pc-windows-msvc
    • x86_64-pc-windows-gnu
    • x86_64-pc-windows-msvc
  • macOS
    • i686-apple-darwin
    • x86_64-apple-darwin

Installation

Add this to your Cargo.toml:

[dependencies]
detour = "0.7.1"

Example

  • A static detour (one of three different detours):
use std::error::Error;
use detour::static_detour;

static_detour! {
  static Test: /* extern "X" */ fn(i32) -> i32;
}

fn add5(val: i32) -> i32 {
  val + 5
}

fn add10(val: i32) -> i32 {
  val + 10
}

fn main() -> Result<(), Box<dyn Error>> {
  // Reroute the 'add5' function to 'add10' (can also be a closure)
  unsafe { Test.initialize(add5, add10)? };

  assert_eq!(add5(1), 6);
  assert_eq!(Test.call(1), 6);

  // Hooks must be enabled to take effect
  unsafe { Test.enable()? };

  // The original function is detoured to 'add10'
  assert_eq!(add5(1), 11);

  // The original function can still be invoked using 'call'
  assert_eq!(Test.call(1), 6);

  // It is also possible to change the detour whilst hooked
  Test.set_detour(|val| val - 5);
  assert_eq!(add5(5), 0);

  unsafe { Test.disable()? };

  assert_eq!(add5(1), 6);
  Ok(())
}
  • A Windows API hooking example is available here; build it by running:
$ cargo build --example messageboxw_detour

Mentions

Part of the library's external user interface was inspired by minhook-rs, created by Jascha-N, and it contains derivative code of his work.

Appendix

  • EIP relocation

    Should be performed whenever a function's prolog instructions are being executed, simultaneously as the function itself is being detoured. This is done by halting all affected threads, copying the affected instructions and appending a JMP to return to the function. This is barely ever an issue, and never in single-threaded environments, but YMMV.

  • NOP-padding

    int function() { return 0; }
    // xor eax, eax
    // ret
    // nop
    // nop
    // ...
    

    Functions such as this one, lacking a hot-patching area, and too small to be hooked with a 5-byte jmp, are supported thanks to the detection of code padding (NOP/INT3 instructions). Therefore the required amount of trailing NOP instructions will be replaced, to make room for the detour.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].