diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-08-10 03:06:44 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-08-10 03:06:59 +0200 |
commit | ec3bef7b4c21931918f3a84ad79a53d31b02aeaf (patch) | |
tree | e9da97be14d9474910faa1cfde851aa5b2383bc0 /src/core/loader | |
parent | Merge pull request #995 from bunnei/gl-buff-bounds (diff) | |
download | yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar.gz yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar.bz2 yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar.lz yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar.xz yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.tar.zst yuzu-ec3bef7b4c21931918f3a84ad79a53d31b02aeaf.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 14 | ||||
-rw-r--r-- | src/core/loader/elf.cpp | 2 | ||||
-rw-r--r-- | src/core/loader/loader.cpp | 49 | ||||
-rw-r--r-- | src/core/loader/loader.h | 46 | ||||
-rw-r--r-- | src/core/loader/nca.cpp | 10 | ||||
-rw-r--r-- | src/core/loader/nro.cpp | 10 | ||||
-rw-r--r-- | src/core/loader/xci.cpp | 11 |
7 files changed, 111 insertions, 31 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 915d525b0..de05f21d8 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -83,13 +83,13 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( if (dir == nullptr) { if (file == nullptr) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNullFile; dir = file->GetContainingDirectory(); } const FileSys::VirtualFile npdm = dir->GetFile("main.npdm"); if (npdm == nullptr) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorMissingNPDM; ResultStatus result = metadata.Load(npdm); if (result != ResultStatus::Success) { @@ -99,7 +99,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit) { - return ResultStatus::ErrorUnsupportedArch; + return ResultStatus::Error32BitISA; } // Load NSO modules @@ -143,28 +143,28 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& dir) { if (romfs == nullptr) - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoRomFS; dir = romfs; return ResultStatus::Success; } ResultStatus AppLoader_DeconstructedRomDirectory::ReadIcon(std::vector<u8>& buffer) { if (icon_data.empty()) - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoIcon; buffer = icon_data; return ResultStatus::Success; } ResultStatus AppLoader_DeconstructedRomDirectory::ReadProgramId(u64& out_program_id) { if (name.empty()) - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoControl; out_program_id = title_id; return ResultStatus::Success; } ResultStatus AppLoader_DeconstructedRomDirectory::ReadTitle(std::string& title) { if (name.empty()) - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoControl; title = name; return ResultStatus::Success; } diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index a7133f5a6..401cad3ab 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -390,7 +390,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { std::vector<u8> buffer = file->ReadAllBytes(); if (buffer.size() != file->GetSize()) - return ResultStatus::Error; + return ResultStatus::ErrorIncorrectELFFileSize; ElfReader elf_reader(&buffer[0]); SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index a288654df..2f5bfc67c 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -86,6 +86,55 @@ std::string GetFileTypeString(FileType type) { return "unknown"; } +constexpr std::array<const char*, 36> RESULT_MESSAGES{ + "The operation completed successfully.", + "The loader requested to load is already loaded.", + "The operation is not implemented.", + "The loader is not initialized properly.", + "The NPDM file has a bad header.", + "The NPDM has a bad ACID header.", + "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 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.", + "The general keyfile could not be found.", + "The NCA Header key could not be found.", + "The NCA Header key is incorrect or the header is invalid.", + "Support for NCA2-type NCAs is not implemented.", + "Support for NCA0-type NCAs is not implemented.", + "The titlekey for this Rights ID could not be found.", + "The titlekek for this crypto revision could not be found.", + "The Rights ID in the header is invalid.", + "The key area key for this application type and crypto revision could not be found.", + "The key area key is incorrect or the section header is invalid.", + "The titlekey and/or titlekek is incorrect or the section header is invalid.", + "The XCI file is missing a Program-type NCA.", + "The NCA file is not an application.", + "The ExeFS partition could not be found.", + "The XCI file has a bad header.", + "The XCI file is missing a partition.", + "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.", + "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.", + "There is no icon available.", + "There is no control data available.", +}; + +std::string GetMessageForResultStatus(ResultStatus status) { + return GetMessageForResultStatus(static_cast<size_t>(status)); +} + +std::string GetMessageForResultStatus(u16 status) { + if (status >= 36) + return ""; + return RESULT_MESSAGES[status]; +} + /** * Get a loader for a file with a specific type * @param file The file to load diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 6a9e5a68b..cfdadbee3 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -58,18 +58,46 @@ std::string GetFileTypeString(FileType type); /// Return type for functions in Loader namespace enum class ResultStatus { Success, - Error, - ErrorInvalidFormat, - ErrorNotImplemented, - ErrorNotLoaded, - ErrorNotUsed, ErrorAlreadyLoaded, - ErrorMemoryAllocationFailed, - ErrorMissingKeys, - ErrorDecrypting, - ErrorUnsupportedArch, + ErrorNotImplemented, + ErrorNotInitialized, + ErrorBadNPDMHeader, + ErrorBadACIDHeader, + ErrorBadACIHeader, + ErrorBadFileAccessControl, + ErrorBadFileAccessHeader, + ErrorBadPFSHeader, + ErrorIncorrectPFSFileSize, + ErrorBadNCAHeader, + ErrorMissingProductionKeyFile, + ErrorMissingHeaderKey, + ErrorIncorrectHeaderKey, + ErrorNCA2, + ErrorNCA0, + ErrorMissingTitlekey, + ErrorMissingTitlekek, + ErrorInvalidRightsID, + ErrorMissingKeyAreaKey, + ErrorIncorrectKeyAreaKey, + ErrorIncorrectTitlekeyOrTitlekek, + ErrorXCIMissingProgramNCA, + ErrorNCANotProgram, + ErrorNoExeFS, + ErrorBadXCIHeader, + ErrorXCIMissingPartition, + ErrorNullFile, + ErrorMissingNPDM, + Error32BitISA, + ErrorNoRomFS, + ErrorIncorrectELFFileSize, + ErrorLoadingNRO, + ErrorNoIcon, + ErrorNoControl, }; +std::string GetMessageForResultStatus(ResultStatus status); +std::string GetMessageForResultStatus(u16 status); + /// Interface for loading an application class AppLoader : NonCopyable { public: diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index 46f5cd393..8498cc94b 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp @@ -46,12 +46,12 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) { } if (nca->GetType() != FileSys::NCAContentType::Program) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNCANotProgram; const auto exefs = nca->GetExeFS(); if (exefs == nullptr) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNoExeFS; directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs); @@ -69,16 +69,16 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) { ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { if (nca == nullptr) - return ResultStatus::ErrorNotLoaded; + return ResultStatus::ErrorNotInitialized; if (nca->GetRomFS() == nullptr || nca->GetRomFS()->GetSize() == 0) - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoRomFS; dir = nca->GetRomFS(); return ResultStatus::Success; } ResultStatus AppLoader_NCA::ReadProgramId(u64& out_program_id) { if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNotInitialized; out_program_id = nca->GetTitleId(); return ResultStatus::Success; } diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index dc053cdad..908d91eab 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -182,7 +182,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; if (!LoadNro(file, base_addr)) { - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorLoadingNRO; } process->svc_access_mask.set(); @@ -197,7 +197,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { if (icon_data.empty()) { - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoIcon; } buffer = icon_data; @@ -206,7 +206,7 @@ ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { if (nacp == nullptr) { - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoControl; } out_program_id = nacp->GetTitleId(); @@ -215,7 +215,7 @@ ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { if (romfs == nullptr) { - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoRomFS; } dir = romfs; @@ -224,7 +224,7 @@ ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { if (nacp == nullptr) { - return ResultStatus::ErrorNotUsed; + return ResultStatus::ErrorNoControl; } title = nacp->GetApplicationName(); diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index d3fe24419..5d67fb186 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -66,10 +66,13 @@ ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) { return ResultStatus::ErrorAlreadyLoaded; } + if (xci->GetStatus() != ResultStatus::Success) + return xci->GetStatus(); + if (xci->GetNCAFileByType(FileSys::NCAContentType::Program) == nullptr) { if (!Core::Crypto::KeyManager::KeyFileExists(false)) - return ResultStatus::ErrorMissingKeys; - return ResultStatus::ErrorDecrypting; + return ResultStatus::ErrorMissingProductionKeyFile; + return ResultStatus::ErrorXCIMissingProgramNCA; } auto result = nca_loader->Load(process); @@ -91,14 +94,14 @@ ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { if (icon_file == nullptr) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNoControl; buffer = icon_file->ReadAllBytes(); return ResultStatus::Success; } ResultStatus AppLoader_XCI::ReadTitle(std::string& title) { if (nacp_file == nullptr) - return ResultStatus::ErrorInvalidFormat; + return ResultStatus::ErrorNoControl; title = nacp_file->GetApplicationName(); return ResultStatus::Success; } |