mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-15 16:59:18 +01:00
NANDImporter: Only read the AES key once
There is no need to constantly reset the key for every file entry.
This commit is contained in:
parent
80012ae253
commit
41a3368889
@ -4,7 +4,6 @@
|
|||||||
#include "DiscIO/NANDImporter.h"
|
#include "DiscIO/NANDImporter.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "Common/Crypto/AES.h"
|
#include "Common/Crypto/AES.h"
|
||||||
@ -35,8 +34,8 @@ void NANDImporter::ImportNANDBin(const std::string& path_to_bin,
|
|||||||
if (!FindSuperblock())
|
if (!FindSuperblock())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProcessEntry(0, "");
|
|
||||||
ExportKeys();
|
ExportKeys();
|
||||||
|
ProcessEntry(0, "");
|
||||||
ExtractCertificates();
|
ExtractCertificates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,13 +164,8 @@ void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path
|
|||||||
|
|
||||||
std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry)
|
std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry)
|
||||||
{
|
{
|
||||||
constexpr size_t NAND_AES_KEY_OFFSET = 0x158;
|
|
||||||
constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000;
|
constexpr size_t NAND_FAT_BLOCK_SIZE = 0x4000;
|
||||||
|
|
||||||
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 = entry.sub;
|
u16 sub = entry.sub;
|
||||||
size_t remaining_bytes = entry.size;
|
size_t remaining_bytes = entry.size;
|
||||||
std::vector<u8> data{};
|
std::vector<u8> data{};
|
||||||
@ -181,7 +175,7 @@ std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry)
|
|||||||
{
|
{
|
||||||
std::array<u8, 16> iv{};
|
std::array<u8, 16> iv{};
|
||||||
std::vector<u8> block = Common::AES::Decrypt(
|
std::vector<u8> block = Common::AES::Decrypt(
|
||||||
key.data(), iv.data(), &m_nand[NAND_FAT_BLOCK_SIZE * sub], NAND_FAT_BLOCK_SIZE);
|
m_aes_key.data(), iv.data(), &m_nand[NAND_FAT_BLOCK_SIZE * sub], NAND_FAT_BLOCK_SIZE);
|
||||||
|
|
||||||
size_t size = std::min(remaining_bytes, block.size());
|
size_t size = std::min(remaining_bytes, block.size());
|
||||||
data.insert(data.end(), block.begin(), block.begin() + size);
|
data.insert(data.end(), block.begin(), block.begin() + size);
|
||||||
@ -264,6 +258,10 @@ bool NANDImporter::ExtractCertificates()
|
|||||||
|
|
||||||
void NANDImporter::ExportKeys()
|
void NANDImporter::ExportKeys()
|
||||||
{
|
{
|
||||||
|
constexpr size_t NAND_AES_KEY_OFFSET = 0x158;
|
||||||
|
|
||||||
|
std::copy_n(&m_nand_keys[NAND_AES_KEY_OFFSET], m_aes_key.size(), m_aes_key.begin());
|
||||||
|
|
||||||
const std::string file_path = m_nand_root + "/keys.bin";
|
const std::string file_path = m_nand_root + "/keys.bin";
|
||||||
File::IOFile file(file_path, "wb");
|
File::IOFile file(file_path, "wb");
|
||||||
if (!file.WriteBytes(m_nand_keys.data(), NAND_KEYS_SIZE))
|
if (!file.WriteBytes(m_nand_keys.data(), NAND_KEYS_SIZE))
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -73,6 +74,7 @@ private:
|
|||||||
std::string m_nand_root;
|
std::string m_nand_root;
|
||||||
std::vector<u8> m_nand;
|
std::vector<u8> m_nand;
|
||||||
std::vector<u8> m_nand_keys;
|
std::vector<u8> m_nand_keys;
|
||||||
|
std::array<u8, 16> m_aes_key;
|
||||||
std::unique_ptr<NANDSuperblock> m_superblock;
|
std::unique_ptr<NANDSuperblock> m_superblock;
|
||||||
std::function<void()> m_update_callback;
|
std::function<void()> m_update_callback;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user