parent
fe559131a9
commit
ef0a787903
@ -1,42 +0,0 @@
|
||||
#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;}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#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;}
|
||||
}
|
Loading…
Reference in new issue