Overview of PolyHook 2 hooking techniques
masterPolyHook 2 provides several distinct methods for intercepting execution, depending on your requirements:
- Inline Hook (x86/x64 Detour): Places a
jmpat the function prologue to a callback and uses a trampoline to continue execution. It handles complex relocation of position-dependent code and supports cross-architecture hooking (e.g., 32-bit process hooking 64-bit memory). - Runtime Inline Hook: Similar to Inline Hook, but JITs a translation stub compatible with a given
typedefand ABI. This allows hooking functions where thetypedefis only known at runtime. - Virtual Function Swap (VFuncSwap): Swaps pointers at specific indices in a C++ VTable to point to callbacks.
- Virtual Table Swap (VTableSwap): Performs a deep copy of a C++ VTable, replaces the pointer to the table with the new copy, and swaps entries in the copy.
- Software Breakpoint Hook (BreakpointHook): Overwrites the first byte of a function with
0xCCand uses an exception handler to trigger the callback. - Hardware Breakpoint Hook (HWBreakpointHook): Uses CPU debug registers. Warning: Hardware breakpoints are per-thread; the thread calling
hook()must be the same thread being hooked. - Import Address Table Hook (IatHook): Resolves modules via PEB and swaps the IAT thunk pointer to the callback.
- Export Address Table Hook (EatHook): Resolves modules via PEB and swaps the EAT pointer to the callback.