PPU Debug: Dump decrypted PRX

This commit is contained in:
Elad Ashkenazi 2024-06-07 19:27:15 +03:00
parent 721e55458c
commit 4e8e5a7fed
2 changed files with 15 additions and 4 deletions

View File

@ -17,6 +17,8 @@
#include "sys_memory.h"
#include <span>
extern void dump_executable(std::span<const u8> data, ppu_module* _main, std::string_view title_id);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, bool virtual_load, const std::string&, s64, utils::serial* = nullptr);
extern void ppu_unload_prx(const lv2_prx& prx);
extern bool ppu_initialize(const ppu_module&, bool check_only = false, u64 file_size = 0);
@ -270,6 +272,8 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
return {CELL_PRX_ERROR_UNSUPPORTED_PRX_TYPE, +"Failed to decrypt file"};
}
const auto src_data = g_cfg.core.ppu_debug ? src.to_vector<u8>() : std::vector<u8>{};
ppu_prx_object obj = std::move(src);
src.close();
@ -280,6 +284,11 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
const auto prx = ppu_load_prx(obj, false, path, file_offset);
if (g_cfg.core.ppu_debug)
{
dump_executable({src_data.data(), src_data.size()}, prx.get(), Emu.GetTitleID());
}
obj.clear();
if (!prx)

View File

@ -301,16 +301,18 @@ static void fixup_settings(const psf::registry* _psf)
}
}
extern void dump_executable(std::span<const u8> data, ppu_module* _main, std::string_view title_id)
extern void dump_executable(std::span<const u8> data, ppu_module* _module, std::string_view title_id)
{
const std::string_view filename = _module->path.substr(_module->path.find_last_of('/') + 1);
// Format filename and directory name
// Make each directory for each file so tools like IDA can work on it cleanly
const std::string dir_path = fs::get_cache_dir() + "ppu_progs/" + std::string{!title_id.empty() ? title_id : "untitled"} + fmt::format("-%s-%s", fmt::base57(_main->sha1), _main->path.substr(_main->path.find_last_of('/') + 1)) + '/';
const std::string filename = dir_path + "exec.elf";
const std::string dir_path = fs::get_cache_dir() + "ppu_progs/" + std::string{!title_id.empty() ? title_id : "untitled"} + fmt::format("-%s-%s", fmt::base57(_module->sha1), filename) + '/';
const std::string file_path = dir_path + (fmt::to_lower(filename).ends_with(".prx") || fmt::to_lower(filename).ends_with(".sprx") ? "prog.prx" : "exec.elf");
if (fs::create_dir(dir_path) || fs::g_tls_error == fs::error::exist)
{
if (fs::file out{filename, fs::create + fs::write})
if (fs::file out{file_path, fs::create + fs::write})
{
if (out.size() == data.size())
{