2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-08-16 23:02:31 +02:00
|
|
|
|
|
|
|
#include "core/file_sys/content_archive.h"
|
|
|
|
#include "core/file_sys/romfs.h"
|
2018-08-19 03:16:20 +02:00
|
|
|
#include "core/file_sys/xts_archive.h"
|
2021-04-24 07:04:28 +02:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2018-08-16 23:02:31 +02:00
|
|
|
#include "core/loader/nax.h"
|
2018-08-19 03:16:20 +02:00
|
|
|
#include "core/loader/nca.h"
|
2018-08-16 23:02:31 +02:00
|
|
|
|
|
|
|
namespace Loader {
|
2018-09-19 20:13:00 +02:00
|
|
|
namespace {
|
|
|
|
FileType IdentifyTypeImpl(const FileSys::NAX& nax) {
|
2018-09-19 19:54:43 +02:00
|
|
|
if (nax.GetStatus() != ResultStatus::Success) {
|
|
|
|
return FileType::Error;
|
2018-08-16 23:02:31 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 19:54:43 +02:00
|
|
|
const auto nca = nax.AsNCA();
|
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
|
|
|
return FileType::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileType::NAX;
|
2018-08-16 23:02:31 +02:00
|
|
|
}
|
2018-09-19 20:13:00 +02:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2021-04-27 18:05:34 +02:00
|
|
|
AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file_)
|
|
|
|
: AppLoader(file_), nax(std::make_unique<FileSys::NAX>(file_)),
|
2018-09-19 20:13:00 +02:00
|
|
|
nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {}
|
|
|
|
|
|
|
|
AppLoader_NAX::~AppLoader_NAX() = default;
|
|
|
|
|
2021-04-27 18:05:34 +02:00
|
|
|
FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& nax_file) {
|
|
|
|
const FileSys::NAX nax(nax_file);
|
2018-09-19 20:13:00 +02:00
|
|
|
return IdentifyTypeImpl(nax);
|
|
|
|
}
|
|
|
|
|
2018-12-05 23:42:41 +01:00
|
|
|
FileType AppLoader_NAX::GetFileType() const {
|
2018-09-19 20:13:00 +02:00
|
|
|
return IdentifyTypeImpl(*nax);
|
|
|
|
}
|
2018-08-16 23:02:31 +02:00
|
|
|
|
2021-04-24 07:04:28 +02:00
|
|
|
AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::KProcess& process, Core::System& system) {
|
2018-08-16 23:02:31 +02:00
|
|
|
if (is_loaded) {
|
2019-04-09 23:03:04 +02:00
|
|
|
return {ResultStatus::ErrorAlreadyLoaded, {}};
|
2018-08-16 23:02:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:03:04 +02:00
|
|
|
const auto nax_status = nax->GetStatus();
|
|
|
|
if (nax_status != ResultStatus::Success) {
|
|
|
|
return {nax_status, {}};
|
|
|
|
}
|
2018-08-16 23:02:31 +02:00
|
|
|
|
|
|
|
const auto nca = nax->AsNCA();
|
|
|
|
if (nca == nullptr) {
|
2019-04-09 23:03:04 +02:00
|
|
|
if (!Core::Crypto::KeyManager::KeyFileExists(false)) {
|
|
|
|
return {ResultStatus::ErrorMissingProductionKeyFile, {}};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {ResultStatus::ErrorNAXInconvertibleToNCA, {}};
|
2018-08-16 23:02:31 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:03:04 +02:00
|
|
|
const auto nca_status = nca->GetStatus();
|
|
|
|
if (nca_status != ResultStatus::Success) {
|
|
|
|
return {nca_status, {}};
|
|
|
|
}
|
2018-08-16 23:02:31 +02:00
|
|
|
|
2020-09-16 14:19:25 +02:00
|
|
|
const auto result = nca_loader->Load(process, system);
|
2019-04-09 23:03:04 +02:00
|
|
|
if (result.first != ResultStatus::Success) {
|
2018-08-16 23:02:31 +02:00
|
|
|
return result;
|
2019-04-09 23:03:04 +02:00
|
|
|
}
|
2018-08-16 23:02:31 +02:00
|
|
|
|
|
|
|
is_loaded = true;
|
2019-04-09 23:03:04 +02:00
|
|
|
return result;
|
2018-08-16 23:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) {
|
|
|
|
return nca_loader->ReadRomFS(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) {
|
|
|
|
return nca_loader->ReadProgramId(out_program_id);
|
|
|
|
}
|
2019-01-15 21:56:52 +01:00
|
|
|
|
|
|
|
ResultStatus AppLoader_NAX::ReadBanner(std::vector<u8>& buffer) {
|
|
|
|
return nca_loader->ReadBanner(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NAX::ReadLogo(std::vector<u8>& buffer) {
|
|
|
|
return nca_loader->ReadLogo(buffer);
|
|
|
|
}
|
|
|
|
|
2019-05-26 17:40:41 +02:00
|
|
|
ResultStatus AppLoader_NAX::ReadNSOModules(Modules& modules) {
|
|
|
|
return nca_loader->ReadNSOModules(modules);
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:02:31 +02:00
|
|
|
} // namespace Loader
|