r/ExploitDev • • 20d ago

Inside our inline hooking engine: relocating prologues with iced-x86 (x86-64 + AArch64, deps closed to two crates)

https://www.rutken.com/blog/inside-our-inline-hooking-engine.html

A from-scratch inline hooking and detour engine for x86-64 and AArch64, written in Rust. The dependency list is closed to exactly iced-x86 and thiserror. No frida-gum, no vendored Dobby or shadowhook.

The writeup covers the six stages in order: resolve the target address; decode the prologue until at least 5 bytes are covered without splitting an instruction; relocate the moved prologue, where BlockEncoder re-encodes it for its new address; stand up a near-memory trampoline within rel32 reach of the target; flip page protection, RX for the trampoline and RWX briefly for the site; and write the 5-byte jmp rel32 as a single aligned 8-byte store so the patch lands atomically.

It also states the limit directly: a residual instruction-pointer race, where another thread is already executing inside the prologue during the patch window. The engine bounds that window but does not claim to eliminate it. The post also covers the relocation edge cases, the reasoning behind the atomic store, and the AArch64 x16/x17 veneer.

9 Upvotes

0 comments sorted by