updated Memory

This commit is contained in:
Silent 2016-03-10 20:27:53 +01:00
parent c587821c63
commit 901a3c818b

View file

@ -13,8 +13,7 @@
enum enum
{ {
PATCH_CALL, PATCH_CALL,
PATCH_JUMP, PATCH_JUMP
PATCH_NOTHING,
}; };
inline signed char* GetVer() inline signed char* GetVer()
@ -401,7 +400,7 @@ namespace Memory
{ memset((void*)address, 0x90, nCount); } { memset((void*)address, 0x90, nCount); }
template<typename AT, typename HT> template<typename AT, typename HT>
inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) inline void InjectHook(AT address, HT hook)
{ {
DWORD dwHook; DWORD dwHook;
_asm _asm
@ -410,16 +409,21 @@ namespace Memory
mov dwHook, eax mov dwHook, eax
} }
switch ( nType ) *(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5;
{
case PATCH_JUMP:
*(BYTE*)address = 0xE9;
break;
case PATCH_CALL:
*(BYTE*)address = 0xE8;
break;
} }
template<typename AT, typename HT>
inline void InjectHook(AT address, HT hook, unsigned int nType)
{
DWORD dwHook;
_asm
{
mov eax, hook
mov dwHook, eax
}
*(BYTE*)address = nType == PATCH_JUMP ? 0xE9 : 0xE8;
*(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; *(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5;
} }
}; };
@ -445,23 +449,11 @@ namespace MemoryVP
} }
template<typename AT, typename HT> template<typename AT, typename HT>
inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) inline void InjectHook(AT address, HT hook)
{ {
DWORD dwProtect[2]; 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]); VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
break;
}
DWORD dwHook; DWORD dwHook;
_asm _asm
{ {
@ -470,9 +462,25 @@ namespace MemoryVP
} }
*(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; *(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5;
if ( nType == PATCH_NOTHING )
VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]);
else }
template<typename AT, typename HT>
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]); VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]);
} }
@ -491,7 +499,13 @@ namespace MemoryVP
} }
template<typename AT, typename HT> template<typename AT, typename HT>
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<typename AT, typename HT>
inline void InjectHook(AT address, HT hook, unsigned int nType)
{ {
MemoryVP::InjectHook(DynBaseAddress(address), hook, nType); MemoryVP::InjectHook(DynBaseAddress(address), hook, nType);
} }