From 390b544059be0e94a2572c54cc9d8924c9f0a15e Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 7 Jul 2022 20:41:05 +0800 Subject: [PATCH 1/2] Fixed XCI Header Hey selection. --- deps/libpietendo | 2 +- src/GameCardProcess.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/libpietendo b/deps/libpietendo index 3c68ffe..89204ee 160000 --- a/deps/libpietendo +++ b/deps/libpietendo @@ -1 +1 @@ -Subproject commit 3c68ffeeb903d286647823ea1676d1cb7ede939b +Subproject commit 89204ee499bfb3e4d1017c4a1fe2d29b2e70ff37 diff --git a/src/GameCardProcess.cpp b/src/GameCardProcess.cpp index 599b22f..c415aed 100644 --- a/src/GameCardProcess.cpp +++ b/src/GameCardProcess.cpp @@ -120,7 +120,7 @@ void nstool::GameCardProcess::importHeader() memcpy(mHdrSignature.data(), hdr_ptr->signature.data(), mHdrSignature.size()); // decrypt extended header - byte_t xci_header_key_index = hdr_ptr->header.key_flag & 7; + byte_t xci_header_key_index = hdr_ptr->header.key_flag & 0xf; if (mKeyCfg.xci_header_key.find(xci_header_key_index) != mKeyCfg.xci_header_key.end()) { pie::hac::GameCardUtil::decryptXciHeader(&hdr_ptr->header, mKeyCfg.xci_header_key[xci_header_key_index].data()); From b0a07c061ab6afc9d66b2bff20343a252d8591e4 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 27 Nov 2022 12:26:44 +0800 Subject: [PATCH 2/2] Fix issue where RomFs with no files could not be processed. --- deps/libpietendo | 2 +- src/RomfsProcess.cpp | 43 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/deps/libpietendo b/deps/libpietendo index 89204ee..994e702 160000 --- a/deps/libpietendo +++ b/deps/libpietendo @@ -1 +1 @@ -Subproject commit 89204ee499bfb3e4d1017c4a1fe2d29b2e70ff37 +Subproject commit 994e70282691fb8cdb9276906500fd873ac51270 diff --git a/src/RomfsProcess.cpp b/src/RomfsProcess.cpp index bd93618..ccc5806 100644 --- a/src/RomfsProcess.cpp +++ b/src/RomfsProcess.cpp @@ -20,6 +20,7 @@ nstool::RomfsProcess::RomfsProcess() : void nstool::RomfsProcess::process() { + // state checks if (mFile == nullptr) { throw tc::Exception(mModuleName, "No file reader set."); @@ -29,8 +30,6 @@ void nstool::RomfsProcess::process() throw tc::NotSupportedException(mModuleName, "Input stream requires read/seek permissions."); } - tc::ByteData scratch; - // read base header to determine complete header size if (mFile->length() < tc::io::IOUtil::castSizeToInt64(sizeof(pie::hac::sRomfsHeader))) { @@ -46,16 +45,42 @@ void nstool::RomfsProcess::process() throw tc::ArgumentOutOfRangeException(mModuleName, "Corrupt RomFs: RomFsHeader is corrupted."); } + /* + fmt::print("RomFsHeader:\n"); + fmt::print(" > header_size = 0x{:04x}\n", mRomfsHeader.header_size.unwrap()); + fmt::print(" > dir_hash_bucket\n"); + fmt::print(" > offset = 0x{:04x}\n", mRomfsHeader.dir_hash_bucket.offset.unwrap()); + fmt::print(" > size = 0x{:04x}\n", mRomfsHeader.dir_hash_bucket.size.unwrap()); + fmt::print(" > dir_entry\n"); + fmt::print(" > offset = 0x{:04x}\n", mRomfsHeader.dir_entry.offset.unwrap()); + fmt::print(" > size = 0x{:04x}\n", mRomfsHeader.dir_entry.size.unwrap()); + fmt::print(" > file_hash_bucket\n"); + fmt::print(" > offset = 0x{:04x}\n", mRomfsHeader.file_hash_bucket.offset.unwrap()) + fmt::print(" > size = 0x{:04x}\n", mRomfsHeader.file_hash_bucket.size.unwrap()); + fmt::print(" > file_entry\n"); + fmt::print(" > offset = 0x{:04x}\n", mRomfsHeader.file_entry.offset.unwrap()); + fmt::print(" > size = 0x{:04x}\n", mRomfsHeader.file_entry.size.unwrap()); + fmt::print(" > data_offset = 0x{:04x}\n", mRomfsHeader.data_offset.unwrap()); + */ + // get dir entry ptr - tc::ByteData dir_entry_table = tc::ByteData(tc::io::IOUtil::castInt64ToSize(mRomfsHeader.dir_entry.size.unwrap())); - mFile->seek(mRomfsHeader.dir_entry.offset.unwrap(), tc::io::SeekOrigin::Begin); - mFile->read(dir_entry_table.data(), dir_entry_table.size()); + tc::ByteData dir_entry_table = tc::ByteData(); + if (mRomfsHeader.dir_entry.size.unwrap() > 0) + { + dir_entry_table = tc::ByteData(tc::io::IOUtil::castInt64ToSize(mRomfsHeader.dir_entry.size.unwrap())); + mFile->seek(mRomfsHeader.dir_entry.offset.unwrap(), tc::io::SeekOrigin::Begin); + mFile->read(dir_entry_table.data(), dir_entry_table.size()); + } // get file entry ptr - tc::ByteData file_entry_table = tc::ByteData(tc::io::IOUtil::castInt64ToSize(mRomfsHeader.file_entry.size.unwrap())); - mFile->seek(mRomfsHeader.file_entry.offset.unwrap(), tc::io::SeekOrigin::Begin); - mFile->read(file_entry_table.data(), file_entry_table.size()); - + tc::ByteData file_entry_table = tc::ByteData(); + if (mRomfsHeader.file_entry.size.unwrap() > 0) + { + file_entry_table = tc::ByteData(tc::io::IOUtil::castInt64ToSize(mRomfsHeader.file_entry.size.unwrap())); + mFile->seek(mRomfsHeader.file_entry.offset.unwrap(), tc::io::SeekOrigin::Begin); + mFile->read(file_entry_table.data(), file_entry_table.size()); + } + // count dir num mDirNum = 0; for (uint32_t v_addr = 0; size_t(v_addr) < dir_entry_table.size();)