{"id":33919649,"url":"https://github.com/dasaav-dsv/winhook","last_synced_at":"2026-01-13T14:00:52.052Z","repository":{"id":328292168,"uuid":"1065914991","full_name":"Dasaav-dsv/WinHook","owner":"Dasaav-dsv","description":"A next generation function hooking library for x86_64 Windows and Wine.","archived":false,"fork":false,"pushed_at":"2025-11-15T10:46:36.000Z","size":267,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-13T15:23:24.317Z","etag":null,"topics":["function-hooking","hooking","threadsafe","windows"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/winhook","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dasaav-dsv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-28T17:24:38.000Z","updated_at":"2025-11-15T18:06:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Dasaav-dsv/WinHook","commit_stats":null,"previous_names":["dasaav-dsv/winhook"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Dasaav-dsv/WinHook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dasaav-dsv%2FWinHook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dasaav-dsv%2FWinHook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dasaav-dsv%2FWinHook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dasaav-dsv%2FWinHook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dasaav-dsv","download_url":"https://codeload.github.com/Dasaav-dsv/WinHook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dasaav-dsv%2FWinHook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28387596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T13:42:20.960Z","status":"ssl_error","status_checked_at":"2026-01-13T13:42:03.276Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["function-hooking","hooking","threadsafe","windows"],"created_at":"2025-12-12T08:58:48.084Z","updated_at":"2026-01-13T14:00:52.044Z","avatar_url":"https://github.com/Dasaav-dsv.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WinHook\n\nA next generation function hooking library for x86_64 Windows and Wine.\n\n### Pros\n- First of its kind, fully atomic and threadsafe hook installation without IP relocation\n- Constant time hooking without ever \"stopping the world\" (suspending all threads in a process)\n- Support for stateful closures as hooks via [closure-ffi](https://crates.io/crates/closure-ffi)\n- No instruction boundary splitting (which can otherwise cause crashes when a branch target is clobbered with a jump instruction)\n\n### Cons\n- Windows and Wine on x86_64 only (for now)\n- Function addresses not aligned to 16 bytes are more likely to fail to be hooked, see `InstallerResultExt::retry_unchecked`\n- Hooked functions *must be a part of a module* like an executable or a DLL\n- Limited to the [Microsoft x64 calling convention ABI](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention)\n\n## Examples\n\nWinHook can be used with `\"C\"`, `\"system\"` and `\"win64\"` ABI functions when targeting `x86_64-pc-windows`. The `\"Rust\"` calling convention is inherently unstable and unsupported.\n\nAside from `Fn` closures with internal state, WinHook provides a method for installing `FnMut` hooks, i.e. using closures with mutable internal state. Under the hood, they are wrapped in a `Mutex` (note that recursive calls are not allowed, as they would mutably borrow the state a second time). `FnOnce` hooks are likewise supported.\n\nLet's take a simple \"add two numbers\" function and instrument it to notify a callback whenever a new highest sum is returned.\n\n```rust\n#[inline(never)]\nextern \"C\" fn add(a: i32, b: i32) -\u003e i32 {\n    a + b\n}\n\nlet new_highest = |num: i32| println!(\"new highest sum: {}\", num);\n\nuse winhook::HookInstaller;\n\n// Note how we added \"unsafe\" to the function signature.\n// Intercepting a function call must preserve all invariants of the original\n// and it is not possible to broadly claim for it to be memory safe.\nlet hook_handle = HookInstaller::\u003cunsafe extern \"C\" fn(_, _) -\u003e _\u003e::for_function(add)\n    .install_mut({\n        let mut max = i32::MIN;\n        move |original| move |a, b| {\n            // SAFETY: it's definitely safe to call the original function once\n            // with the original arguments.\n            let sum = unsafe { original(a, b) };\n            \n            if sum \u003e max {\n                // Notify our callback and update the maximum value.\n                new_highest(sum);\n                max = sum;\n            }\n\n            // Return the original result.\n            sum\n        }\n    })\n    .unwrap();\n\n// NOTE: always assign the returned `HookHandle` to a variable.\n// The hook will be uninstalled when the handle goes out of scope.\n\n// Installing a hook *is* safe, enabling it *is NOT*.\n// You guarantee all invariants of the original function are preserved.\nunsafe {\n    hook_handle.enable(true);\n}\n\n// Should print 4, 8, 15, 16, 23, 42.\nlet sequence = [\n    add(3, 1),\n    add(1, 2),\n    add(6, 2),\n    add(6, 9),\n    add(10, 2),\n    add(14, 2),\n    add(3, 20),\n    add(34, 8),\n];\n\n// The original output should not be affected.\nassert_eq!(sequence, [4, 3, 8, 15, 12, 16, 23, 42]);\n```\n\nBroadly speaking, the return value of the outer closure passed to `HookInstaller::install_*` methods is the function to be invoked in place of the hooked one. If you plan to completely detour the original function, it does not have to be a closure:\n\n```rust\n#[inline(never)]\n#[allow(improper_ctypes_definitions)]\nextern \"system\" fn hello(name: String) {\n    println!(\"Hello, {name}\");\n}\n\n// The hook is using the \"Rust\" calling convention as it must coerce to a `Fn`.\nfn goodbye(name: String) {\n    println!(\"Goodbye, {name}\");\n}\n\nuse winhook::HookInstaller;\n\n// `enable` can be used when installing the hook directly,\n// which is more efficient (and still *unsafe*, see above example).\nlet _hook_handle = unsafe {\n    HookInstaller::\u003cunsafe extern \"system\" fn(String)\u003e::for_function(hello)\n        .enable(true)\n        .install(|_original| goodbye)\n        .unwrap()\n};\n\n// Should print \"Goodbye, Mario\".\nhello(\"Mario\".to_owned());\n```\n\nIn cases where you do not wish to store a hook handle directly, you can leak it with `std::mem::forget` or use the associated `HookHandle::into_raw` method. Do not store a handle past its module's lifetime (after the module is unloaded).\n\n## Note about `iced-x86`\n\nThis crate currently depends on [`closure-ffi-iced-x86`](https://crates.io/crates/closure-ffi-iced-x86) due to an [upstream dependency on it](https://github.com/icedland/iced/issues/762) to prevent duplicating the `iced-x86` dependency in its own dependency tree.\n\n## License\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasaav-dsv%2Fwinhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdasaav-dsv%2Fwinhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasaav-dsv%2Fwinhook/lists"}