From 5670cb7e16d154bfeb6c81cf5fda4ee1be60008c Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 3 Oct 2021 10:56:55 +0800 Subject: [PATCH] Fix bug in detecting corrupt RomFs. --- deps/libnintendo-hac | 2 +- src/RomfsProcess.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/deps/libnintendo-hac b/deps/libnintendo-hac index a4bef5a..02a5acb 160000 --- a/deps/libnintendo-hac +++ b/deps/libnintendo-hac @@ -1 +1 @@ -Subproject commit a4bef5a52859625027f75b71d802b1a53af18534 +Subproject commit 02a5acb78bfa55edfeebcc42b4591b3d43424575 diff --git a/src/RomfsProcess.cpp b/src/RomfsProcess.cpp index e1e24c1..8e61bc5 100644 --- a/src/RomfsProcess.cpp +++ b/src/RomfsProcess.cpp @@ -83,10 +83,10 @@ void nstool::RomfsProcess::importHeader() mFile->seek(0, tc::io::SeekOrigin::Begin); mFile->read((byte_t*)&mRomfsHeader, sizeof(mRomfsHeader)); if (mRomfsHeader.header_size.unwrap() != sizeof(nn::hac::sRomfsHeader) || - mRomfsHeader.dir_hash_bucket.offset.unwrap() != sizeof(nn::hac::sRomfsHeader) || + mRomfsHeader.dir_entry.offset.unwrap() != (mRomfsHeader.dir_hash_bucket.offset.unwrap() + mRomfsHeader.dir_hash_bucket.size.unwrap()) || mRomfsHeader.data_offset.unwrap() != align(mRomfsHeader.header_size.unwrap(), nn::hac::romfs::kRomfsHeaderAlign)) { - throw tc::ArgumentOutOfRangeException("nn::hac::RomFsMetaGenerator", "Corrupt RomFs: RomFsHeader is corrupted."); + throw tc::ArgumentOutOfRangeException(mModuleName, "Corrupt RomFs: RomFsHeader is corrupted."); } // get dir entry ptr @@ -105,7 +105,11 @@ void nstool::RomfsProcess::importHeader() { uint32_t total_size = sizeof(nn::hac::sRomfsDirEntry) + align(((nn::hac::sRomfsDirEntry*)(dir_entry_table.data() + v_addr))->name_size.unwrap(), 4); - mDirNum += 1; + // don't count root directory + if (v_addr != 0) + { + mDirNum += 1; + } v_addr += total_size; }