Refactored protected memory writes
This commit is contained in:
parent
f8c4c5ad82
commit
2da21065a6
@ -12,3 +12,5 @@ void utils_create_parent_dirs(const wchar_t *path);
|
|||||||
void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length);
|
void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length);
|
||||||
|
|
||||||
char utils_env_enabled(const char *env);
|
char utils_env_enabled(const char *env);
|
||||||
|
|
||||||
|
void utils_write_protected_memory(void *addr, void *buf, size_t size);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <ntdll.h>
|
#include <ntdll.h>
|
||||||
#include <pe.h>
|
#include <pe.h>
|
||||||
#include <msg.h>
|
#include <msg.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
#include <ace.h>
|
#include <ace.h>
|
||||||
|
|
||||||
@ -23,14 +24,7 @@ static void _dll_notification(ULONG reason, const PLDR_DLL_NOTIFICATION_DATA dat
|
|||||||
0xB8, 0x01, 0x00, 0x00, 0x00, // mov eax, 1
|
0xB8, 0x01, 0x00, 0x00, 0x00, // mov eax, 1
|
||||||
0xC3 // ret
|
0xC3 // ret
|
||||||
};
|
};
|
||||||
|
utils_write_protected_memory(entryPoint, ENTRY_POINT_STUB, sizeof(ENTRY_POINT_STUB));
|
||||||
DWORD oldProtect;
|
|
||||||
VirtualProtect(entryPoint, sizeof(ENTRY_POINT_STUB), PAGE_EXECUTE_READWRITE, &oldProtect);
|
|
||||||
|
|
||||||
memcpy(entryPoint, ENTRY_POINT_STUB, sizeof(ENTRY_POINT_STUB));
|
|
||||||
|
|
||||||
VirtualProtect(entryPoint, sizeof(ENTRY_POINT_STUB), oldProtect, &oldProtect);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _create_driver_file(const char *path) {
|
static void _create_driver_file(const char *path) {
|
||||||
|
@ -38,13 +38,8 @@ char *wtsud_patch_addr;
|
|||||||
|
|
||||||
static void _wtsud_stub() {
|
static void _wtsud_stub() {
|
||||||
// Recover original bytes
|
// Recover original bytes
|
||||||
DWORD oldProtect;
|
utils_write_protected_memory(wtsud_patch_addr, wtsud_original_bytes, JUMP_SIZE);
|
||||||
VirtualProtect(wtsud_patch_addr, JUMP_SIZE, PAGE_EXECUTE_READWRITE, &oldProtect);
|
|
||||||
|
|
||||||
memcpy(wtsud_patch_addr, wtsud_original_bytes, JUMP_SIZE);
|
|
||||||
|
|
||||||
VirtualProtect(wtsud_patch_addr, JUMP_SIZE, oldProtect, &oldProtect);
|
|
||||||
|
|
||||||
unload_ctr_dec();
|
unload_ctr_dec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,21 +54,20 @@ static void _unityplayer_callback(HMODULE unityModule) {
|
|||||||
|
|
||||||
wtsud_patch_addr = ((char*)unityModule) + WTSUD_PATCH_OFFSET;
|
wtsud_patch_addr = ((char*)unityModule) + WTSUD_PATCH_OFFSET;
|
||||||
|
|
||||||
DWORD oldProtect;
|
|
||||||
VirtualProtect(wtsud_patch_addr, JUMP_SIZE, PAGE_EXECUTE_READWRITE, &oldProtect);
|
|
||||||
|
|
||||||
// Save original bytes
|
// Save original bytes
|
||||||
memcpy(wtsud_original_bytes, wtsud_patch_addr, JUMP_SIZE);
|
memcpy(wtsud_original_bytes, wtsud_patch_addr, JUMP_SIZE);
|
||||||
|
|
||||||
// Write jump
|
// Prepare payload
|
||||||
|
char payload[JUMP_SIZE];
|
||||||
|
|
||||||
const char JUMP_INST[] = { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 }; // jmp [$ + 6]
|
const char JUMP_INST[] = { 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00 }; // jmp [$ + 6]
|
||||||
memcpy(wtsud_patch_addr, JUMP_INST, sizeof(JUMP_INST));
|
memcpy(payload, JUMP_INST, sizeof(JUMP_INST));
|
||||||
|
|
||||||
// Write destination address
|
|
||||||
void *destAddr = &_wtsud_stub;
|
void *destAddr = &_wtsud_stub;
|
||||||
memcpy(wtsud_patch_addr + sizeof(JUMP_INST), &destAddr, sizeof(destAddr));
|
memcpy(payload + sizeof(JUMP_INST), &destAddr, sizeof(destAddr));
|
||||||
|
|
||||||
VirtualProtect(wtsud_patch_addr, JUMP_SIZE, oldProtect, &oldProtect);
|
// Write payload
|
||||||
|
utils_write_protected_memory(wtsud_patch_addr, payload, sizeof(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
void hsr_fill_data(struct game_data *buf) {
|
void hsr_fill_data(struct game_data *buf) {
|
||||||
|
@ -64,3 +64,12 @@ char utils_env_enabled(const char *env) {
|
|||||||
char *envText = getenv(env);
|
char *envText = getenv(env);
|
||||||
return envText && *envText;
|
return envText && *envText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void utils_write_protected_memory(void *addr, void *buf, size_t size) {
|
||||||
|
DWORD oldProtect;
|
||||||
|
VirtualProtect(addr, size, PAGE_READWRITE, &oldProtect);
|
||||||
|
|
||||||
|
memcpy(addr, buf, size);
|
||||||
|
|
||||||
|
VirtualProtect(addr, size, oldProtect, &oldProtect);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user