mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-23 05:55:40 +01:00
Merge pull request #1361 from lioncash/nax
xts_archive/nax: Minor interface changes
This commit is contained in:
commit
b02a1e38fa
@ -30,9 +30,6 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t
|
|||||||
mbedtls_md_context_t context;
|
mbedtls_md_context_t context;
|
||||||
mbedtls_md_init(&context);
|
mbedtls_md_init(&context);
|
||||||
|
|
||||||
const auto key_f = reinterpret_cast<const u8*>(key);
|
|
||||||
const std::vector<u8> key_v(key_f, key_f + key_length);
|
|
||||||
|
|
||||||
if (mbedtls_md_setup(&context, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1) ||
|
if (mbedtls_md_setup(&context, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1) ||
|
||||||
mbedtls_md_hmac_starts(&context, reinterpret_cast<const u8*>(key), key_length) ||
|
mbedtls_md_hmac_starts(&context, reinterpret_cast<const u8*>(key), key_length) ||
|
||||||
mbedtls_md_hmac_update(&context, reinterpret_cast<const u8*>(data), data_length) ||
|
mbedtls_md_hmac_update(&context, reinterpret_cast<const u8*>(data), data_length) ||
|
||||||
@ -45,7 +42,7 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NAXHeader>()) {
|
NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) {
|
||||||
std::string path = FileUtil::SanitizePath(file->GetFullPath());
|
std::string path = FileUtil::SanitizePath(file->GetFullPath());
|
||||||
static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca",
|
static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca",
|
||||||
std::regex_constants::ECMAScript |
|
std::regex_constants::ECMAScript |
|
||||||
@ -65,7 +62,7 @@ NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NA
|
|||||||
}
|
}
|
||||||
|
|
||||||
NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id)
|
NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id)
|
||||||
: file(std::move(file_)), header(std::make_unique<NAXHeader>()) {
|
: header(std::make_unique<NAXHeader>()), file(std::move(file_)) {
|
||||||
Core::Crypto::SHA256Hash hash{};
|
Core::Crypto::SHA256Hash hash{};
|
||||||
mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0);
|
mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0);
|
||||||
status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0],
|
status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0],
|
||||||
@ -138,9 +135,9 @@ VirtualFile NAX::GetDecrypted() const {
|
|||||||
return dec_file;
|
return dec_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<NCA> NAX::AsNCA() const {
|
std::unique_ptr<NCA> NAX::AsNCA() const {
|
||||||
if (type == NAXContentType::NCA)
|
if (type == NAXContentType::NCA)
|
||||||
return std::make_shared<NCA>(GetDecrypted());
|
return std::make_unique<NCA>(GetDecrypted());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
VirtualFile GetDecrypted() const;
|
VirtualFile GetDecrypted() const;
|
||||||
|
|
||||||
std::shared_ptr<NCA> AsNCA() const;
|
std::unique_ptr<NCA> AsNCA() const;
|
||||||
|
|
||||||
NAXContentType GetContentType() const;
|
NAXContentType GetContentType() const;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
|
|
||||||
VirtualFile file;
|
VirtualFile file;
|
||||||
Loader::ResultStatus status;
|
Loader::ResultStatus status;
|
||||||
NAXContentType type;
|
NAXContentType type{};
|
||||||
|
|
||||||
VirtualFile dec_file;
|
VirtualFile dec_file;
|
||||||
|
|
||||||
|
@ -11,6 +11,20 @@
|
|||||||
#include "core/loader/nca.h"
|
#include "core/loader/nca.h"
|
||||||
|
|
||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
namespace {
|
||||||
|
FileType IdentifyTypeImpl(const FileSys::NAX& nax) {
|
||||||
|
if (nax.GetStatus() != ResultStatus::Success) {
|
||||||
|
return FileType::Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto nca = nax.AsNCA();
|
||||||
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
||||||
|
return FileType::Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FileType::NAX;
|
||||||
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)
|
AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)
|
||||||
: AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)),
|
: AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)),
|
||||||
@ -19,14 +33,12 @@ AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)
|
|||||||
AppLoader_NAX::~AppLoader_NAX() = default;
|
AppLoader_NAX::~AppLoader_NAX() = default;
|
||||||
|
|
||||||
FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
|
FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
|
||||||
FileSys::NAX nax(file);
|
const FileSys::NAX nax(file);
|
||||||
|
return IdentifyTypeImpl(nax);
|
||||||
|
}
|
||||||
|
|
||||||
if (nax.GetStatus() == ResultStatus::Success && nax.AsNCA() != nullptr &&
|
FileType AppLoader_NAX::GetFileType() {
|
||||||
nax.AsNCA()->GetStatus() == ResultStatus::Success) {
|
return IdentifyTypeImpl(*nax);
|
||||||
return FileType::NAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FileType::Error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
||||||
|
@ -31,9 +31,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
static FileType IdentifyType(const FileSys::VirtualFile& file);
|
static FileType IdentifyType(const FileSys::VirtualFile& file);
|
||||||
|
|
||||||
FileType GetFileType() override {
|
FileType GetFileType() override;
|
||||||
return IdentifyType(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user