Update hook.hpp

master
xerox 5 years ago
parent ac7148d269
commit b2a388dd58

@ -36,12 +36,24 @@
namespace hook namespace hook
{ {
static void write_to_readonly(void* addr, void* data, int size) inline void write_to_readonly(void* addr, void* data, int size)
{ {
DWORD old_flags; DWORD old_flags;
VirtualProtect((LPVOID)addr, size, PAGE_EXECUTE_READWRITE, &old_flags); if(!VirtualProtect(
memcpy((void*)addr, data, size); addr,
VirtualProtect((LPVOID)addr, size, old_flags, &old_flags); size,
PAGE_EXECUTE_READWRITE,
&old_flags
)) return;
memcpy(addr, data, size);
VirtualProtect(
addr,
size,
old_flags,
&old_flags
);
} }
class detour class detour
@ -119,15 +131,9 @@ namespace hook
std::uint8_t org_bytes[sizeof(jmp_code)]; std::uint8_t org_bytes[sizeof(jmp_code)];
}; };
static std::map<void*, std::unique_ptr<detour>> hooks{}; inline std::map<void*, std::unique_ptr<detour>> hooks{};
/* inline void make_hook(void* addr_to_hook, void* jmp_to_addr, bool enable = true)
Author: xerox
Date: 12/19/2019
Create Hook without needing to deal with objects
*/
static void make_hook(void* addr_to_hook, void* jmp_to_addr, bool enable = true)
{ {
if (!addr_to_hook) if (!addr_to_hook)
return; return;
@ -141,40 +147,21 @@ namespace hook
); );
} }
/* inline void enable(void* addr)
Author: xerox
Date: 12/19/2019
Enable hook given the address to hook
*/
static void enable(void* addr)
{ {
if (!addr) if (!addr)
return; return;
hooks.at(addr)->install(); hooks.at(addr)->install();
} }
/* inline void disable(void* addr)
Author: xerox
Date: 12/19/2019
Disable hook givent the address of the hook
*/
static void disable(void* addr)
{ {
if (!addr) if (!addr)
return; return;
hooks.at(addr)->uninstall(); hooks.at(addr)->uninstall();
} }
inline void remove(void* addr)
/*
Author: xerox
Date: 12/19/2019
Remove hook completely from vector
*/
static void remove(void* addr)
{ {
if (!addr) if (!addr)
return; return;

Loading…
Cancel
Save