mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 06:39:14 +01:00
NANDImporter: Improve NANDFSTEntry
`uid` is a u32, not a u16. Also, everything is big endian, so we can simplify the code a little bit.
This commit is contained in:
parent
643057fea2
commit
2ccd974471
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user