From 901a3c818ba0ac373c43d56818d9f816f61befb7 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 10 Mar 2016 20:27:53 +0100 Subject: [PATCH] updated Memory --- SilentPatch/MemoryMgr.h | 74 ++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index 4701eaf..3b7b7d1 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -13,8 +13,7 @@ enum { PATCH_CALL, - PATCH_JUMP, - PATCH_NOTHING, + PATCH_JUMP }; inline signed char* GetVer() @@ -401,7 +400,7 @@ namespace Memory { memset((void*)address, 0x90, nCount); } template - inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) + inline void InjectHook(AT address, HT hook) { DWORD dwHook; _asm @@ -410,16 +409,21 @@ namespace Memory mov dwHook, eax } - switch ( nType ) + *(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; + } + + template + inline void InjectHook(AT address, HT hook, unsigned int nType) + { + DWORD dwHook; + _asm { - case PATCH_JUMP: - *(BYTE*)address = 0xE9; - break; - case PATCH_CALL: - *(BYTE*)address = 0xE8; - break; + mov eax, hook + mov dwHook, eax } + *(BYTE*)address = nType == PATCH_JUMP ? 0xE9 : 0xE8; + *(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; } }; @@ -445,23 +449,11 @@ namespace MemoryVP } template - inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) + inline void InjectHook(AT address, HT hook) { DWORD dwProtect[2]; - switch ( nType ) - { - case PATCH_JUMP: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]); - *(BYTE*)address = 0xE9; - break; - case PATCH_CALL: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]); - *(BYTE*)address = 0xE8; - break; - default: - VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]); - break; - } + + VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]); DWORD dwHook; _asm { @@ -470,10 +462,26 @@ namespace MemoryVP } *(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; - if ( nType == PATCH_NOTHING ) - VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); - else - VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]); + VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); + } + + template + inline void InjectHook(AT address, HT hook, unsigned int nType) + { + DWORD dwProtect[2]; + + VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]); + *(BYTE*)address = nType == PATCH_JUMP ? 0xE9 : 0xE8; + + DWORD dwHook; + _asm + { + mov eax, hook + mov dwHook, eax + } + + *(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; + VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]); } namespace DynBase @@ -491,7 +499,13 @@ namespace MemoryVP } template - inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) + inline void InjectHook(AT address, HT hook) + { + MemoryVP::InjectHook(DynBaseAddress(address), hook); + } + + template + inline void InjectHook(AT address, HT hook, unsigned int nType) { MemoryVP::InjectHook(DynBaseAddress(address), hook, nType); }