summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-07-24 04:06:30 +0200
committerGitHub <noreply@github.com>2018-07-24 04:06:30 +0200
commit10dd03dec5d43dc4486c313e7654b89c3bbe32a2 (patch)
tree720918f2ce43b138b4c3918efab361fcb57bc579
parentMerge pull request #781 from lioncash/decl (diff)
parentnro: Replace inclusion with a forward declaration (diff)
downloadyuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.gz
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.bz2
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.lz
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.xz
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.tar.zst
yuzu-10dd03dec5d43dc4486c313e7654b89c3bbe32a2.zip
-rw-r--r--src/core/loader/nro.cpp37
-rw-r--r--src/core/loader/nro.h10
2 files changed, 33 insertions, 14 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 44158655c..7d3ec2a76 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -6,6 +6,7 @@
#include <vector>
#include "common/common_funcs.h"
+#include "common/common_types.h"
#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/swap.h"
@@ -68,22 +69,27 @@ static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size.");
AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {
NroHeader nro_header{};
- if (file->ReadObject(&nro_header) != sizeof(NroHeader))
+ if (file->ReadObject(&nro_header) != sizeof(NroHeader)) {
return;
+ }
if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) {
- u64 offset = nro_header.file_size;
+ const u64 offset = nro_header.file_size;
AssetHeader asset_header{};
- if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader))
+ if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) {
return;
+ }
- if (asset_header.format_version != 0)
+ if (asset_header.format_version != 0) {
LOG_WARNING(Loader,
"NRO Asset Header has format {}, currently supported format is 0. If "
"strange glitches occur with metadata, check NRO assets.",
asset_header.format_version);
- if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T'))
+ }
+
+ if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) {
return;
+ }
if (asset_header.nacp.size > 0) {
nacp = std::make_unique<FileSys::NACP>(std::make_shared<FileSys::OffsetVfsFile>(
@@ -101,6 +107,8 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {
}
}
+AppLoader_NRO::~AppLoader_NRO() = default;
+
FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) {
// Read NSO header
NroHeader nro_header{};
@@ -130,8 +138,9 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
// Build program image
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size));
- if (program_image.size() != PageAlignSize(nro_header.file_size))
+ if (program_image.size() != PageAlignSize(nro_header.file_size)) {
return {};
+ }
for (std::size_t i = 0; i < nro_header.segments.size(); ++i) {
codeset->segments[i].addr = nro_header.segments[i].offset;
@@ -187,29 +196,37 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
}
ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) {
- if (icon_data.empty())
+ if (icon_data.empty()) {
return ResultStatus::ErrorNotUsed;
+ }
+
buffer = icon_data;
return ResultStatus::Success;
}
ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) {
- if (nacp == nullptr)
+ if (nacp == nullptr) {
return ResultStatus::ErrorNotUsed;
+ }
+
out_program_id = nacp->GetTitleId();
return ResultStatus::Success;
}
ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) {
- if (romfs == nullptr)
+ if (romfs == nullptr) {
return ResultStatus::ErrorNotUsed;
+ }
+
dir = romfs;
return ResultStatus::Success;
}
ResultStatus AppLoader_NRO::ReadTitle(std::string& title) {
- if (nacp == nullptr)
+ if (nacp == nullptr) {
return ResultStatus::ErrorNotUsed;
+ }
+
title = nacp->GetApplicationName();
return ResultStatus::Success;
}
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h
index 5f3fc40d2..04a0f497e 100644
--- a/src/core/loader/nro.h
+++ b/src/core/loader/nro.h
@@ -6,19 +6,21 @@
#include <string>
#include "common/common_types.h"
-#include "core/file_sys/control_metadata.h"
#include "core/hle/kernel/kernel.h"
#include "core/loader/linker.h"
#include "core/loader/loader.h"
-namespace Loader {
+namespace FileSys {
+class NACP;
+}
-struct AssetHeader;
+namespace Loader {
/// Loads an NRO file
class AppLoader_NRO final : public AppLoader, Linker {
public:
- AppLoader_NRO(FileSys::VirtualFile file);
+ explicit AppLoader_NRO(FileSys::VirtualFile file);
+ ~AppLoader_NRO() override;
/**
* Returns the type of the file