From 549f11a40ec17d24d5689080052ceebb8ddb29f4 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Wed, 15 Nov 2017 17:30:52 -0700 Subject: [PATCH] file_sys/ncch_container: Expose ncch_offset during instantiation and in OpenFile --- src/core/file_sys/ncch_container.cpp | 10 ++++++---- src/core/file_sys/ncch_container.h | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index b9fb940c7b..56ecd8123b 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -95,12 +95,14 @@ static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decom return true; } -NCCHContainer::NCCHContainer(const std::string& filepath) : filepath(filepath) { +NCCHContainer::NCCHContainer(const std::string& filepath, u32 ncch_offset) + : filepath(filepath), ncch_offset(ncch_offset) { file = FileUtil::IOFile(filepath, "rb"); } -Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath) { +Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 ncch_offset) { this->filepath = filepath; + this->ncch_offset = ncch_offset; file = FileUtil::IOFile(filepath, "rb"); if (!file.IsOpen()) { @@ -118,7 +120,7 @@ Loader::ResultStatus NCCHContainer::Load() { if (file.IsOpen()) { // Reset read pointer in case this file has been read before. - file.Seek(0, SEEK_SET); + file.Seek(ncch_offset, SEEK_SET); if (file.ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header)) return Loader::ResultStatus::Error; @@ -126,7 +128,7 @@ Loader::ResultStatus NCCHContainer::Load() { // Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)... if (Loader::MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) { LOG_DEBUG(Service_FS, "Only loading the first (bootable) NCCH within the NCSD file!"); - ncch_offset = 0x4000; + ncch_offset += 0x4000; file.Seek(ncch_offset, SEEK_SET); file.ReadBytes(&ncch_header, sizeof(NCCH_Header)); } diff --git a/src/core/file_sys/ncch_container.h b/src/core/file_sys/ncch_container.h index 2cc9d13dcf..77794a763c 100644 --- a/src/core/file_sys/ncch_container.h +++ b/src/core/file_sys/ncch_container.h @@ -168,10 +168,10 @@ namespace FileSys { */ class NCCHContainer { public: - NCCHContainer(const std::string& filepath); + NCCHContainer(const std::string& filepath, u32 ncch_offset = 0); NCCHContainer() {} - Loader::ResultStatus OpenFile(const std::string& filepath); + Loader::ResultStatus OpenFile(const std::string& filepath, u32 ncch_offset = 0); /** * Ensure ExeFS and exheader is loaded and ready for reading sections @@ -263,7 +263,7 @@ private: bool is_loaded = false; bool is_compressed = false; - u32 ncch_offset = 0; // Offset to NCCH header, can be 0 or after NCSD header + u32 ncch_offset = 0; // Offset to NCCH header, can be 0 for NCCHs or non-zero for CIAs/NCSDs u32 exefs_offset = 0; std::string filepath;