2017-03-19 07:00:49 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
class NANDImporter final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NANDImporter();
|
|
|
|
~NANDImporter();
|
|
|
|
|
2017-10-26 19:22:16 +00:00
|
|
|
// Extract a NAND image to the configured NAND root.
|
|
|
|
// If the associated OTP/SEEPROM dump (keys.bin) is not included in the image,
|
|
|
|
// get_otp_dump_path will be called to get a path to it.
|
|
|
|
void ImportNANDBin(const std::string& path_to_bin, std::function<void()> update_callback,
|
|
|
|
std::function<std::string()> get_otp_dump_path);
|
2017-06-19 02:57:30 +00:00
|
|
|
bool ExtractCertificates(const std::string& nand_root);
|
2017-03-19 07:00:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct NANDFSTEntry
|
|
|
|
{
|
2017-10-28 20:40:05 +00:00
|
|
|
char name[12];
|
2017-03-19 07:00:49 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2017-10-26 19:22:16 +00:00
|
|
|
bool ReadNANDBin(const std::string& path_to_bin, std::function<std::string()> get_otp_dump_path);
|
2017-03-19 07:00:49 +00:00
|
|
|
void FindSuperblock();
|
|
|
|
std::string GetPath(const NANDFSTEntry& entry, const std::string& parent_path);
|
2017-05-15 00:47:02 +00:00
|
|
|
std::string FormatDebugString(const NANDFSTEntry& entry);
|
2017-03-19 07:00:49 +00:00
|
|
|
void ProcessEntry(u16 entry_number, const std::string& parent_path);
|
|
|
|
void ProcessFile(const NANDFSTEntry& entry, const std::string& parent_path);
|
|
|
|
void ProcessDirectory(const NANDFSTEntry& entry, const std::string& parent_path);
|
|
|
|
void ExportKeys(const std::string& nand_root);
|
|
|
|
|
|
|
|
std::vector<u8> m_nand;
|
|
|
|
std::vector<u8> m_nand_keys;
|
|
|
|
size_t m_nand_fat_offset = 0;
|
|
|
|
size_t m_nand_fst_offset = 0;
|
2017-05-07 03:26:46 +00:00
|
|
|
std::function<void()> m_update_callback;
|
2017-05-15 00:47:02 +00:00
|
|
|
size_t m_nand_root_length = 0;
|
2017-03-19 07:00:49 +00:00
|
|
|
};
|
|
|
|
}
|