diff --git a/Hook.cpp b/Hook.cpp new file mode 100644 index 0000000..aa71fc8 --- /dev/null +++ b/Hook.cpp @@ -0,0 +1,45 @@ +#include "Hook.hpp" +#include + +namespace Hook +{ + //--- default constructor + Detour::Detour(uintptr_t addrToHook, uintptr_t jmpTo) + : HookAddress(addrToHook), DetourAddress(jmpTo) + { + //finish the shellcode by adding the address to jmp to + *(uintptr_t*)(jmpCode + OFFSET_TO_ADDRESS) = jmpTo; + + //save old bytes + memcpy(originalBytes, (void*)HookAddress, JMP_CODE_SIZE); + + //install the hook. + InstallHook(); + } + + Detour::~Detour() + {UninstallHook();} + + void Detour::InstallHook() + { + //install the hook. + WriteToReadOnly(HookAddress, (void *)jmpCode, JMP_CODE_SIZE); + isHookInstalled = true; + } + + void Detour::UninstallHook() + { + //write the original bytes back. + WriteToReadOnly(HookAddress, originalBytes, JMP_CODE_SIZE); + isHookInstalled = false; + } + + uintptr_t Detour::GetHookAddress() + {return HookAddress;} + + uintptr_t Detour::GetDetourAddress() + {return DetourAddress;} + + bool Detour::IsInstalled() + {return isHookInstalled;} +} \ No newline at end of file