diff options
| author | Starsam80 <samraskauskas@gmail.com> | 2021-12-29 18:28:54 -0700 |
|---|---|---|
| committer | Starsam80 <samraskauskas@gmail.com> | 2022-03-01 19:24:59 -0700 |
| commit | 73151a57536d7ce7e0b11904b7ab5467cd1fe466 (patch) | |
| tree | b043ecea9f65fd9f65cc6f8219a995dbf4f499b8 /Source/Core/DiscIO/NANDImporter.cpp | |
| parent | 6758c77c39b094555ab2797b0419217de40e202e (diff) | |
NANDImporter: Don't pass paths if we don't need to
Diffstat (limited to 'Source/Core/DiscIO/NANDImporter.cpp')
| -rw-r--r-- | Source/Core/DiscIO/NANDImporter.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp index 322dd548d7..1691ed5410 100644 --- a/Source/Core/DiscIO/NANDImporter.cpp +++ b/Source/Core/DiscIO/NANDImporter.cpp @@ -140,44 +140,53 @@ void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path Type type = static_cast<Type>(entry.mode & 3); if (type == Type::File) - ProcessFile(entry, path); + { + std::vector<u8> data = GetEntryData(entry); + File::IOFile file(m_nand_root + path, "wb"); + file.WriteBytes(data.data(), data.size()); + } else if (type == Type::Directory) - ProcessDirectory(entry, path); + { + File::CreateDir(m_nand_root + path); + ProcessEntry(entry.sub, path); + } else + { ERROR_LOG_FMT(DISCIO, "Ignoring unknown entry type for {}", entry); + } entry_number = entry.sib; } } -void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string& path) -{ - File::CreateDir(m_nand_root + path); - ProcessEntry(entry.sub, path); -} - -void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& path) +std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry) { constexpr size_t NAND_AES_KEY_OFFSET = 0x158; constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000; - File::IOFile file(m_nand_root + path, "wb"); std::array<u8, 16> key{}; std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()], key.begin()); + u16 sub = entry.sub; - u32 remaining_bytes = entry.size; + size_t remaining_bytes = entry.size; + std::vector<u8> data{}; + data.reserve(remaining_bytes); while (remaining_bytes > 0) { std::array<u8, 16> iv{}; std::vector<u8> block = Common::AES::Decrypt( key.data(), iv.data(), &m_nand[NAND_FAT_BLOCK_SIZE * sub], NAND_FAT_BLOCK_SIZE); - u32 size = remaining_bytes < NAND_FAT_BLOCK_SIZE ? remaining_bytes : NAND_FAT_BLOCK_SIZE; - file.WriteBytes(block.data(), size); + + size_t size = std::min(remaining_bytes, block.size()); + data.insert(data.end(), block.begin(), block.begin() + size); remaining_bytes -= size; + sub = Common::swap16(&m_nand[m_nand_fat_offset + 2 * sub]); } + + return data; } bool NANDImporter::ExtractCertificates() |
