From b7ff2ecffb3c304c6718c6d695010acafd68bb86 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 2 Feb 2021 19:18:50 +0300 Subject: [PATCH] Patch system: export some info for future use For now it's just a list of addresses. For now it's not used (just a stub). --- Utilities/bin_patch.cpp | 32 +++++++++++++++++++------------- Utilities/bin_patch.h | 8 ++++---- rpcs3/Emu/Cell/PPUModule.cpp | 16 ++++++++-------- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 2 +- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index c6a8ef068c..646514ed27 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -505,26 +505,27 @@ void patch_engine::append_title_patches(const std::string& title_id) load(m_map, get_patches_path() + title_id + "_patch.yml"); } -usz patch_engine::apply(const std::string& name, u8* dst) +std::basic_string patch_engine::apply(const std::string& name, u8* dst) { return apply_patch(name, dst, 0, 0); } -usz patch_engine::apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr) +std::basic_string patch_engine::apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr) { return apply_patch(name, dst, filesz, ls_addr); } -template -static usz apply_modification(const patch_engine::patch_info& patch, u8* dst, u32 filesz, u32 ls_addr) +template +static std::basic_string apply_modification(const patch_engine::patch_info& patch, u8* dst, u32 filesz, u32 ls_addr) { - usz applied = 0; + std::basic_string applied; for (const auto& p : patch.data_list) { u32 offset = p.offset; + u32 resval = 0; - if constexpr (check_local_storage) + if constexpr (CheckLS) { if (offset < ls_addr || offset >= (ls_addr + filesz)) { @@ -583,6 +584,10 @@ static usz apply_modification(const patch_engine::patch_info& patch, u8* dst, u3 case patch_type::be32: { *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + + // Possibly an executable instruction + if constexpr (!CheckLS) + resval = offset; break; } case patch_type::bef32: @@ -602,21 +607,21 @@ static usz apply_modification(const patch_engine::patch_info& patch, u8* dst, u3 } } - ++applied; + applied.push_back(resval); } return applied; } -template -usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr) +template +std::basic_string patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr) { if (m_map.find(name) == m_map.cend()) { - return 0; + return {}; } - usz applied_total = 0; + std::basic_string applied_total; const auto& container = m_map.at(name); const auto serial = Emu.GetTitleID(); const auto app_version = Emu.GetAppVersion(); @@ -714,10 +719,11 @@ usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 m_applied_groups.insert(patch.patch_group); } - const usz applied = apply_modification(patch, dst, filesz, ls_addr); + auto applied = apply_modification(patch, dst, filesz, ls_addr); + applied_total += applied; - patch_log.success("Applied patch (hash='%s', description='%s', author='%s', patch_version='%s', file_version='%s') (<- %d)", patch.hash, patch.description, patch.author, patch.patch_version, patch.version, applied); + patch_log.success("Applied patch (hash='%s', description='%s', author='%s', patch_version='%s', file_version='%s') (<- %u)", patch.hash, patch.description, patch.author, patch.patch_version, patch.version, applied.size()); } return applied_total; diff --git a/Utilities/bin_patch.h b/Utilities/bin_patch.h index 56e94e17d8..0a8e5d64fe 100644 --- a/Utilities/bin_patch.h +++ b/Utilities/bin_patch.h @@ -129,15 +129,15 @@ public: void append_title_patches(const std::string& title_id); // Apply patch (returns the number of entries applied) - usz apply(const std::string& name, u8* dst); + std::basic_string apply(const std::string& name, u8* dst); // Apply patch with a check that the address exists in SPU local storage - usz apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr); + std::basic_string apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr); private: // Internal: Apply patch (returns the number of entries applied) - template - usz apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr); + template + std::basic_string apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr); // Database patch_map m_map; diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 65e7bed77a..08aff7024c 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -717,7 +717,7 @@ static void ppu_check_patch_spu_images(const ppu_segment& seg) std::string name; std::string dump; - usz applied = 0; + std::basic_string applied; // Executable hash sha1_context sha2; @@ -782,7 +782,7 @@ static void ppu_check_patch_spu_images(const ppu_segment& seg) } } - ppu_loader.success("SPU executable hash: %s (<- %u)%s", hash, applied, dump); + ppu_loader.success("SPU executable hash: %s (<- %u)%s", hash, applied.size(), dump); } } @@ -1107,7 +1107,7 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri applied += g_fxo->get()->apply(Emu.GetTitleID() + '-' + hash, vm::g_base_addr); } - if (applied) + if (!applied.empty()) { // TODO (invalidate constraints if patches were applied) end = 0; @@ -1121,7 +1121,7 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri prx->analyse(toc, 0, end); - ppu_loader.success("PRX library hash: %s (<- %u)", hash, applied); + ppu_loader.success("PRX library hash: %s (<- %u)", hash, applied.size()); try_spawn_ppu_if_exclusive_program(*prx); @@ -1330,7 +1330,7 @@ bool ppu_load_exec(const ppu_exec_object& elf) applied += g_fxo->get()->apply(Emu.GetTitleID() + '-' + hash, vm::g_base_addr); } - ppu_loader.success("PPU executable hash: %s (<- %u)", hash, applied); + ppu_loader.success("PPU executable hash: %s (<- %u)", hash, applied.size()); // Initialize HLE modules ppu_initialize_modules(link); @@ -1570,7 +1570,7 @@ bool ppu_load_exec(const ppu_exec_object& elf) _main->name.clear(); _main->path = vfs::get(Emu.argv[0]); - if (applied) + if (!applied.empty()) { // TODO (invalidate constraints if patches were applied) end = 0; @@ -1893,7 +1893,7 @@ std::pair, CellError> ppu_load_overlay(const ppu_ex ppu_check_patch_spu_images(seg); } - ppu_loader.success("OVL executable hash: %s (<- %u)", hash, applied); + ppu_loader.success("OVL executable hash: %s (<- %u)", hash, applied.size()); // Load other programs for (auto& prog : elf.progs) @@ -1980,7 +1980,7 @@ std::pair, CellError> ppu_load_overlay(const ppu_ex ovlm->entry = static_cast(elf.header.e_entry); - if (applied) + if (!applied.empty()) { // TODO (invalidate constraints if patches were applied) end = 0; diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index e3b9a647a0..7488c1011f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -176,7 +176,7 @@ void sys_spu_image::deploy(u8* loc, sys_spu_segment* segs, u32 nsegs) applied += g_fxo->get()->apply(Emu.GetTitleID() + '-' + hash, loc); } - spu_log.notice("Loaded SPU image: %s (<- %u)%s", hash, applied, dump); + spu_log.notice("Loaded SPU image: %s (<- %u)%s", hash, applied.size(), dump); } // Get spu thread ptr, returns group ptr as well for refcounting