Some more bugfixes

This commit is contained in:
momo5502 2016-03-14 21:29:21 +01:00
parent 15b26bf4e7
commit 42cfaccbad
5 changed files with 58 additions and 28 deletions

View File

@ -5,6 +5,7 @@ namespace Components
int AntiCheat::LastCheck;
std::string AntiCheat::Hash;
Utils::Hook AntiCheat::LoadLibHook[4];
Utils::Hook AntiCheat::VirtualProtectHook;
// This function does nothing, it only adds the two passed variables and returns the value
// The only important thing it does is to clean the first parameter, and then return
@ -98,8 +99,8 @@ namespace Components
AntiCheat::LoadLibHook[0].Initialize(LoadLibraryA, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].Initialize(LoadLibraryW, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[2].Initialize(LoadLibraryExA, loadLibExStub, HOOK_JUMP);
AntiCheat::LoadLibHook[3].Initialize(LoadLibraryExW, loadLibExStub, HOOK_JUMP);
//AntiCheat::LoadLibHook[2].Initialize(LoadLibraryExA, loadLibExStub, HOOK_JUMP);
//AntiCheat::LoadLibHook[3].Initialize(LoadLibraryExW, loadLibExStub, HOOK_JUMP);
}
void AntiCheat::PerformCheck()
@ -133,10 +134,10 @@ namespace Components
void AntiCheat::PatchWinAPI()
{
AntiCheat::LoadLibHook[0].Uninstall();
AntiCheat::LoadLibHook[1].Uninstall();
AntiCheat::LoadLibHook[2].Uninstall();
AntiCheat::LoadLibHook[3].Uninstall();
for (int i = 0; i < ARRAYSIZE(AntiCheat::LoadLibHook); ++i)
{
AntiCheat::LoadLibHook[i].Uninstall();
}
// Initialize directx :P
Utils::Hook::Call<void()>(0x5078C0)();
@ -147,8 +148,33 @@ namespace Components
//AntiCheat::LoadLibHook[3].Install();
}
BOOL WINAPI AntiCheat::VirtualProtectStub(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect)
{
AntiCheat::VirtualProtectHook.Uninstall(false);
if (flNewProtect == PAGE_WRITECOPY || flNewProtect == PAGE_READWRITE || flNewProtect == PAGE_EXECUTE_READWRITE || flNewProtect == PAGE_WRITECOMBINE)
{
DWORD addr = (DWORD)lpAddress;
DWORD start = 0x401000;
DWORD end = start + 0x2D6000;
if (addr > start && addr < end)
{
OutputDebugStringA(Utils::VA("Write access to address %X", lpAddress));
}
}
BOOL retVal = VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect);
AntiCheat::VirtualProtectHook.Install(false);
return retVal;
}
AntiCheat::AntiCheat()
{
// This is required for debugging...in release mode :P
//AntiCheat::VirtualProtectHook.Initialize(VirtualProtect, VirtualProtectStub, HOOK_JUMP);
//AntiCheat::VirtualProtectHook.Install(true, true);
AntiCheat::EmptyHash();
#ifdef DEBUG
@ -168,5 +194,11 @@ namespace Components
AntiCheat::~AntiCheat()
{
AntiCheat::EmptyHash();
AntiCheat::VirtualProtectHook.Uninstall(false);
for (int i = 0; i < ARRAYSIZE(AntiCheat::LoadLibHook); ++i)
{
AntiCheat::LoadLibHook[i].Uninstall();
}
}
}

View File

@ -22,6 +22,9 @@ namespace Components
static void NullSub();
static BOOL WINAPI VirtualProtectStub(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
static Utils::Hook LoadLibHook[4];
static Utils::Hook VirtualProtectHook;
};
}

View File

@ -95,24 +95,19 @@ namespace Components
int Menus::KeywordHash(char* key)
{
// patch this function on-the-fly, as it's some ugly C.
Utils::Hook::Set<DWORD>(0x63FE9E, 3523);
Utils::Hook::Set<DWORD>(0x63FECB, 0x7F);
AntiCheat::EmptyHash();
int hash = 0;
int var = 0x63FE90;
__asm
if (*key)
{
mov eax, key
call var
mov var, eax
int sub = 3523 - reinterpret_cast<DWORD>(key);
do
{
char _chr = *key;
hash += reinterpret_cast<DWORD>(&(key++)[sub]) * tolower(_chr);
} while (*key);
}
Utils::Hook::Set<DWORD>(0x63FE9E, 531);
Utils::Hook::Set<DWORD>(0x63FECB, 0x1FF);
AntiCheat::EmptyHash();
return var;
return (static_cast<uint16_t>(hash) + static_cast<uint16_t>(hash >> 8)) & 0x7F;
}
Game::menuDef_t* Menus::ParseMenu(int handle)

View File

@ -34,7 +34,7 @@ namespace Utils
return this;
}
Hook* Hook::Install()
Hook* Hook::Install(bool unprotect, bool keepUnportected)
{
Hook::StateMutex.lock();
@ -46,7 +46,7 @@ namespace Utils
Hook::Installed = true;
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
if (unprotect) VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
memcpy(Hook::Buffer, Hook::Place, sizeof(Hook::Buffer));
char* code = static_cast<char*>(Hook::Place);
@ -55,7 +55,7 @@ namespace Utils
*reinterpret_cast<size_t*>(code + 1) = reinterpret_cast<size_t>(Hook::Stub) - (reinterpret_cast<size_t>(Hook::Place) + 5);
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
if (unprotect && !keepUnportected) VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
FlushInstructionCache(GetCurrentProcess(), Hook::Place, sizeof(Hook::Buffer));
@ -72,7 +72,7 @@ namespace Utils
}
}
Hook* Hook::Uninstall()
Hook* Hook::Uninstall(bool unprotect)
{
Hook::StateMutex.lock();
@ -84,11 +84,11 @@ namespace Utils
Hook::Installed = false;
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
if(unprotect) VirtualProtect(Hook::Place, sizeof(Hook::Buffer), PAGE_EXECUTE_READWRITE, &this->Protection);
memcpy(Hook::Place, Hook::Buffer, sizeof(Hook::Buffer));
VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
if (unprotect) VirtualProtect(Hook::Place, sizeof(Hook::Buffer), Hook::Protection, &this->Protection);
FlushInstructionCache(GetCurrentProcess(), Hook::Place, sizeof(Hook::Buffer));

View File

@ -22,8 +22,8 @@ namespace Utils
Hook* Initialize(void* place, void* stub, bool useJump = true);
Hook* Initialize(DWORD place, void* stub, bool useJump = true);
Hook* Initialize(DWORD place, void(*stub)(), bool useJump = true); // For lambdas
Hook* Install();
Hook* Uninstall();
Hook* Install(bool unprotect = true, bool keepUnportected = false);
Hook* Uninstall(bool unprotect = true);
void* GetAddress();
void Quick();