2018-08-16 21:02:31 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/file_sys/content_archive.h"
|
|
|
|
#include "core/file_sys/romfs.h"
|
2018-08-19 01:16:20 +00:00
|
|
|
#include "core/file_sys/xts_archive.h"
|
2018-08-16 21:02:31 +00:00
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
#include "core/loader/nax.h"
|
2018-08-19 01:16:20 +00:00
|
|
|
#include "core/loader/nca.h"
|
2018-08-16 21:02:31 +00:00
|
|
|
|
|
|
|
namespace Loader {
|
2018-09-19 18:13:00 +00:00
|
|
|
namespace {
|
|
|
|
FileType IdentifyTypeImpl(const FileSys::NAX& nax) {
|
2018-09-19 17:54:43 +00:00
|
|
|
if (nax.GetStatus() != ResultStatus::Success) {
|
|
|
|
return FileType::Error;
|
2018-08-16 21:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 17:54:43 +00:00
|
|
|
const auto nca = nax.AsNCA();
|
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) {
|
|
|
|
return FileType::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileType::NAX;
|
2018-08-16 21:02:31 +00:00
|
|
|
}
|
2018-09-19 18:13:00 +00:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
|
|
|
AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)
|
|
|
|
: AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)),
|
|
|
|
nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {}
|
|
|
|
|
|
|
|
AppLoader_NAX::~AppLoader_NAX() = default;
|
|
|
|
|
|
|
|
FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
|
|
|
|
const FileSys::NAX nax(file);
|
|
|
|
return IdentifyTypeImpl(nax);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileType AppLoader_NAX::GetFileType() {
|
|
|
|
return IdentifyTypeImpl(*nax);
|
|
|
|
}
|
2018-08-16 21:02:31 +00:00
|
|
|
|
2018-09-29 19:57:40 +00:00
|
|
|
ResultStatus AppLoader_NAX::Load(Kernel::Process& process) {
|
2018-08-16 21:02:31 +00:00
|
|
|
if (is_loaded) {
|
|
|
|
return ResultStatus::ErrorAlreadyLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nax->GetStatus() != ResultStatus::Success)
|
|
|
|
return nax->GetStatus();
|
|
|
|
|
|
|
|
const auto nca = nax->AsNCA();
|
|
|
|
if (nca == nullptr) {
|
|
|
|
if (!Core::Crypto::KeyManager::KeyFileExists(false))
|
|
|
|
return ResultStatus::ErrorMissingProductionKeyFile;
|
|
|
|
return ResultStatus::ErrorNAXInconvertibleToNCA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nca->GetStatus() != ResultStatus::Success)
|
|
|
|
return nca->GetStatus();
|
|
|
|
|
|
|
|
const auto result = nca_loader->Load(process);
|
|
|
|
if (result != ResultStatus::Success)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
is_loaded = true;
|
|
|
|
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} // namespace Loader
|