added if's in uninstall/install

master
xerox 5 years ago
parent b74dc0561d
commit 72d3e99140

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

Loading…
Cancel
Save