Qt: add guest memory dump utility (#19068)

This adds a tool that writes a snapshot of the full PS3 guest address
space to disk for offline analysis.

This tool produces a flat image that any hex editor or script can index
directly by guest address. It dumps allocated PS3 guest memory only, not
RPCS3 host-process memory, host registers, or GPU-side state.

What it does:

1. Pauses emulation and waits up to five seconds for every PPU, SPU, and
RSX thread to settle. If they do not settle, nothing is written.
2. Copies every allocated guest page into an intermediate buffer on a
named worker thread, then writes it to a sparse `guest_memory.bin` whose
file offset equals the PS3 effective address. Reads go through
`vm::g_sudo_addr` so guest protected pages are captured too.
3. Saves each live SPU thread's 256 KB local store to its own file, with
its ID, LV2 ID, PC, and type recorded.
4. Writes `manifest.json`, listing every allocated region with its
addresses and permissions, the storage mode, and the SPU local-store
table.
5. Resumes emulation.

The menu entry is under Utilities next to Memory Viewer and is enabled
while a game is loaded. Free space is checked before writing. If sparse
file setup fails, the incomplete attempt is removed and the user can
choose another destination or cancel. Failed or cancelled dumps remove
their output folder instead of leaving a partial image.

Tested on Windows using an NTFS destination with a build from this
branch: dumped a running game with 479,535,104 allocated guest bytes
across 76 regions and five SPU local stores. The image was sparse, its
offsets matched guest addresses, and emulation resumed cleanly. The
sparse file failure path was also exercised with a temporary local test:
choosing another location reopened the destination picker, while
cancelling aborted the attempt without leaving partial output. Runtime
behavior on Linux and macOS is untested.

The first draft of this implementation was AI assisted. I reviewed and
adjusted the code and tested the Windows/NTFS path myself. I am happy to
rework anything or answer any questions.
This commit is contained in:
caner
2026-07-23 00:08:05 +00:00
committed by GitHub
parent 8604f1c5d8
commit 5ecfc95c13
5 changed files with 517 additions and 0 deletions
+12
View File
@@ -26,6 +26,7 @@ std::string g_android_cache_dir;
#include <cwchar>
#include <Windows.h>
#include <winioctl.h>
static std::unique_ptr<wchar_t[]> to_wchar(std::string_view source)
{
@@ -1963,6 +1964,17 @@ fs::native_handle fs::file::get_handle() const
#endif
}
bool fs::set_sparse(const fs::file& file)
{
#ifdef _WIN32
FILE_SET_SPARSE_BUFFER sparse{TRUE};
DWORD returned = 0;
return DeviceIoControl(file.get_handle(), FSCTL_SET_SPARSE, &sparse, sizeof(sparse), nullptr, 0, &returned, nullptr) != FALSE;
#else
return true;
#endif
}
fs::file_id fs::file::get_id() const
{
if (m_file)
+3
View File
@@ -496,6 +496,9 @@ namespace fs
}
};
// Enable sparse-file semantics when required by the host platform.
bool set_sparse(const file& file);
class dir final
{
std::unique_ptr<dir_base> m_dir{};
File diff suppressed because it is too large Load Diff
+1
View File
@@ -109,6 +109,7 @@ private Q_SLOTS:
void BootVSH();
void BootSavestate();
void BootRsxCapture(std::string path = "");
void DumpGuestMemory();
void DecryptSPRXLibraries();
void show_boot_error(game_boot_result status);
+12
View File
@@ -365,6 +365,7 @@
<addaction name="separator"/>
<addaction name="toolsSystemCommandsAct"/>
<addaction name="toolsmemory_viewerAct"/>
<addaction name="toolsDumpGuestMemoryAct"/>
<addaction name="toolskernel_explorerAct"/>
<addaction name="toolsRsxDebuggerAct"/>
<addaction name="separator"/>
@@ -759,6 +760,17 @@
<string>Memory Viewer</string>
</property>
</action>
<action name="toolsDumpGuestMemoryAct">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Dump Guest Memory</string>
</property>
<property name="toolTip">
<string>Dump all allocated PS3 guest memory and live SPU local stores</string>
</property>
</action>
<action name="toolsRsxDebuggerAct">
<property name="enabled">
<bool>false</bool>