2018-06-21 08:16:23 -07:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-19 21:10:21 -07:00
|
|
|
#include <utility>
|
2018-06-21 08:16:23 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-07-12 20:22:59 -07:00
|
|
|
#include "common/string_util.h"
|
2018-07-07 20:24:51 -07:00
|
|
|
#include "common/swap.h"
|
2018-06-21 08:16:23 -07:00
|
|
|
#include "core/core.h"
|
2018-07-18 18:07:11 -07:00
|
|
|
#include "core/file_sys/content_archive.h"
|
2018-06-21 08:16:23 -07:00
|
|
|
#include "core/file_sys/program_metadata.h"
|
2018-07-12 20:22:59 -07:00
|
|
|
#include "core/gdbstub/gdbstub.h"
|
2018-06-21 08:16:23 -07:00
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
#include "core/hle/kernel/resource_limit.h"
|
|
|
|
#include "core/hle/service/filesystem/filesystem.h"
|
|
|
|
#include "core/loader/nca.h"
|
|
|
|
#include "core/loader/nso.h"
|
|
|
|
#include "core/memory.h"
|
|
|
|
|
|
|
|
namespace Loader {
|
|
|
|
|
2018-08-05 15:27:05 -07:00
|
|
|
AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_)
|
|
|
|
: AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {}
|
2018-06-21 08:16:23 -07:00
|
|
|
|
2018-07-18 18:07:11 -07:00
|
|
|
FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) {
|
2018-07-27 20:55:23 -07:00
|
|
|
FileSys::NCA nca(file);
|
2018-07-07 20:24:51 -07:00
|
|
|
|
2018-07-27 20:55:23 -07:00
|
|
|
if (nca.GetStatus() == ResultStatus::Success &&
|
|
|
|
nca.GetType() == FileSys::NCAContentType::Program)
|
2018-06-21 08:16:23 -07:00
|
|
|
return FileType::NCA;
|
|
|
|
|
|
|
|
return FileType::Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
|
|
|
if (is_loaded) {
|
|
|
|
return ResultStatus::ErrorAlreadyLoaded;
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:27:05 -07:00
|
|
|
const auto result = nca->GetStatus();
|
2018-06-21 08:16:23 -07:00
|
|
|
if (result != ResultStatus::Success) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-07-18 18:07:11 -07:00
|
|
|
if (nca->GetType() != FileSys::NCAContentType::Program)
|
|
|
|
return ResultStatus::ErrorInvalidFormat;
|
|
|
|
|
2018-08-05 15:27:05 -07:00
|
|
|
const auto exefs = nca->GetExeFS();
|
2018-07-18 18:07:11 -07:00
|
|
|
|
|
|
|
if (exefs == nullptr)
|
|
|
|
return ResultStatus::ErrorInvalidFormat;
|
|
|
|
|
2018-08-05 15:27:05 -07:00
|
|
|
directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs);
|
2018-06-21 08:16:23 -07:00
|
|
|
|
2018-08-05 15:27:05 -07:00
|
|
|
const auto load_result = directory_loader->Load(process);
|
|
|
|
if (load_result != ResultStatus::Success)
|
|
|
|
return load_result;
|
2018-06-21 08:16:23 -07:00
|
|
|
|
2018-07-18 18:07:11 -07:00
|
|
|
if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0)
|
2018-07-17 12:42:15 -07:00
|
|
|
Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this));
|
2018-07-07 20:24:51 -07:00
|
|
|
|
2018-06-21 08:16:23 -07:00
|
|
|
is_loaded = true;
|
2018-07-18 18:07:11 -07:00
|
|
|
|
2018-07-07 20:24:51 -07:00
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2018-07-18 18:07:11 -07:00
|
|
|
ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) {
|
2018-07-27 20:55:23 -07:00
|
|
|
if (nca == nullptr)
|
|
|
|
return ResultStatus::ErrorNotLoaded;
|
|
|
|
if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0)
|
2018-07-07 20:24:51 -07:00
|
|
|
return ResultStatus::ErrorNotUsed;
|
2018-07-18 18:07:11 -07:00
|
|
|
dir = nca->GetRomFS();
|
2018-06-21 08:16:23 -07:00
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2018-07-27 20:55:23 -07:00
|
|
|
ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) {
|
2018-07-28 09:32:16 -07:00
|
|
|
if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
|
|
|
|
return ResultStatus::ErrorInvalidFormat;
|
2018-07-27 20:55:23 -07:00
|
|
|
out_program_id = nca->GetTitleId();
|
|
|
|
return ResultStatus::Success;
|
|
|
|
}
|
|
|
|
|
2018-06-21 08:16:23 -07:00
|
|
|
AppLoader_NCA::~AppLoader_NCA() = default;
|
|
|
|
|
|
|
|
} // namespace Loader
|