mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-22 09:19:28 +08:00
28 lines
641 B
C++
28 lines
641 B
C++
#include "dobby/dobby_internal.h"
|
|
|
|
#include <windows.h>
|
|
|
|
using namespace zz;
|
|
|
|
PUBLIC int DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) {
|
|
DWORD oldProtect;
|
|
int page_size;
|
|
|
|
// Get page size
|
|
SYSTEM_INFO si;
|
|
GetSystemInfo(&si);
|
|
page_size = si.dwPageSize;
|
|
|
|
void *addressPageAlign = (void *)ALIGN(address, page_size);
|
|
|
|
if (!VirtualProtect(addressPageAlign, page_size, PAGE_EXECUTE_READWRITE, &oldProtect))
|
|
return kMemoryOperationError;
|
|
|
|
memcpy(address, buffer, buffer_size);
|
|
|
|
if (!VirtualProtect(addressPageAlign, page_size, oldProtect, &oldProtect))
|
|
return kMemoryOperationError;
|
|
|
|
return 0;
|
|
}
|