mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 19:07:01 +02:00
remove readback hacks, allows to read/write guest memory directly
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||
#ifndef NOMINMAX
|
||||
@@ -21,10 +20,10 @@ bool IsAccessible(DWORD protect, HostMemoryAccess access) {
|
||||
constexpr DWORD blocked = PAGE_NOACCESS | PAGE_GUARD;
|
||||
constexpr DWORD readable = PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ |
|
||||
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;
|
||||
constexpr DWORD writable =
|
||||
PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;
|
||||
return (protect & blocked) == 0 &&
|
||||
(protect & (access == HostMemoryAccess::Write ? writable : readable)) != 0;
|
||||
if (access == HostMemoryAccess::Mapped) {
|
||||
return (protect & PAGE_GUARD) == 0;
|
||||
}
|
||||
return (protect & blocked) == 0 && (protect & readable) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -77,8 +76,7 @@ bool HostMemoryQueryRange(uint64_t addr, uint64_t requested_size, HostMemoryAcce
|
||||
if (begin > current) {
|
||||
break;
|
||||
}
|
||||
const bool allowed =
|
||||
access == HostMemoryAccess::Write ? permissions[1] == 'w' : permissions[0] == 'r';
|
||||
const bool allowed = access == HostMemoryAccess::Mapped || permissions[0] == 'r';
|
||||
if (!allowed) {
|
||||
break;
|
||||
}
|
||||
@@ -93,39 +91,10 @@ bool HostMemoryQueryRange(uint64_t addr, uint64_t requested_size, HostMemoryAcce
|
||||
return *accessible_size != 0;
|
||||
}
|
||||
|
||||
bool HostMemoryQueryEnd(uint64_t addr, HostMemoryAccess access, uint64_t* end) {
|
||||
if (addr == 0 || end == nullptr) {
|
||||
return false;
|
||||
}
|
||||
uint64_t accessible_size = 0;
|
||||
if (!HostMemoryQueryRange(addr, UINT64_MAX - addr, access, &accessible_size) ||
|
||||
accessible_size == 0 || UINT64_MAX - addr < accessible_size) {
|
||||
return false;
|
||||
}
|
||||
*end = addr + accessible_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HostMemoryQueryReadable(uint64_t addr, uint64_t requested_size, uint64_t* readable_size) {
|
||||
return HostMemoryQueryRange(addr, requested_size, HostMemoryAccess::Read, readable_size);
|
||||
}
|
||||
|
||||
bool HostMemoryQueryWritable(uint64_t addr, uint64_t requested_size, uint64_t* writable_size) {
|
||||
return HostMemoryQueryRange(addr, requested_size, HostMemoryAccess::Write, writable_size);
|
||||
}
|
||||
|
||||
bool HostMemoryReadDword(void*, uint64_t addr, uint32_t* value) {
|
||||
if (value == nullptr) {
|
||||
return false;
|
||||
}
|
||||
uint64_t readable = 0;
|
||||
if (!HostMemoryQueryReadable(addr, sizeof(*value), &readable) || readable < sizeof(*value)) {
|
||||
return false;
|
||||
}
|
||||
std::memcpy(value, reinterpret_cast<const void*>(static_cast<uintptr_t>(addr)), sizeof(*value));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HostMemoryIsReadable(uint64_t addr) {
|
||||
return HostMemoryRangeIsReadable(addr, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user