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.
45 lines
958 B
45 lines
958 B
5 years ago
|
#include "Hook.hpp"
|
||
|
#include <iostream>
|
||
|
|
||
|
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;}
|
||
|
}
|