summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorStarsam80 <samraskauskas@gmail.com>2021-12-29 16:26:46 -0700
committerStarsam80 <samraskauskas@gmail.com>2022-03-01 19:24:59 -0700
commit2ccd9744719a03bd37b47ebbfde7d67d89491749 (patch)
treed1dfbb2ecf8e981c406f4b156968e58b72d3435f /Source/Core/DiscIO
parent643057fea2c7818318fdc42e54a01583374db30c (diff)
NANDImporter: Improve NANDFSTEntry
`uid` is a u32, not a u16. Also, everything is big endian, so we can simplify the code a little bit.
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/NANDImporter.cpp24
-rw-r--r--Source/Core/DiscIO/NANDImporter.h43
2 files changed, 40 insertions, 27 deletions
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 <array>
#include <cstring>
-#include <fmt/format.h>
-
#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<Type>(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<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 = 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 <string>
#include <vector>
+#include <fmt/format.h>
+
#include "Common/CommonTypes.h"
+#include "Common/Swap.h"
namespace DiscIO
{
@@ -24,23 +27,29 @@ public:
std::function<std::string()> 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<u16> sub;
+ Common::BigEndianValue<u16> sib;
+ Common::BigEndianValue<u32> size;
+ Common::BigEndianValue<u32> uid;
+ Common::BigEndianValue<u16> gid;
+ Common::BigEndianValue<u32> x3;
};
+ static_assert(sizeof(NANDFSTEntry) == 0x20, "Wrong size");
#pragma pack(pop)
+private:
bool ReadNANDBin(const std::string& path_to_bin, std::function<std::string()> get_otp_dump_path);
void FindSuperblock();
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
@@ -58,3 +67,17 @@ private:
std::function<void()> m_update_callback;
};
} // namespace DiscIO
+
+template <>
+struct fmt::formatter<DiscIO::NANDImporter::NANDFSTEntry>
+{
+ constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+ template <typename FormatContext>
+ 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);
+ }
+};