ib-hook
A Rust library for Windows binary and system hooking.
Features:
- Inline hooking:
Hook functions on x86/x64/ARM64,
no_stdandNtdll.dllonly. - DLL injection: Inject DLL into processes with optional RPC and auto self unload.
- Windows shell hook (
WH_SHELL): Monitor window operations: creating, activating, title redrawing, monitor changing... - GUI process watcher: Monitor GUI processes.
See documentation for details.
Inline hooking
- Supported CPU architectures: x86, x64, ARM64.
no_stdand depend onNtdll.dllonly.
// cargo add ib-hook --features inline
use InlineHook;
extern "system"
// Hook the function with a detour
extern "system"
let mut hook = new_enabled.unwrap;
// Now calls to original are redirected to hooked
assert_eq!; // redirected to hooked: 0x100 + 0o721 = 721
// Access original via trampoline
assert_eq!; // 0x100 + 1
// Disable the hook manually (or automatically on drop)
hook.disable.unwrap;
assert_eq!; // back to original
DLL injection
Inject DLL into processes with optional RPC and auto self unload.
- Optional RPC with
serdeinput and output. - RAII (drop guard) design with optional
leak(). - Single DLL injection / Multiple DLL injection manager.
- Optioanlly, in the DLL, unload self automatically if the injector process aborted.
use ;
;
// Inject into all processes named Notepad.exe
let mut injections = new;
injections.inject_with_process_name
.dll_path
.apply
.on_error
.call
.unwrap;
// Eject all manually or let drop handle it
injections.eject.on_error.call;
See src/bin/inject-app-dll.rs
and examples/app-dll.rs
for a complete example.
Windows shell hook (WH_SHELL)
Monitor window operations: creating, activating, title redrawing, monitor changing...
use ;
// Shell hook unregistered
See also ib-shell: Some desktop environment libraries, mainly for Windows Shell.
GUI process watcher
Monitor GUI processes.
use ;
let watcher = new.unwrap;
println!;
sleep;
Apply a function on every existing and new GUI process exactly once:
// cargo add ib-hook --features sysinfo
use GuiProcessWatcher;
let _watcher = for_each
.filter_image_path
.build;
sleep;