统一native_sdk

This commit is contained in:
Huoji's
2023-10-02 17:31:02 +08:00
parent 7d24c5a405
commit dc75327dec
46 changed files with 573 additions and 629 deletions

35
csgo2/vmthook.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "vmthook.h"
VMTHook::VMTHook(void* vmt_addy)
{
vmt = (void**)vmt_addy;
}
void* VMTHook::Hook(int index, void* hk)
{
// Store the index and original function address
hooked_funcs.insert(std::make_pair(index, vmt[index]));
// Change the memory's access rights, patch the address to our hook, restore original rights
DWORD old;
VirtualProtect(&vmt[index], sizeof(void*), PAGE_EXECUTE_READWRITE, &old);
vmt[index] = hk;
VirtualProtect(&vmt[index], sizeof(void*), old, NULL);
return hooked_funcs[index];
}
void VMTHook::ClearHooks()
{
for (func_iterator = hooked_funcs.begin(); func_iterator != hooked_funcs.end(); func_iterator++)
{
DWORD old;
VirtualProtect(&vmt[func_iterator->first], sizeof(void*), PAGE_EXECUTE_READWRITE, &old);
vmt[func_iterator->first] = func_iterator->second;
VirtualProtect(&vmt[func_iterator->first], sizeof(void*), old, NULL);
}
hooked_funcs.clear();
vmt = nullptr;
}
VMTHook::~VMTHook() {}