x86/x64 hooking library
#include<iostream>
#include"X96Hook.h"
#defineFUNC_FooBar0xCAFEBABE//address of a function of type void()/* The function looks like this * void FooBar() * { * std::cout << "FooBar called \n"; * }*/typedefvoid (*pfn_FooBar)();
voidFooBar_hk() //our hook function
{
std::cout << "hook called\n";
}
intmain()
{
X32Hook foo_hook;
foo_hook.SetupHook((void*)FUNC_FooBar, FooBar_hk); //setup our hook
foo_hook.InstallHook(); //install our hook function
pfn_FooBar FooBar_t = (pfn_FooBar)FUNC_FooBar; //create a function pointerFooBar_t(); //call the hooked function (FUNC_FooBar)
foo_hook.RemoveHook(); //remove the hook//possible output: hook calledreturn1;
}
#include<iostream>
#include"X96Hook.h"
#defineFUNC_FooBar0xCAFEBABE//address of a function of type void()/* The function looks like this * void FooBar() * { * std::cout << "FooBar called \n"; * }*/typedefvoid (*pfn_FooBar)();
pfn_FooBar FooBar_t = NULL;
X32Hook foo_hook;
voidFooBar_hk() //our hook function
{
std::cout << "hook called\n";
((pfn_FooBar)foo_hook.Trampoline())(); //call the original un-hooked function to perform its tasks/* way without trampoline: * foo_hook.RemoveHook(); * FooBar_t(); * foo_hook.InstallHook(); * using trampolines is way more optimized*/
}
intmain()
{
foo_hook.SetupHook((void*)FUNC_FooBar, FooBar_hk); //setup our hook
foo_hook.InstallHook(); //install our hook function
FooBar_t = (pfn_FooBar)FUNC_FooBar; //assign FUNC_FooBar to FooBar_tFooBar_t(); //call the hooked function (FUNC_FooBar)
foo_hook.RemoveHook(); //remove the hook//possible output://hook called//FooBar calledreturn1;
}