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).
This commit is contained in:
Nekotekina 2021-02-02 19:18:50 +03:00
parent fad89f1c3b
commit b7ff2ecffb
4 changed files with 32 additions and 26 deletions

View File

@ -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<u32> patch_engine::apply(const std::string& name, u8* dst)
{
return apply_patch<false>(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<u32> patch_engine::apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr)
{
return apply_patch<true>(name, dst, filesz, ls_addr);
}
template <bool check_local_storage>
static usz apply_modification(const patch_engine::patch_info& patch, u8* dst, u32 filesz, u32 ls_addr)
template <bool CheckLS>
static std::basic_string<u32> apply_modification(const patch_engine::patch_info& patch, u8* dst, u32 filesz, u32 ls_addr)
{
usz applied = 0;
std::basic_string<u32> 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<be_t<u32, 1>*>(ptr) = static_cast<u32>(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 <bool check_local_storage>
usz patch_engine::apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr)
template <bool CheckLS>
std::basic_string<u32> 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<u32> 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<check_local_storage>(patch, dst, filesz, ls_addr);
auto applied = apply_modification<CheckLS>(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;

View File

@ -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<u32> 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<u32> 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 <bool check_local_storage>
usz apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr);
template <bool CheckLS>
std::basic_string<u32> apply_patch(const std::string& name, u8* dst, u32 filesz, u32 ls_addr);
// Database
patch_map m_map;

View File

@ -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<u32> 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<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::stri
applied += g_fxo->get<patch_engine>()->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<lv2_prx> 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<patch_engine>()->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<std::shared_ptr<lv2_overlay>, 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<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_ex
ovlm->entry = static_cast<u32>(elf.header.e_entry);
if (applied)
if (!applied.empty())
{
// TODO (invalidate constraints if patches were applied)
end = 0;

View File

@ -176,7 +176,7 @@ void sys_spu_image::deploy(u8* loc, sys_spu_segment* segs, u32 nsegs)
applied += g_fxo->get<patch_engine>()->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