From ab7a1a6ec4befc3f43a3f3ca55d0927d8fa15599 Mon Sep 17 00:00:00 2001 From: elad335 <18193363+elad335@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:36:03 +0300 Subject: [PATCH] sys_spu: Fix sys_spu_image_open --- rpcs3/Crypto/unself.cpp | 5 ++++- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 3855dcd62f..c2d430fe10 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -1371,7 +1371,10 @@ fs::file decrypt_self(const fs::file& elf_or_self, const u8* klic_key, SelfAddit elf_or_self.seek(0); // Check SELF header first. Check for a debug SELF. - if (elf_or_self.size() >= 4 && elf_or_self.read() == "SCE\0"_u32) + u32 file_type = umax; + elf_or_self.read_at(0, &file_type, sizeof(file_type)); + + if (file_type == "SCE\0"_u32) { if (fs::file res = CheckDebugSelf(elf_or_self)) { diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 7011475a2d..9cc12678b9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -94,7 +94,7 @@ void sys_spu_image::load(const fs::file& stream) const s32 nsegs = sys_spu_image::get_nsegs(obj.progs); const u32 mem_size = nsegs * sizeof(sys_spu_segment) + ::size32(stream); - const vm::ptr segs = vm::cast(vm::alloc(mem_size, vm::main)); + const vm::ptr segs = vm::cast(vm::reserve_map(vm::user64km 0, 0x10000000)->alloc(mem_size)); //const u32 entry = obj.header.e_entry; @@ -517,7 +517,20 @@ error_code sys_spu_image_open(ppu_thread& ppu, vm::ptr img, vm::c u128 klic = g_fxo->get().last_key(); - const fs::file elf_file = decrypt_self(std::move(file), reinterpret_cast(&klic)); + fs::file elf_file; + + // Check for SELF header + u32 file_type = umax; + file.read_at(0, &file_type, sizeof(file_type)); + + if (file_type == "SCE\0"_u32) + { + elf_file = decrypt_self(file, reinterpret_cast(&klic)); + } + else + { + elf_file = std::move(file); + } if (!elf_file) {