Embedded SPU elf patching

- PS3 games include both PPU and SPU code in their PPU executables, so to make patching games that make use of the same SPU libraries easier, we add a system to find and patch them.
- Patches for this system still use SPU LS (Local Storage) addresses despite the fact that we aren't loading anything into SPU LS at this time. The patches are checked against each segment and patched in place.
This commit is contained in:
Malcolm Jestadt 2020-01-07 04:10:23 -05:00 committed by Ivan
parent 7f07b79c04
commit ad8988afd3
3 changed files with 151 additions and 0 deletions

View file

@ -173,3 +173,78 @@ std::size_t patch_engine::apply(const std::string& name, u8* dst) const
return found->second.size();
}
std::size_t patch_engine::apply_with_ls_check(const std::string& name, u8* dst, u32 filesz, u32 ls_addr) const
{
u32 rejected = 0;
const auto found = m_map.find(name);
if (found == m_map.cend())
{
return 0;
}
// Apply modifications sequentially
for (const auto& p : found->second)
{
auto ptr = dst + (p.offset - ls_addr);
if(p.offset < ls_addr || p.offset >= (ls_addr + filesz))
{
// This patch is out of range for this segment
rejected++;
continue;
}
switch (p.type)
{
case patch_type::load:
{
// Invalid in this context
break;
}
case patch_type::byte:
{
*ptr = static_cast<u8>(p.value);
break;
}
case patch_type::le16:
{
*reinterpret_cast<le_t<u16, 1>*>(ptr) = static_cast<u16>(p.value);
break;
}
case patch_type::le32:
case patch_type::lef32:
{
*reinterpret_cast<le_t<u32, 1>*>(ptr) = static_cast<u32>(p.value);
break;
}
case patch_type::le64:
case patch_type::lef64:
{
*reinterpret_cast<le_t<u64, 1>*>(ptr) = static_cast<u64>(p.value);
break;
}
case patch_type::be16:
{
*reinterpret_cast<be_t<u16, 1>*>(ptr) = static_cast<u16>(p.value);
break;
}
case patch_type::be32:
case patch_type::bef32:
{
*reinterpret_cast<be_t<u32, 1>*>(ptr) = static_cast<u32>(p.value);
break;
}
case patch_type::be64:
case patch_type::bef64:
{
*reinterpret_cast<be_t<u64, 1>*>(ptr) = static_cast<u64>(p.value);
break;
}
}
}
return (found->second.size() - rejected);
}