From 289ed6a8283f2a7e12c4643594dbf8e32e7b950b Mon Sep 17 00:00:00 2001 From: xerox Date: Fri, 20 Dec 2019 20:20:04 -0800 Subject: [PATCH] Upload New File --- Hook.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Hook.cpp 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