{"id":13611744,"url":"https://github.com/darfink/detour-rs","last_synced_at":"2025-05-16T01:05:51.246Z","repository":{"id":41435467,"uuid":"75536680","full_name":"darfink/detour-rs","owner":"darfink","description":"A cross-platform detour library written in Rust","archived":false,"fork":false,"pushed_at":"2023-05-23T18:52:09.000Z","size":4376,"stargazers_count":433,"open_issues_count":14,"forks_count":77,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-08T11:16:01.947Z","etag":null,"topics":["detour","function","hook"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darfink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-04T12:42:31.000Z","updated_at":"2025-04-08T07:39:30.000Z","dependencies_parsed_at":"2024-01-14T06:50:40.809Z","dependency_job_id":"94c49d8f-7ddf-44e3-b903-1c18621165e3","html_url":"https://github.com/darfink/detour-rs","commit_stats":{"total_commits":113,"total_committers":9,"mean_commits":"12.555555555555555","dds":0.08849557522123896,"last_synced_commit":"3b6f17a8b51ba5b37addc8c4361e5cfbe2875243"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darfink%2Fdetour-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darfink%2Fdetour-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darfink%2Fdetour-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darfink%2Fdetour-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darfink","download_url":"https://codeload.github.com/darfink/detour-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["detour","function","hook"],"created_at":"2024-08-01T19:02:03.895Z","updated_at":"2025-05-16T01:05:46.224Z","avatar_url":"https://github.com/darfink.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# `detour-rs`\n\n[![Azure build Status][azure-shield]][azure]\n[![crates.io version][crate-shield]][crate]\n[![Documentation][docs-shield]][docs]\n[![Language (Rust)][rust-shield]][rust]\n\n\u003c/div\u003e\n\nThis is a cross-platform detour library developed in Rust. Beyond the basic\nfunctionality, this library handles branch redirects, RIP-relative\ninstructions, hot-patching, NOP-padded functions, and allows the original\nfunction to be called using a trampoline whilst hooked.\n\nThis is one of few **cross-platform** detour libraries that exists, and to\nmaintain this feature, not all desired functionality can be supported due to\nlack of cross-platform APIs. Therefore [EIP relocation](#appendix) is not\nsupported.\n\n**NOTE**: Nightly is currently required for `static_detour!` and is enabled by\ndefault.\n\n## Platforms\n\nThis library provides CI for these targets:\n\n- Linux\n  * `i686-unknown-linux-gnu`\n  * `x86_64-unknown-linux-gnu`\n  * `x86_64-unknown-linux-musl`\n- Windows\n  * `i686-pc-windows-gnu`\n  * `i686-pc-windows-msvc`\n  * `x86_64-pc-windows-gnu`\n  * `x86_64-pc-windows-msvc`\n- macOS\n  * ~~`i686-apple-darwin`~~\n  * `x86_64-apple-darwin`\n\n## Installation\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\ndetour = \"0.8.0\"\n```\n\n## Example\n\n- A static detour (one of *three* different detours):\n\n```rust\nuse std::error::Error;\nuse detour::static_detour;\n\nstatic_detour! {\n  static Test: /* extern \"X\" */ fn(i32) -\u003e i32;\n}\n\nfn add5(val: i32) -\u003e i32 {\n  val + 5\n}\n\nfn add10(val: i32) -\u003e i32 {\n  val + 10\n}\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n  // Reroute the 'add5' function to 'add10' (can also be a closure)\n  unsafe { Test.initialize(add5, add10)? };\n\n  assert_eq!(add5(1), 6);\n  assert_eq!(Test.call(1), 6);\n\n  // Hooks must be enabled to take effect\n  unsafe { Test.enable()? };\n\n  // The original function is detoured to 'add10'\n  assert_eq!(add5(1), 11);\n\n  // The original function can still be invoked using 'call'\n  assert_eq!(Test.call(1), 6);\n\n  // It is also possible to change the detour whilst hooked\n  Test.set_detour(|val| val - 5);\n  assert_eq!(add5(5), 0);\n\n  unsafe { Test.disable()? };\n\n  assert_eq!(add5(1), 6);\n  Ok(())\n}\n```\n\n- A Windows API hooking example is available [here](./examples/messageboxw_detour.rs); build it by running:\n```\n$ cargo build --example messageboxw_detour\n```\n\n## Mentions\n\nPart of the library's external user interface was inspired by\n[minhook-rs][minhook], created by [Jascha-N][minhook], and it contains\nderivative code of his work.\n\n## Appendix\n\n- *EIP relocation*\n\n  *Should be performed whenever a function's prolog instructions\n  are being executed, simultaneously as the function itself is being\n  detoured. This is done by halting all affected threads, copying the affected\n  instructions and appending a `JMP` to return to the function. This is\n  barely ever an issue, and never in single-threaded environments, but YMMV.*\n\n- *NOP-padding*\n  ```c\n  int function() { return 0; }\n  // xor eax, eax\n  // ret\n  // nop\n  // nop\n  // ...\n  ```\n  *Functions such as this one, lacking a hot-patching area, and too small to\n  be hooked with a 5-byte `jmp`, are supported thanks to the detection of\n  code padding (`NOP/INT3` instructions). Therefore the required amount of\n  trailing `NOP` instructions will be replaced, to make room for the detour.*\n\n\u003c!-- Links --\u003e\n[azure-shield]: https://img.shields.io/azure-devops/build/darfink/detour-rs/2/master?label=Azure%20Pipelines\u0026logo=azure-pipelines\u0026style=flat-square\n[azure]: https://dev.azure.com/darfink/detour-rs/_build/latest?definitionId=1\u0026branchName=master\n[crate-shield]: https://img.shields.io/crates/v/detour.svg?style=flat-square\n[crate]: https://crates.io/crates/detour\n[rust-shield]: https://img.shields.io/badge/powered%20by-rust-blue.svg?style=flat-square\n[rust]: https://www.rust-lang.org\n[docs-shield]: https://img.shields.io/badge/docs-crates-green.svg?style=flat-square\n[docs]: https://docs.rs/detour/\n[minhook-author]: https://github.com/Jascha-N\n[minhook]: https://github.com/Jascha-N/minhook-rs/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarfink%2Fdetour-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarfink%2Fdetour-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarfink%2Fdetour-rs/lists"}