forked from Armonte/wanwan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFM2K_Memory.cpp
More file actions
44 lines (38 loc) · 1.53 KB
/
Copy pathFM2K_Memory.cpp
File metadata and controls
44 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "FM2K_Integration.h"
#include "SDL3/SDL.h"
#include <windows.h>
// All definitions inside FM2K namespace declared in the header
namespace FM2K {
bool ReadMemoryRaw(HANDLE proc, uintptr_t remote_addr, void* out, size_t bytes)
{
if (!proc || !out || bytes == 0) return false;
SIZE_T read = 0;
if (!::ReadProcessMemory(proc, reinterpret_cast<LPCVOID>(remote_addr), out, bytes, &read) || read != bytes) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"ReadProcessMemory failed (addr=0x%p, bytes=%zu, err=%lu)",
reinterpret_cast<void*>(remote_addr), bytes, ::GetLastError());
return false;
}
return true;
}
bool WriteMemoryRaw(HANDLE proc, uintptr_t remote_addr, const void* in, size_t bytes)
{
if (!proc || !in || bytes == 0) return false;
SIZE_T written = 0;
if (!::WriteProcessMemory(proc, reinterpret_cast<LPVOID>(remote_addr), in, bytes, &written) || written != bytes) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"WriteProcessMemory failed (addr=0x%p, bytes=%zu, err=%lu)",
reinterpret_cast<void*>(remote_addr), bytes, ::GetLastError());
return false;
}
return true;
}
bool BulkCopyOut(HANDLE proc, void* local_dst, uintptr_t remote_src, size_t bytes)
{
return ReadMemoryRaw(proc, remote_src, local_dst, bytes);
}
bool BulkCopyIn(HANDLE proc, uintptr_t remote_dst, const void* local_src, size_t bytes)
{
return WriteMemoryRaw(proc, remote_dst, local_src, bytes);
}
} // namespace FM2K