3
0
mirror of https://github.com/CrazyRedMachine/popnhax.git synced 2024-11-15 02:07:35 +01:00
popnhax/util/patch.cc
CrazyRedMachine 698e9c5476 Omnimix v2
2023-02-10 20:33:37 +01:00

28 lines
845 B
C++

// clang-format off
#include <windows.h>
#include <psapi.h>
// clang-format on
#include "patch.h"
void patch_memory(uint64_t patch_addr, char *data, size_t len) {
DWORD old_prot;
VirtualProtect((LPVOID)patch_addr, len, PAGE_EXECUTE_READWRITE, &old_prot);
memcpy((LPVOID)patch_addr, data, len);
VirtualProtect((LPVOID)patch_addr, len, old_prot, &old_prot);
}
char *getDllData(const char *dllFilename, DWORD *dllSize) {
HMODULE _moduleBase = GetModuleHandle(dllFilename);
MODULEINFO module_info;
memset(&module_info, 0, sizeof(module_info));
if (!GetModuleInformation(GetCurrentProcess(), _moduleBase, &module_info,
sizeof(module_info))) {
return NULL;
}
*dllSize = module_info.SizeOfImage;
return (char *)module_info.lpBaseOfDll;
}