|
|
|
@ -24,7 +24,7 @@ namespace hook
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
detour(void* addr_to_hook, void* jmp_to, bool enable = true)
|
|
|
|
|
: hook_addr(addr_to_hook), detour_addr(jmp_to)
|
|
|
|
|
: hook_addr(addr_to_hook), detour_addr(jmp_to), hook_installed(false)
|
|
|
|
|
{
|
|
|
|
|
//setup hook
|
|
|
|
|
memcpy(
|
|
|
|
@ -44,11 +44,15 @@ namespace hook
|
|
|
|
|
|
|
|
|
|
void install()
|
|
|
|
|
{
|
|
|
|
|
if (hook_installed.load())
|
|
|
|
|
return;
|
|
|
|
|
write_to_readonly(hook_addr, jmp_code, sizeof(jmp_code));
|
|
|
|
|
hook_installed.exchange(true);
|
|
|
|
|
}
|
|
|
|
|
void uninstall()
|
|
|
|
|
{
|
|
|
|
|
if (!hook_installed.load())
|
|
|
|
|
return;
|
|
|
|
|
write_to_readonly(hook_addr, org_bytes, sizeof(org_bytes));
|
|
|
|
|
hook_installed.exchange(false);
|
|
|
|
|
}
|
|
|
|
@ -58,7 +62,7 @@ namespace hook
|
|
|
|
|
void* hook_address() { return hook_addr; }
|
|
|
|
|
void* detour_address() { return detour_addr; }
|
|
|
|
|
private:
|
|
|
|
|
std::atomic<bool> hook_installed{ false };
|
|
|
|
|
std::atomic<bool> hook_installed;
|
|
|
|
|
void *hook_addr, *detour_addr;
|
|
|
|
|
|
|
|
|
|
#if _M_IX86
|
|
|
|
|