summaryrefslogtreecommitdiffstats
path: root/src/core/loader
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp5
-rw-r--r--src/core/loader/deconstructed_rom_directory.h2
-rw-r--r--src/core/loader/elf.h2
-rw-r--r--src/core/loader/loader.cpp4
-rw-r--r--src/core/loader/loader.h31
-rw-r--r--src/core/loader/nax.cpp11
-rw-r--r--src/core/loader/nax.h5
-rw-r--r--src/core/loader/nca.cpp19
-rw-r--r--src/core/loader/nca.h5
-rw-r--r--src/core/loader/nro.h2
-rw-r--r--src/core/loader/nso.h2
-rw-r--r--src/core/loader/nsp.cpp24
-rw-r--r--src/core/loader/nsp.h7
-rw-r--r--src/core/loader/xci.cpp25
-rw-r--r--src/core/loader/xci.h7
15 files changed, 139 insertions, 12 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index ac04d72d7..07aa7a1cd 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -129,7 +129,10 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
return ResultStatus::Error32BitISA;
}
- process.LoadFromMetadata(metadata);
+ if (process.LoadFromMetadata(metadata).IsError()) {
+ return ResultStatus::ErrorUnableToParseKernelMetadata;
+ }
+
const FileSys::PatchManager pm(metadata.GetTitleID());
// Load NSO modules
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h
index d109ed2b5..1615cb5a8 100644
--- a/src/core/loader/deconstructed_rom_directory.h
+++ b/src/core/loader/deconstructed_rom_directory.h
@@ -33,7 +33,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h
index 6af76441c..a2d33021c 100644
--- a/src/core/loader/elf.h
+++ b/src/core/loader/elf.h
@@ -22,7 +22,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 9cd0b0ccd..d8cc30959 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -93,7 +93,7 @@ std::string GetFileTypeString(FileType type) {
return "unknown";
}
-constexpr std::array<const char*, 60> RESULT_MESSAGES{
+constexpr std::array<const char*, 62> RESULT_MESSAGES{
"The operation completed successfully.",
"The loader requested to load is already loaded.",
"The operation is not implemented.",
@@ -103,6 +103,7 @@ constexpr std::array<const char*, 60> RESULT_MESSAGES{
"The NPDM has a bad ACI header,",
"The NPDM file has a bad file access control.",
"The NPDM has a bad file access header.",
+ "The NPDM has bad kernel capability descriptors.",
"The PFS/HFS partition has a bad header.",
"The PFS/HFS partition has incorrect size as determined by the header.",
"The NCA file has a bad header.",
@@ -125,6 +126,7 @@ constexpr std::array<const char*, 60> RESULT_MESSAGES{
"The file could not be found or does not exist.",
"The game is missing a program metadata file (main.npdm).",
"The game uses the currently-unimplemented 32-bit architecture.",
+ "Unable to completely parse the kernel metadata when loading the emulated process",
"The RomFS could not be found.",
"The ELF file has incorrect size as determined by the header.",
"There was a general error loading the NRO into emulated memory.",
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 7686634bf..bb925f4a6 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -12,8 +12,13 @@
#include <vector>
#include "common/common_types.h"
+#include "core/file_sys/control_metadata.h"
#include "core/file_sys/vfs.h"
+namespace FileSys {
+class NACP;
+} // namespace FileSys
+
namespace Kernel {
struct AddressMapping;
class Process;
@@ -66,6 +71,7 @@ enum class ResultStatus : u16 {
ErrorBadACIHeader,
ErrorBadFileAccessControl,
ErrorBadFileAccessHeader,
+ ErrorBadKernelCapabilityDescriptors,
ErrorBadPFSHeader,
ErrorIncorrectPFSFileSize,
ErrorBadNCAHeader,
@@ -88,6 +94,7 @@ enum class ResultStatus : u16 {
ErrorNullFile,
ErrorMissingNPDM,
Error32BitISA,
+ ErrorUnableToParseKernelMetadata,
ErrorNoRomFS,
ErrorIncorrectELFFileSize,
ErrorLoadingNRO,
@@ -131,7 +138,7 @@ public:
* Returns the type of this file
* @return FileType corresponding to the loaded file
*/
- virtual FileType GetFileType() = 0;
+ virtual FileType GetFileType() const = 0;
/**
* Load the application and return the created Process instance
@@ -171,6 +178,8 @@ public:
/**
* Get the banner (typically banner section) of the application
+ * In the context of NX, this is the animation that displays in the bottom right of the screen
+ * when a game boots. Stored in GIF format.
* @param buffer Reference to buffer to store data
* @return ResultStatus result of function
*/
@@ -180,6 +189,8 @@ public:
/**
* Get the logo (typically logo section) of the application
+ * In the context of NX, this is the static image that displays in the top left of the screen
+ * when a game boots. Stored in JPEG format.
* @param buffer Reference to buffer to store data
* @return ResultStatus result of function
*/
@@ -243,6 +254,24 @@ public:
return ResultStatus::ErrorNotImplemented;
}
+ /**
+ * Get the control data (CNMT) of the application
+ * @param control Reference to store the application control data into
+ * @return ResultStatus result of function
+ */
+ virtual ResultStatus ReadControlData(FileSys::NACP& control) {
+ return ResultStatus::ErrorNotImplemented;
+ }
+
+ /**
+ * Get the RomFS of the manual of the application
+ * @param file The raw manual RomFS of the game
+ * @return ResultStatus result of function
+ */
+ virtual ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) {
+ return ResultStatus::ErrorNotImplemented;
+ }
+
protected:
FileSys::VirtualFile file;
bool is_loaded = false;
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp
index 42f4a777b..93a970d10 100644
--- a/src/core/loader/nax.cpp
+++ b/src/core/loader/nax.cpp
@@ -37,7 +37,7 @@ FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
return IdentifyTypeImpl(nax);
}
-FileType AppLoader_NAX::GetFileType() {
+FileType AppLoader_NAX::GetFileType() const {
return IdentifyTypeImpl(*nax);
}
@@ -79,4 +79,13 @@ u64 AppLoader_NAX::ReadRomFSIVFCOffset() const {
ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) {
return nca_loader->ReadProgramId(out_program_id);
}
+
+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);
+}
+
} // namespace Loader
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h
index b4d93bd01..f40079574 100644
--- a/src/core/loader/nax.h
+++ b/src/core/loader/nax.h
@@ -31,7 +31,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override;
+ FileType GetFileType() const override;
ResultStatus Load(Kernel::Process& process) override;
@@ -39,6 +39,9 @@ public:
u64 ReadRomFSIVFCOffset() const override;
ResultStatus ReadProgramId(u64& out_program_id) override;
+ ResultStatus ReadBanner(std::vector<u8>& buffer) override;
+ ResultStatus ReadLogo(std::vector<u8>& buffer) override;
+
private:
std::unique_ptr<FileSys::NAX> nax;
std::unique_ptr<AppLoader_NCA> nca_loader;
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp
index 7e1b0d84f..ce8196fcf 100644
--- a/src/core/loader/nca.cpp
+++ b/src/core/loader/nca.cpp
@@ -84,4 +84,23 @@ ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) {
return ResultStatus::Success;
}
+ResultStatus AppLoader_NCA::ReadBanner(std::vector<u8>& buffer) {
+ if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
+ return ResultStatus::ErrorNotInitialized;
+ const auto logo = nca->GetLogoPartition();
+ if (logo == nullptr)
+ return ResultStatus::ErrorNoIcon;
+ buffer = logo->GetFile("StartupMovie.gif")->ReadAllBytes();
+ return ResultStatus::Success;
+}
+
+ResultStatus AppLoader_NCA::ReadLogo(std::vector<u8>& buffer) {
+ if (nca == nullptr || nca->GetStatus() != ResultStatus::Success)
+ return ResultStatus::ErrorNotInitialized;
+ const auto logo = nca->GetLogoPartition();
+ if (logo == nullptr)
+ return ResultStatus::ErrorNoIcon;
+ buffer = logo->GetFile("NintendoLogo.png")->ReadAllBytes();
+ return ResultStatus::Success;
+}
} // namespace Loader
diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h
index 95d9b73a1..b9f077468 100644
--- a/src/core/loader/nca.h
+++ b/src/core/loader/nca.h
@@ -29,7 +29,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
@@ -39,6 +39,9 @@ public:
u64 ReadRomFSIVFCOffset() const override;
ResultStatus ReadProgramId(u64& out_program_id) override;
+ ResultStatus ReadBanner(std::vector<u8>& buffer) override;
+ ResultStatus ReadLogo(std::vector<u8>& buffer) override;
+
private:
std::unique_ptr<FileSys::NCA> nca;
std::unique_ptr<AppLoader_DeconstructedRomDirectory> directory_loader;
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h
index 6deff3a51..013d629c0 100644
--- a/src/core/loader/nro.h
+++ b/src/core/loader/nro.h
@@ -33,7 +33,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h
index 0c1defbb6..135b6ea5a 100644
--- a/src/core/loader/nso.h
+++ b/src/core/loader/nso.h
@@ -37,7 +37,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp
index 080d89904..7da1f8960 100644
--- a/src/core/loader/nsp.cpp
+++ b/src/core/loader/nsp.cpp
@@ -151,4 +151,28 @@ ResultStatus AppLoader_NSP::ReadTitle(std::string& title) {
title = nacp_file->GetApplicationName();
return ResultStatus::Success;
}
+
+ResultStatus AppLoader_NSP::ReadControlData(FileSys::NACP& nacp) {
+ if (nacp_file == nullptr)
+ return ResultStatus::ErrorNoControl;
+ nacp = *nacp_file;
+ return ResultStatus::Success;
+}
+
+ResultStatus AppLoader_NSP::ReadManualRomFS(FileSys::VirtualFile& file) {
+ const auto nca = nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Manual);
+ if (nsp->GetStatus() != ResultStatus::Success || nca == nullptr)
+ return ResultStatus::ErrorNoRomFS;
+ file = nca->GetRomFS();
+ return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success;
+}
+
+ResultStatus AppLoader_NSP::ReadBanner(std::vector<u8>& buffer) {
+ return secondary_loader->ReadBanner(buffer);
+}
+
+ResultStatus AppLoader_NSP::ReadLogo(std::vector<u8>& buffer) {
+ return secondary_loader->ReadLogo(buffer);
+}
+
} // namespace Loader
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h
index db91cd01e..953a1b508 100644
--- a/src/core/loader/nsp.h
+++ b/src/core/loader/nsp.h
@@ -31,7 +31,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
@@ -43,6 +43,11 @@ public:
ResultStatus ReadProgramId(u64& out_program_id) override;
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
ResultStatus ReadTitle(std::string& title) override;
+ ResultStatus ReadControlData(FileSys::NACP& nacp) override;
+ ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override;
+
+ ResultStatus ReadBanner(std::vector<u8>& buffer) override;
+ ResultStatus ReadLogo(std::vector<u8>& buffer) override;
private:
std::unique_ptr<FileSys::NSP> nsp;
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp
index 461607c95..89f7bbf77 100644
--- a/src/core/loader/xci.cpp
+++ b/src/core/loader/xci.cpp
@@ -120,4 +120,29 @@ ResultStatus AppLoader_XCI::ReadTitle(std::string& title) {
title = nacp_file->GetApplicationName();
return ResultStatus::Success;
}
+
+ResultStatus AppLoader_XCI::ReadControlData(FileSys::NACP& control) {
+ if (nacp_file == nullptr)
+ return ResultStatus::ErrorNoControl;
+ control = *nacp_file;
+ return ResultStatus::Success;
+}
+
+ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& file) {
+ const auto nca = xci->GetSecurePartitionNSP()->GetNCA(xci->GetProgramTitleID(),
+ FileSys::ContentRecordType::Manual);
+ if (xci->GetStatus() != ResultStatus::Success || nca == nullptr)
+ return ResultStatus::ErrorXCIMissingPartition;
+ file = nca->GetRomFS();
+ return file == nullptr ? ResultStatus::ErrorNoRomFS : ResultStatus::Success;
+}
+
+ResultStatus AppLoader_XCI::ReadBanner(std::vector<u8>& buffer) {
+ return nca_loader->ReadBanner(buffer);
+}
+
+ResultStatus AppLoader_XCI::ReadLogo(std::vector<u8>& buffer) {
+ return nca_loader->ReadLogo(buffer);
+}
+
} // namespace Loader
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h
index 46f8dfc9e..d6995b61e 100644
--- a/src/core/loader/xci.h
+++ b/src/core/loader/xci.h
@@ -31,7 +31,7 @@ public:
*/
static FileType IdentifyType(const FileSys::VirtualFile& file);
- FileType GetFileType() override {
+ FileType GetFileType() const override {
return IdentifyType(file);
}
@@ -43,6 +43,11 @@ public:
ResultStatus ReadProgramId(u64& out_program_id) override;
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
ResultStatus ReadTitle(std::string& title) override;
+ ResultStatus ReadControlData(FileSys::NACP& control) override;
+ ResultStatus ReadManualRomFS(FileSys::VirtualFile& file) override;
+
+ ResultStatus ReadBanner(std::vector<u8>& buffer) override;
+ ResultStatus ReadLogo(std::vector<u8>& buffer) override;
private:
std::unique_ptr<FileSys::XCI> xci;