From 5f55c75a4beaded62179fd0947654bd66b866b5c Mon Sep 17 00:00:00 2001 From: Daniel Seiller Date: Thu, 28 Nov 2019 19:59:36 +0100 Subject: [PATCH] update ScrapHacks: remove unused VMT_Hook --- ScrapHacks/ScrapHack/VMT_Hook.h | 101 -------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 ScrapHacks/ScrapHack/VMT_Hook.h diff --git a/ScrapHacks/ScrapHack/VMT_Hook.h b/ScrapHacks/ScrapHack/VMT_Hook.h deleted file mode 100644 index 4dd898e..0000000 --- a/ScrapHacks/ScrapHack/VMT_Hook.h +++ /dev/null @@ -1,101 +0,0 @@ - -#pragma once -class VMT_Hook -{ -private: - MEMORY_BASIC_INFORMATION mbi; - void *orig; - void *detour; - DWORD *vtable; - size_t ord; - bool enabled; - static map> hooks; - static DWORD *GetVTable(void *addr) - { - return (DWORD *)*(DWORD *)addr; - }; - -public: - VMT_Hook(void *obj, size_t ord, void *detour) - { - this->vtable = GetVTable(obj); - this->detour = detour; - this->orig = reinterpret_cast(vtable[ord]); - this->ord = ord; - this->enabled = false; - - VirtualQuery(&this->vtable[this->ord], &mbi, sizeof(mbi)); - cout << "Hooking: " << this->vtable << "[" << this->ord << "]: (" << this->orig << " -> " << this->detour << ")" << endl; - } - - ~VMT_Hook() - { - cout << "Unhooking: " << this->vtable << "[" << this->ord << "]: (" << this->orig << " -> " << this->detour << ")" << endl; - this->disable(); - } - - static void create(void *obj, size_t ord, void *detour) - { - uintptr_t key = reinterpret_cast(detour); - hooks[key] = make_shared(obj, ord, detour); - hooks[key]->enable(); - } - - static shared_ptr get(void *func) - { - uintptr_t addr = reinterpret_cast(func); - return VMT_Hook::get(addr); - } - - static shared_ptr get(uintptr_t addr) - { - return hooks.at(addr); - } - - static size_t drop(void *func) - { - uintptr_t addr = reinterpret_cast(func); - return VMT_Hook::drop(addr); - } - - static size_t drop(uintptr_t addr) - { - return hooks.erase(addr); - } - - static void clear() - { - return hooks.clear(); - } - - void disable() - { - if (enabled) - { - cout << "Disabling: " << this->vtable << "[" << this->ord << "]: (" << this->orig << " -> " << this->detour << ")" << endl; - VirtualProtect(mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, NULL); - this->vtable[ord] = reinterpret_cast(this->orig); - VirtualProtect(mbi.BaseAddress, mbi.RegionSize, mbi.Protect, NULL); - enabled = false; - } - } - void enable() - { - if (!enabled) - { - cout << "Enabling: " << this->vtable << "[" << this->ord << "]: (" << this->orig << " -> " << this->detour << ")" << endl; - VirtualProtect(mbi.BaseAddress, mbi.RegionSize, PAGE_EXECUTE_READWRITE, NULL); - this->vtable[ord] = reinterpret_cast(this->detour); - VirtualProtect(mbi.BaseAddress, mbi.RegionSize, mbi.Protect, NULL); - enabled = true; - } - } - - template - T func() - { - return reinterpret_cast(this->orig); - } -}; - -map> VMT_Hook::hooks;