mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-06 23:11:25 +12:00
Cache decrypted EBOOT.BIN
This commit is contained in:
parent
5e539f71e6
commit
4cba60b27f
1 changed files with 41 additions and 35 deletions
|
@ -155,56 +155,68 @@ void Emulator::Load()
|
||||||
// Open SELF or ELF
|
// Open SELF or ELF
|
||||||
fs::file elf_file(m_path);
|
fs::file elf_file(m_path);
|
||||||
|
|
||||||
LOG_NOTICE(LOADER, "Path: %s", m_path);
|
|
||||||
|
|
||||||
if (!elf_file)
|
if (!elf_file)
|
||||||
{
|
{
|
||||||
LOG_ERROR(LOADER, "Failed to open file: %s", m_path);
|
LOG_ERROR(LOADER, "Failed to open file: %s", m_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& elf_dir = fs::get_parent_dir(m_path);
|
LOG_NOTICE(LOADER, "Path: %s", m_path);
|
||||||
|
|
||||||
|
const std::string elf_dir = fs::get_parent_dir(m_path);
|
||||||
|
const fs::file sfov(elf_dir + "/sce_sys/param.sfo");
|
||||||
|
const fs::file sfo1(elf_dir + "/../PARAM.SFO");
|
||||||
|
|
||||||
|
// Load PARAM.SFO (TODO)
|
||||||
|
const auto _psf = psf::load_object(sfov ? sfov : sfo1);
|
||||||
|
m_title = psf::get_string(_psf, "TITLE", m_path);
|
||||||
|
m_title_id = psf::get_string(_psf, "TITLE_ID");
|
||||||
|
|
||||||
|
// Initialize data/cache directory
|
||||||
|
const std::string data_dir = fs::get_data_dir(m_title_id, m_path);
|
||||||
|
|
||||||
// Check SELF header
|
// Check SELF header
|
||||||
if (elf_file.size() >= 4 && elf_file.read<u32>() == "SCE\0"_u32)
|
if (elf_file.size() >= 4 && elf_file.read<u32>() == "SCE\0"_u32)
|
||||||
{
|
{
|
||||||
// Decrypt SELF
|
const std::string decrypted_path = data_dir + "boot.elf";
|
||||||
elf_file = decrypt_self(std::move(elf_file));
|
|
||||||
|
|
||||||
const std::size_t elf_ext_pos = m_path.find_last_of('.');
|
fs::stat_t encrypted_stat = elf_file.stat();
|
||||||
const std::string& elf_ext = fmt::to_upper(m_path.substr(elf_ext_pos != -1 ? elf_ext_pos : m_path.size()));
|
fs::stat_t decrypted_stat;
|
||||||
const std::string& elf_name = m_path.substr(elf_dir.size());
|
|
||||||
|
|
||||||
// Save ELF (TODO: configuration, cache and different file location)
|
// Check modification time and try to load decrypted ELF
|
||||||
std::string new_path = m_path;
|
if (fs::stat(decrypted_path, decrypted_stat) && decrypted_stat.mtime == encrypted_stat.mtime)
|
||||||
|
|
||||||
if (elf_name.compare(elf_name.find_last_of("/\\", -1, 2) + 1, 9, "EBOOT.BIN", 9) == 0)
|
|
||||||
{
|
{
|
||||||
new_path.erase(new_path.size() - 9, 1); // change EBOOT.BIN to BOOT.BIN
|
elf_file.open(decrypted_path);
|
||||||
}
|
|
||||||
else if (elf_ext == ".SELF" || elf_ext == ".SPRX")
|
|
||||||
{
|
|
||||||
new_path.erase(new_path.size() - 4, 1); // change *.self to *.elf, *.sprx to *.prx
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_path += ".decrypted.elf";
|
// Decrypt SELF
|
||||||
}
|
elf_file = decrypt_self(std::move(elf_file));
|
||||||
|
|
||||||
if (fs::file elf_out{new_path, fs::rewrite})
|
if (fs::file elf_out{decrypted_path, fs::rewrite})
|
||||||
{
|
{
|
||||||
elf_out.write(elf_file.to_vector<u8>());
|
elf_out.write(elf_file.to_vector<u8>());
|
||||||
}
|
elf_out.close();
|
||||||
else
|
fs::utime(decrypted_path, encrypted_stat.atime, encrypted_stat.mtime);
|
||||||
{
|
}
|
||||||
LOG_ERROR(LOADER, "Failed to save file: %s", new_path);
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR(LOADER, "Failed to create boot.elf", data_dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load custom config
|
// Load custom config-1
|
||||||
if (fs::file cfg_file{ m_path + ".yml" })
|
if (fs::file cfg_file{data_dir + "config.yml"})
|
||||||
{
|
{
|
||||||
LOG_NOTICE(LOADER, "Custom config: %s.yml", m_path);
|
LOG_NOTICE(LOADER, "Applying custom config (config.yml)");
|
||||||
|
cfg::root.from_string(cfg_file.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load custom config-2
|
||||||
|
if (fs::file cfg_file{m_path + ".yml"})
|
||||||
|
{
|
||||||
|
LOG_NOTICE(LOADER, "Applying custom config: %s.yml", m_path);
|
||||||
cfg::root.from_string(cfg_file.to_string());
|
cfg::root.from_string(cfg_file.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,12 +243,6 @@ void Emulator::Load()
|
||||||
LOG_NOTICE(LOADER, "Elf path: %s", m_elf_path);
|
LOG_NOTICE(LOADER, "Elf path: %s", m_elf_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load PARAM.SFO
|
|
||||||
const auto _psf = psf::load_object(fs::file(elf_dir + "/../PARAM.SFO"));
|
|
||||||
m_title = psf::get_string(_psf, "TITLE", m_path);
|
|
||||||
m_title_id = psf::get_string(_psf, "TITLE_ID");
|
|
||||||
fs::get_data_dir(m_title_id, m_path);
|
|
||||||
|
|
||||||
LOG_NOTICE(LOADER, "Title: %s", GetTitle());
|
LOG_NOTICE(LOADER, "Title: %s", GetTitle());
|
||||||
LOG_NOTICE(LOADER, "Serial: %s", GetTitleID());
|
LOG_NOTICE(LOADER, "Serial: %s", GetTitleID());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue