diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp index 85be1630e2..32dafdd58d 100644 --- a/Source/Core/DiscIO/NANDImporter.cpp +++ b/Source/Core/DiscIO/NANDImporter.cpp @@ -7,14 +7,11 @@ #include #include -#include - #include "Common/Crypto/AES.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" -#include "Common/Swap.h" #include "Core/IOS/ES/Formats.h" namespace DiscIO @@ -129,29 +126,22 @@ std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string& return parent_path + '/' + name; } -std::string NANDImporter::FormatDebugString(const NANDFSTEntry& entry) -{ - return fmt::format( - "{:12.12} {:#04x} {:#04x} {:#06x} {:#06x} {:#010x} {:#06x} {:#06x} {:#06x} {:#010x}", - entry.name, entry.mode, entry.attr, entry.sub, entry.sib, entry.size, entry.x1, entry.uid, - entry.gid, entry.x3); -} - void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path) { NANDFSTEntry entry; - memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * Common::swap16(entry_number)], + memcpy(&entry, &m_nand[m_nand_fst_offset + sizeof(NANDFSTEntry) * entry_number], sizeof(NANDFSTEntry)); if (entry.sib != 0xffff) ProcessEntry(entry.sib, parent_path); - if ((entry.mode & 3) == 1) + Type type = static_cast(entry.mode & 3); + if (type == Type::File) ProcessFile(entry, parent_path); - else if ((entry.mode & 3) == 2) + else if (type == Type::Directory) ProcessDirectory(entry, parent_path); else - ERROR_LOG_FMT(DISCIO, "Unknown mode: {}", FormatDebugString(entry)); + ERROR_LOG_FMT(DISCIO, "Ignoring unknown entry type for {}", entry); } void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string& parent_path) @@ -181,8 +171,8 @@ void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& par std::array key{}; std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()], key.begin()); - u16 sub = Common::swap16(entry.sub); - u32 remaining_bytes = Common::swap32(entry.size); + u16 sub = entry.sub; + u32 remaining_bytes = entry.size; while (remaining_bytes > 0) { diff --git a/Source/Core/DiscIO/NANDImporter.h b/Source/Core/DiscIO/NANDImporter.h index e5a36188e3..7c266d6840 100644 --- a/Source/Core/DiscIO/NANDImporter.h +++ b/Source/Core/DiscIO/NANDImporter.h @@ -7,7 +7,10 @@ #include #include +#include + #include "Common/CommonTypes.h" +#include "Common/Swap.h" namespace DiscIO { @@ -24,23 +27,29 @@ public: std::function get_otp_dump_path); bool ExtractCertificates(); -private: + enum class Type + { + File = 1, + Directory = 2, + }; + #pragma pack(push, 1) struct NANDFSTEntry { char name[12]; - u8 mode; // 0x0C - u8 attr; // 0x0D - u16 sub; // 0x0E - u16 sib; // 0x10 - u32 size; // 0x12 - u16 x1; // 0x16 - u16 uid; // 0x18 - u16 gid; // 0x1A - u32 x3; // 0x1C + u8 mode; + u8 attr; + Common::BigEndianValue sub; + Common::BigEndianValue sib; + Common::BigEndianValue size; + Common::BigEndianValue uid; + Common::BigEndianValue gid; + Common::BigEndianValue x3; }; + static_assert(sizeof(NANDFSTEntry) == 0x20, "Wrong size"); #pragma pack(pop) +private: bool ReadNANDBin(const std::string& path_to_bin, std::function get_otp_dump_path); void FindSuperblock(); std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path); @@ -58,3 +67,17 @@ private: std::function m_update_callback; }; } // namespace DiscIO + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + template + auto format(const DiscIO::NANDImporter::NANDFSTEntry& entry, FormatContext& ctx) const + { + return fmt::format_to( + ctx.out(), "{:12.12} {:#010b} {:#04x} {:#06x} {:#06x} {:#010x} {:#010x} {:#06x} {:#010x}", + entry.name, entry.mode, entry.attr, entry.sub, entry.sib, entry.size, entry.uid, entry.gid, + entry.x3); + } +};