Merge pull request #4900 from leoetlino/exheader-fix

ncch_container: Fix NCCH decryption heuristic when replacing exheader
This commit is contained in:
Pengfei Zhu 2019-09-14 10:33:06 -05:00 committed by GitHub
commit 360e6cb513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -325,20 +325,11 @@ Loader::ResultStatus NCCHContainer::Load() {
return file && file.ReadBytes(&exheader_header, size) == size; return file && file.ReadBytes(&exheader_header, size) == size;
}; };
FileUtil::IOFile exheader_override_file{filepath + ".exheader", "rb"}; if (!read_exheader(file)) {
const bool has_exheader_override = read_exheader(exheader_override_file);
if (has_exheader_override) {
if (exheader_header.system_info.jump_id !=
exheader_header.arm11_system_local_caps.program_id) {
LOG_WARNING(Service_FS, "Jump ID and Program ID don't match. "
"The override exheader might not be decrypted.");
}
is_tainted = true;
} else if (!read_exheader(file)) {
return Loader::ResultStatus::Error; return Loader::ResultStatus::Error;
} }
if (!has_exheader_override && is_encrypted) { if (is_encrypted) {
// This ID check is masked to low 32-bit as a toleration to ill-formed ROM created // This ID check is masked to low 32-bit as a toleration to ill-formed ROM created
// by merging games and its updates. // by merging games and its updates.
if ((exheader_header.system_info.jump_id & 0xFFFFFFFF) == if ((exheader_header.system_info.jump_id & 0xFFFFFFFF) ==
@ -358,6 +349,17 @@ Loader::ResultStatus NCCHContainer::Load() {
} }
} }
FileUtil::IOFile exheader_override_file{filepath + ".exheader", "rb"};
const bool has_exheader_override = read_exheader(exheader_override_file);
if (has_exheader_override) {
if (exheader_header.system_info.jump_id !=
exheader_header.arm11_system_local_caps.program_id) {
LOG_WARNING(Service_FS, "Jump ID and Program ID don't match. "
"The override exheader might not be decrypted.");
}
is_tainted = true;
}
is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1; is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1;
u32 entry_point = exheader_header.codeset_info.text.address; u32 entry_point = exheader_header.codeset_info.text.address;
u32 code_size = exheader_header.codeset_info.text.code_size; u32 code_size = exheader_header.codeset_info.text.code_size;