#include "hook.hpp" namespace hook { //--- default constructor detour::detour(void* addr_to_hook, void* jmp_to_addr) : hook_addr((std::uintptr_t)addr_to_hook), detour_addr((std::uintptr_t)jmp_to_addr) { //finish the shellcode by adding the address to jmp to *(uintptr_t*)(jmp_code + OFFSET_TO_ADDRESS) = (std::uintptr_t)jmp_to_addr; //save old bytes memcpy(org_bytes, (void*)hook_addr, JMP_CODE_SIZE); //install the hook. install(); } detour::~detour() {uninstall();} void detour::install() { //install the hook. write_to_readonly((void *)hook_addr, jmp_code, JMP_CODE_SIZE); hook_installed = true; } void detour::uninstall() { //write the original bytes back. write_to_readonly((void *)hook_addr, org_bytes, JMP_CODE_SIZE); hook_installed = false; } uintptr_t detour::hook_address() {return hook_addr;} uintptr_t detour::detour_address() {return detour_addr;} bool detour::installed() {return hook_installed;} }