summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorStarsam80 <samraskauskas@gmail.com>2021-12-29 15:19:21 -0700
committerStarsam80 <samraskauskas@gmail.com>2022-03-01 15:07:59 -0700
commit643057fea2c7818318fdc42e54a01583374db30c (patch)
treef17dc2634fff86f573e746bb4812e5bd0b1389c5 /Source/Core/DiscIO
parentea116fbbdf4ab1bf6e0ac22815646ba1767ac538 (diff)
NANDImporter: Make a class variable for the NAND root
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/NANDImporter.cpp30
-rw-r--r--Source/Core/DiscIO/NANDImporter.h6
2 files changed, 17 insertions, 19 deletions
diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp
index ccd1525b62..85be1630e2 100644
--- a/Source/Core/DiscIO/NANDImporter.cpp
+++ b/Source/Core/DiscIO/NANDImporter.cpp
@@ -22,7 +22,9 @@ namespace DiscIO
constexpr size_t NAND_SIZE = 0x20000000;
constexpr size_t NAND_KEYS_SIZE = 0x400;
-NANDImporter::NANDImporter() = default;
+NANDImporter::NANDImporter() : m_nand_root(File::GetUserPath(D_WIIROOT_IDX))
+{
+}
NANDImporter::~NANDImporter() = default;
void NANDImporter::ImportNANDBin(const std::string& path_to_bin,
@@ -34,14 +36,10 @@ void NANDImporter::ImportNANDBin(const std::string& path_to_bin,
if (!ReadNANDBin(path_to_bin, get_otp_dump_path))
return;
- std::string nand_root = File::GetUserPath(D_WIIROOT_IDX);
- nand_root.pop_back(); // remove trailing path separator
- m_nand_root_length = nand_root.length();
-
FindSuperblock();
- ProcessEntry(0, nand_root);
- ExportKeys(nand_root);
- ExtractCertificates(nand_root);
+ ProcessEntry(0, "");
+ ExportKeys();
+ ExtractCertificates();
}
bool NANDImporter::ReadNANDBin(const std::string& path_to_bin,
@@ -162,12 +160,12 @@ void NANDImporter::ProcessDirectory(const NANDFSTEntry& entry, const std::string
INFO_LOG_FMT(DISCIO, "Path: {}", FormatDebugString(entry));
const std::string path = GetPath(entry, parent_path);
- File::CreateDir(path);
+ File::CreateDir(m_nand_root + path);
if (entry.sub != 0xffff)
ProcessEntry(entry.sub, path);
- INFO_LOG_FMT(DISCIO, "Path: {}", parent_path.data() + m_nand_root_length);
+ INFO_LOG_FMT(DISCIO, "Path: {}", parent_path);
}
void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& parent_path)
@@ -179,7 +177,7 @@ void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& par
INFO_LOG_FMT(DISCIO, "File: {}", FormatDebugString(entry));
const std::string path = GetPath(entry, parent_path);
- File::IOFile file(path, "wb");
+ File::IOFile file(m_nand_root + path, "wb");
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());
@@ -198,9 +196,9 @@ void NANDImporter::ProcessFile(const NANDFSTEntry& entry, const std::string& par
}
}
-bool NANDImporter::ExtractCertificates(const std::string& nand_root)
+bool NANDImporter::ExtractCertificates()
{
- const std::string content_dir = nand_root + "/title/00000001/0000000d/content/";
+ const std::string content_dir = m_nand_root + "/title/00000001/0000000d/content/";
File::IOFile tmd_file(content_dir + "title.tmd", "rb");
std::vector<u8> tmd_bytes(tmd_file.GetSize());
@@ -251,7 +249,7 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
return false;
}
- const std::string pem_file_path = nand_root + std::string(certificate.filename);
+ const std::string pem_file_path = m_nand_root + std::string(certificate.filename);
const ptrdiff_t certificate_offset = std::distance(content_bytes.begin(), search_result);
const u16 certificate_size = Common::swap16(&content_bytes[certificate_offset - 2]);
INFO_LOG_FMT(DISCIO, "ExtractCertificates: '{}' offset: {:#x} size: {:#x}",
@@ -267,9 +265,9 @@ bool NANDImporter::ExtractCertificates(const std::string& nand_root)
return true;
}
-void NANDImporter::ExportKeys(const std::string& nand_root)
+void NANDImporter::ExportKeys()
{
- const std::string file_path = nand_root + "/keys.bin";
+ const std::string file_path = m_nand_root + "/keys.bin";
File::IOFile file(file_path, "wb");
if (!file.WriteBytes(m_nand_keys.data(), NAND_KEYS_SIZE))
PanicAlertFmtT("Unable to write to file {0}", file_path);
diff --git a/Source/Core/DiscIO/NANDImporter.h b/Source/Core/DiscIO/NANDImporter.h
index f60a5b06f8..e5a36188e3 100644
--- a/Source/Core/DiscIO/NANDImporter.h
+++ b/Source/Core/DiscIO/NANDImporter.h
@@ -22,7 +22,7 @@ public:
// 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);
- bool ExtractCertificates(const std::string& nand_root);
+ bool ExtractCertificates();
private:
#pragma pack(push, 1)
@@ -48,13 +48,13 @@ private:
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);
+ void ExportKeys();
+ std::string m_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;
std::function<void()> m_update_callback;
- size_t m_nand_root_length = 0;
};
} // namespace DiscIO