The functions interception library written on pure C and NativeAPI with UserMode and KernelMode support
The functions interception library written on pure C and NativeAPI with UserMode and KernelMode support
TargetFunction(): ^ ; return
-> jmp Interceptor ------> Interceptor(): |
??? ; Broken bytes ... Handler code ... |
... ; Continuation OriginalBeginning():
... +---------|-> ... | ... Original beginning ...
ret --------+ | ret -----------------+ ... of TargetFunction ...
+------------------------------ jmp Continuation
Supported trampolines:
Jump to a relative offset:
E9 44 33 22 11 | jmp rip+0x11223344 ; Relative jump to ±2Gb only
Jump to an absolute address (x32):
FF 25 44 33 22 11 | jmp ds:[0x11223344]
NN NN NN NN | Reference** and select the HookLib.
Then add **./HookLib/HookLib/** folder to your header folders list and you're good to go.
```cpp
#include
int func(int a, int b)
{
return a + b;
}
int handler(int a, int b)
{
return a * b;
}
template
Fn hookFunc(Fn fn, Fn handler)
{
return static_cast(hook(fn, handler));
}
void testSimpleHook()
{
const auto orig = hookFunc(func, handler);
assert(func(2, 3) == 6); // Hooked, the 'handler' will be called instead
assert(orig(2, 3) == 5);
unhook(orig);
assert(func(2, 3) == 5);
}
void testCppHelpers()
{
const auto holder = HookFactory::install(func, handler);
assert(func(2, 3) == 6);
assert(holder.call(2, 3) == 5);
}
int main()
{
testSimpleHook();
testCppHelpers();
return 0;
}
No open issues yet, or sync has not completed.