You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
934 B

#include "Hook.hpp"
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;}
}