PPU: Precompile only encrypted executeables

Improve sys_prx_load_module and sys_overlay_load_module error checking.
This commit is contained in:
Eladash 2023-09-02 20:07:35 +03:00 committed by Elad Ashkenazi
parent d62d6cc852
commit b900c43ceb
5 changed files with 18 additions and 7 deletions

View file

@ -1403,7 +1403,7 @@ static bool CheckDebugSelf(fs::file& s)
return false; return false;
} }
fs::file decrypt_self(fs::file elf_or_self, u8* klic_key, SelfAdditionalInfo* out_info) fs::file decrypt_self(fs::file elf_or_self, u8* klic_key, SelfAdditionalInfo* out_info, bool require_encrypted)
{ {
if (out_info) if (out_info)
{ {
@ -1418,8 +1418,14 @@ fs::file decrypt_self(fs::file elf_or_self, u8* klic_key, SelfAdditionalInfo* ou
elf_or_self.seek(0); elf_or_self.seek(0);
// Check SELF header first. Check for a debug SELF. // Check SELF header first. Check for a debug SELF.
if (elf_or_self.size() >= 4 && elf_or_self.read<u32>() == "SCE\0"_u32 && !CheckDebugSelf(elf_or_self)) if (elf_or_self.size() >= 4 && elf_or_self.read<u32>() == "SCE\0"_u32)
{ {
if (CheckDebugSelf(elf_or_self))
{
// TODO: Decrypt
return elf_or_self;
}
// Check the ELF file class (32 or 64 bit). // Check the ELF file class (32 or 64 bit).
const bool isElf32 = IsSelfElf32(elf_or_self); const bool isElf32 = IsSelfElf32(elf_or_self);
@ -1451,6 +1457,11 @@ fs::file decrypt_self(fs::file elf_or_self, u8* klic_key, SelfAdditionalInfo* ou
return self_dec.MakeElf(isElf32); return self_dec.MakeElf(isElf32);
} }
if (require_encrypted)
{
return {};
}
return elf_or_self; return elf_or_self;
} }

View file

@ -559,7 +559,7 @@ private:
} }
}; };
fs::file decrypt_self(fs::file elf_or_self, u8* klic_key = nullptr, SelfAdditionalInfo* additional_info = nullptr); fs::file decrypt_self(fs::file elf_or_self, u8* klic_key = nullptr, SelfAdditionalInfo* additional_info = nullptr, bool require_encrypted = false);
bool verify_npdrm_self_headers(const fs::file& self, u8* klic_key = nullptr, NPD_HEADER* npd_out = nullptr); bool verify_npdrm_self_headers(const fs::file& self, u8* klic_key = nullptr, NPD_HEADER* npd_out = nullptr);
bool get_npdrm_self_header(const fs::file& self, NPD_HEADER& npd); bool get_npdrm_self_header(const fs::file& self, NPD_HEADER& npd);

View file

@ -3890,7 +3890,7 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<ppu_
} }
// Some files may fail to decrypt due to the lack of klic // Some files may fail to decrypt due to the lack of klic
src = decrypt_self(std::move(src)); src = decrypt_self(std::move(src), nullptr, nullptr, true);
if (!src) if (!src)
{ {

View file

@ -36,7 +36,7 @@ static error_code overlay_load_module(vm::ptr<u32> ovlmid, const std::string& vp
u128 klic = g_fxo->get<loaded_npdrm_keys>().last_key(); u128 klic = g_fxo->get<loaded_npdrm_keys>().last_key();
ppu_exec_object obj = decrypt_self(std::move(src), reinterpret_cast<u8*>(&klic)); ppu_exec_object obj = decrypt_self(std::move(src), reinterpret_cast<u8*>(&klic), nullptr, true);
if (obj != elf_error::ok) if (obj != elf_error::ok)
{ {

View file

@ -263,11 +263,11 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
u128 klic = g_fxo->get<loaded_npdrm_keys>().last_key(); u128 klic = g_fxo->get<loaded_npdrm_keys>().last_key();
ppu_prx_object obj = decrypt_self(std::move(src), reinterpret_cast<u8*>(&klic)); ppu_prx_object obj = decrypt_self(std::move(src), reinterpret_cast<u8*>(&klic), nullptr, true);
if (obj != elf_error::ok) if (obj != elf_error::ok)
{ {
return CELL_PRX_ERROR_ILLEGAL_LIBRARY; return CELL_PRX_ERROR_UNSUPPORTED_PRX_TYPE;
} }
const auto prx = ppu_load_prx(obj, false, path, file_offset); const auto prx = ppu_load_prx(obj, false, path, file_offset);