mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-03 04:01:17 +02: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 <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "Common/Crypto/AES.h"
|
#include "Common/Crypto/AES.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/IOFile.h"
|
#include "Common/IOFile.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/Swap.h"
|
|
||||||
#include "Core/IOS/ES/Formats.h"
|
#include "Core/IOS/ES/Formats.h"
|
||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
@ -129,29 +126,22 @@ std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string&
|
|||||||
return parent_path + '/' + name;
|
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)
|
void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path)
|
||||||
{
|
{
|
||||||
NANDFSTEntry entry;
|
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));
|
sizeof(NANDFSTEntry));
|
||||||
|
|
||||||
if (entry.sib != 0xffff)
|
if (entry.sib != 0xffff)
|
||||||
ProcessEntry(entry.sib, parent_path);
|
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);
|
ProcessFile(entry, parent_path);
|
||||||
else if ((entry.mode & 3) == 2)
|
else if (type == Type::Directory)
|
||||||
ProcessDirectory(entry, parent_path);
|
ProcessDirectory(entry, parent_path);
|
||||||
else
|
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)
|
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::array<u8, 16> key{};
|
||||||
std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()],
|
std::copy(&m_nand_keys[NAND_AES_KEY_OFFSET], &m_nand_keys[NAND_AES_KEY_OFFSET + key.size()],
|
||||||
key.begin());
|
key.begin());
|
||||||
u16 sub = Common::swap16(entry.sub);
|
u16 sub = entry.sub;
|
||||||
u32 remaining_bytes = Common::swap32(entry.size);
|
u32 remaining_bytes = entry.size;
|
||||||
|
|
||||||
while (remaining_bytes > 0)
|
while (remaining_bytes > 0)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/Swap.h"
|
||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
@ -24,23 +27,29 @@ public:
|
|||||||
std::function<std::string()> get_otp_dump_path);
|
std::function<std::string()> get_otp_dump_path);
|
||||||
bool ExtractCertificates();
|
bool ExtractCertificates();
|
||||||
|
|
||||||
private:
|
enum class Type
|
||||||
|
{
|
||||||
|
File = 1,
|
||||||
|
Directory = 2,
|
||||||
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct NANDFSTEntry
|
struct NANDFSTEntry
|
||||||
{
|
{
|
||||||
char name[12];
|
char name[12];
|
||||||
u8 mode; // 0x0C
|
u8 mode;
|
||||||
u8 attr; // 0x0D
|
u8 attr;
|
||||||
u16 sub; // 0x0E
|
Common::BigEndianValue<u16> sub;
|
||||||
u16 sib; // 0x10
|
Common::BigEndianValue<u16> sib;
|
||||||
u32 size; // 0x12
|
Common::BigEndianValue<u32> size;
|
||||||
u16 x1; // 0x16
|
Common::BigEndianValue<u32> uid;
|
||||||
u16 uid; // 0x18
|
Common::BigEndianValue<u16> gid;
|
||||||
u16 gid; // 0x1A
|
Common::BigEndianValue<u32> x3;
|
||||||
u32 x3; // 0x1C
|
|
||||||
};
|
};
|
||||||
|
static_assert(sizeof(NANDFSTEntry) == 0x20, "Wrong size");
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
private:
|
||||||
bool ReadNANDBin(const std::string& path_to_bin, std::function<std::string()> get_otp_dump_path);
|
bool ReadNANDBin(const std::string& path_to_bin, std::function<std::string()> get_otp_dump_path);
|
||||||
void FindSuperblock();
|
void FindSuperblock();
|
||||||
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
|
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
|
||||||
@ -58,3 +67,17 @@ private:
|
|||||||
std::function<void()> m_update_callback;
|
std::function<void()> m_update_callback;
|
||||||
};
|
};
|
||||||
} // namespace DiscIO
|
} // 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