#pragma once #define HOOK_JUMP true #define HOOK_CALL false namespace Utils { class Hook { public: Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); } Hook(void* place, void* stub, bool useJump = true) : Hook() { Hook::Initialize(place, stub, useJump); } Hook(DWORD place, void* stub, bool useJump = true) : Hook((void*)place, stub, useJump) {} ~Hook(); Hook* Initialize(void* place, void* stub, bool useJump = true); Hook* Initialize(DWORD place, void* stub, bool useJump = true); Hook* Install(); Hook* Uninstall(); void* GetAddress(); void Quick(); template static T Call(DWORD function) { __asm { mov eax, function call eax } } static void Nop(void* place, size_t length); static void Nop(DWORD place, size_t length); template static void Set(void* place, T value) { *(T*)place = value; FlushInstructionCache(GetCurrentProcess(), place, sizeof(T)); } template static void Set(DWORD place, T value) { return Set((void*)place, value); } template static void Xor(void* place, T value) { *(T*)place ^= value; FlushInstructionCache(GetCurrentProcess(), place, sizeof(T)); } template static void Xor(DWORD place, T value) { return Xor((void*)place, value); } template static void Or(void* place, T value) { *(T*)place |= value; FlushInstructionCache(GetCurrentProcess(), place, sizeof(T)); } template static void Or(DWORD place, T value) { return Or((void*)place, value); } template static void And(void* place, T value) { *(T*)place &= value; FlushInstructionCache(GetCurrentProcess(), place, sizeof(T)); } template static void And(DWORD place, T value) { return And((void*)place, value); } template static T Get(void* place) { return *(T*)place; } template static T Get(DWORD place) { return Get((void*)place); } private: bool Initialized; bool Installed; void* Place; void* Stub; void* Original; char Buffer[5]; bool UseJump; std::mutex StateMutex; }; }