extern bool verify_npdrm_self_headers(const fs::file& self, u8* klic_key) { if (!self) return false; self.seek(0); if (self.size() >= 4 && self.read<u32>() == "SCE\0"_u32) { // Check the ELF file class (32 or 64 bit). bool isElf32 = IsSelfElf32(self); // Start the decrypter on this SELF file. SELFDecrypter self_dec(self); // Load the SELF file headers. if (!self_dec.LoadHeaders(isElf32)) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file headers!"); return false; } // Load and decrypt the SELF file metadata. if (!self_dec.LoadMetadata(klic_key)) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file metadata!"); return false; } } return true; }
bool DecryptSelf(const std::string& elf, const std::string& self) { LOG_NOTICE(LOADER, "Decrypting %s", self); // Check for a debug SELF first. if (!CheckDebugSelf(self, elf)) { // Set a virtual pointer to the SELF file. fs::file self_vf(self); if (!self_vf) return false; // Check the ELF file class (32 or 64 bit). bool isElf32 = IsSelfElf32(self); // Start the decrypter on this SELF file. SELFDecrypter self_dec(self_vf); // Load the SELF file headers. if (!self_dec.LoadHeaders(isElf32)) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file headers!"); return false; } // Load and decrypt the SELF file metadata. if (!self_dec.LoadMetadata()) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file metadata!"); return false; } // Decrypt the SELF file data. if (!self_dec.DecryptData()) { LOG_ERROR(LOADER, "SELF: Failed to decrypt SELF file data!"); return false; } // Make a new ELF file from this SELF. if (!self_dec.MakeElf(elf, isElf32)) { LOG_ERROR(LOADER, "SELF: Failed to make ELF file from SELF!"); return false; } } return true; }
bool DecryptSelf(const std::string& elf, const std::string& self) { // Check for a debug SELF first. if (!CheckDebugSelf(self, elf)) { // Set a virtual pointer to the SELF file. vfsLocalFile self_vf(nullptr); if (!self_vf.Open(self)) return false; // Check the ELF file class (32 or 64 bit). bool isElf32 = IsSelfElf32(self); // Start the decrypter on this SELF file. SELFDecrypter self_dec(self_vf); // Load the SELF file headers. if (!self_dec.LoadHeaders(isElf32)) { ConLog.Error("SELF: Failed to load SELF file headers!"); return false; } // Load and decrypt the SELF file metadata. if (!self_dec.LoadMetadata()) { ConLog.Error("SELF: Failed to load SELF file metadata!"); return false; } // Decrypt the SELF file data. if (!self_dec.DecryptData()) { ConLog.Error("SELF: Failed to decrypt SELF file data!"); return false; } // Make a new ELF file from this SELF. if (!self_dec.MakeElf(elf, isElf32)) { ConLog.Error("SELF: Failed to make ELF file from SELF!"); return false; } } return true; }
extern fs::file decrypt_self(fs::file elf_or_self, u8* klic_key) { if (!elf_or_self) { return fs::file{}; } elf_or_self.seek(0); // 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)) { // Check the ELF file class (32 or 64 bit). bool isElf32 = IsSelfElf32(elf_or_self); // Start the decrypter on this SELF file. SELFDecrypter self_dec(elf_or_self); // Load the SELF file headers. if (!self_dec.LoadHeaders(isElf32)) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file headers!"); return fs::file{}; } // Load and decrypt the SELF file metadata. if (!self_dec.LoadMetadata(klic_key)) { LOG_ERROR(LOADER, "SELF: Failed to load SELF file metadata!"); return fs::file{}; } // Decrypt the SELF file data. if (!self_dec.DecryptData()) { LOG_ERROR(LOADER, "SELF: Failed to decrypt SELF file data!"); return fs::file{}; } // Make a new ELF file from this SELF. return self_dec.MakeElf(isElf32); } return elf_or_self; }