From bc3041248410de4e209a89b200359f16216c6196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 29 Jun 2019 18:08:52 +0200 Subject: [PATCH] ncch_container: Add support for exheader replacement This adds support for custom exheaders, which brings feature parity with Luma3DS's code patching functionality and allows for injecting new game code. --- src/core/file_sys/ncch_container.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index 1a2a6c194c..5efd5e54de 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -320,9 +320,17 @@ Loader::ResultStatus NCCHContainer::Load() { // System archives and DLC don't have an extended header but have RomFS if (ncch_header.extended_header_size) { - if (file.ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != - sizeof(ExHeader_Header)) + auto read_exheader = [this](FileUtil::IOFile& file) { + const std::size_t size = sizeof(exheader_header); + return file && file.ReadBytes(&exheader_header, size) == size; + }; + + FileUtil::IOFile exheader_override_file{filepath + ".exheader", "rb"}; + if (read_exheader(exheader_override_file)) { + is_tainted = true; + } else if (!read_exheader(file)) { return Loader::ResultStatus::Error; + } if (is_encrypted) { // This ID check is masked to low 32-bit as a toleration to ill-formed ROM created