diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/core.cpp | 30 | ||||
-rw-r--r-- | src/core/core.h | 33 | ||||
-rw-r--r-- | src/core/file_sys/card_image.cpp | 19 | ||||
-rw-r--r-- | src/core/file_sys/content_archive.cpp | 86 | ||||
-rw-r--r-- | src/core/file_sys/content_archive.h | 5 | ||||
-rw-r--r-- | src/core/file_sys/partition_filesystem.cpp | 8 | ||||
-rw-r--r-- | src/core/file_sys/program_metadata.cpp | 12 | ||||
-rw-r--r-- | src/core/frontend/emu_window.cpp | 4 | ||||
-rw-r--r-- | src/core/frontend/emu_window.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/server_session.cpp | 8 | ||||
-rw-r--r-- | src/core/hle/service/friend/friend.cpp | 104 | ||||
-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 |
18 files changed, 345 insertions, 110 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 69c45c026..83d4d742b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -88,7 +88,7 @@ System::ResultStatus System::SingleStep() { return RunLoop(false); } -System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& filepath) { +System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) { app_loader = Loader::GetLoader(virtual_filesystem->OpenFile(filepath, FileSys::Mode::Read)); if (!app_loader) { @@ -102,18 +102,8 @@ System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& file LOG_CRITICAL(Core, "Failed to determine system mode (Error {})!", static_cast<int>(system_mode.second)); - switch (system_mode.second) { - case Loader::ResultStatus::ErrorMissingKeys: - return ResultStatus::ErrorLoader_ErrorMissingKeys; - case Loader::ResultStatus::ErrorDecrypting: - return ResultStatus::ErrorLoader_ErrorDecrypting; - case Loader::ResultStatus::ErrorInvalidFormat: - return ResultStatus::ErrorLoader_ErrorInvalidFormat; - case Loader::ResultStatus::ErrorUnsupportedArch: - return ResultStatus::ErrorUnsupportedArch; - default: + if (system_mode.second != Loader::ResultStatus::Success) return ResultStatus::ErrorSystemMode; - } } ResultStatus init_result{Init(emu_window)}; @@ -129,17 +119,9 @@ System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& file LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result)); System::Shutdown(); - switch (load_result) { - case Loader::ResultStatus::ErrorMissingKeys: - return ResultStatus::ErrorLoader_ErrorMissingKeys; - case Loader::ResultStatus::ErrorDecrypting: - return ResultStatus::ErrorLoader_ErrorDecrypting; - case Loader::ResultStatus::ErrorInvalidFormat: - return ResultStatus::ErrorLoader_ErrorInvalidFormat; - case Loader::ResultStatus::ErrorUnsupportedArch: - return ResultStatus::ErrorUnsupportedArch; - default: - return ResultStatus::ErrorLoader; + if (load_result != Loader::ResultStatus::Success) { + return static_cast<ResultStatus>(static_cast<u32>(ResultStatus::ErrorLoader) + + static_cast<u32>(load_result)); } } status = ResultStatus::Success; @@ -169,7 +151,7 @@ Cpu& System::CpuCore(size_t core_index) { return *cpu_cores[core_index]; } -System::ResultStatus System::Init(EmuWindow& emu_window) { +System::ResultStatus System::Init(Frontend::EmuWindow& emu_window) { LOG_DEBUG(HW_Memory, "initialized OK"); CoreTiming::Init(); diff --git a/src/core/core.h b/src/core/core.h index 7cf7ea4e1..d98b15a71 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -22,9 +22,12 @@ #include "video_core/debug_utils/debug_utils.h" #include "video_core/gpu.h" -class EmuWindow; class ARM_Interface; +namespace Core::Frontend { +class EmuWindow; +} + namespace Service::SM { class ServiceManager; } @@ -49,21 +52,15 @@ public: /// Enumeration representing the return values of the System Initialize and Load process. enum class ResultStatus : u32 { - Success, ///< Succeeded - ErrorNotInitialized, ///< Error trying to use core prior to initialization - ErrorGetLoader, ///< Error finding the correct application loader - ErrorSystemMode, ///< Error determining the system mode - ErrorLoader, ///< Error loading the specified application - ErrorLoader_ErrorMissingKeys, ///< Error because the key/keys needed to run could not be - ///< found. - ErrorLoader_ErrorDecrypting, ///< Error loading the specified application due to encryption - ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an - /// invalid format - ErrorSystemFiles, ///< Error in finding system files - ErrorSharedFont, ///< Error in finding shared font - ErrorVideoCore, ///< Error in the video core - ErrorUnsupportedArch, ///< Unsupported Architecture (32-Bit ROMs) - ErrorUnknown ///< Any other error + Success, ///< Succeeded + ErrorNotInitialized, ///< Error trying to use core prior to initialization + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemMode, ///< Error determining the system mode + ErrorSystemFiles, ///< Error in finding system files + ErrorSharedFont, ///< Error in finding shared font + ErrorVideoCore, ///< Error in the video core + ErrorUnknown, ///< Any other error + ErrorLoader, ///< The base for loader errors (too many to repeat) }; /** @@ -105,7 +102,7 @@ public: * @param filepath String path to the executable application to load on the host file system. * @returns ResultStatus code, indicating if the operation succeeded. */ - ResultStatus Load(EmuWindow& emu_window, const std::string& filepath); + ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath); /** * Indicates if the emulated system is powered on (all subsystems initialized and able to run an @@ -233,7 +230,7 @@ private: * input. * @return ResultStatus code, indicating if the operation succeeded. */ - ResultStatus Init(EmuWindow& emu_window); + ResultStatus Init(Frontend::EmuWindow& emu_window); /// RealVfsFilesystem instance FileSys::VirtualFilesystem virtual_filesystem; diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp index e897d9913..a4823353e 100644 --- a/src/core/file_sys/card_image.cpp +++ b/src/core/file_sys/card_image.cpp @@ -12,14 +12,16 @@ namespace FileSys { +constexpr std::array<const char*, 0x4> partition_names = {"update", "normal", "secure", "logo"}; + XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) { if (file->ReadObject(&header) != sizeof(GamecardHeader)) { - status = Loader::ResultStatus::ErrorInvalidFormat; + status = Loader::ResultStatus::ErrorBadXCIHeader; return; } if (header.magic != Common::MakeMagic('H', 'E', 'A', 'D')) { - status = Loader::ResultStatus::ErrorInvalidFormat; + status = Loader::ResultStatus::ErrorBadXCIHeader; return; } @@ -31,9 +33,6 @@ XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) { return; } - static constexpr std::array<const char*, 0x4> partition_names = {"update", "normal", "secure", - "logo"}; - for (XCIPartition partition : {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) { auto raw = main_hfs.GetFile(partition_names[static_cast<size_t>(partition)]); @@ -130,15 +129,21 @@ bool XCI::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { if (partitions[static_cast<size_t>(part)] == nullptr) { - return Loader::ResultStatus::ErrorInvalidFormat; + return Loader::ResultStatus::ErrorXCIMissingPartition; } for (const VirtualFile& file : partitions[static_cast<size_t>(part)]->GetFiles()) { if (file->GetExtension() != "nca") continue; auto nca = std::make_shared<NCA>(file); - if (nca->GetStatus() == Loader::ResultStatus::Success) + if (nca->GetStatus() == Loader::ResultStatus::Success) { ncas.push_back(std::move(nca)); + } else { + const u16 error_id = static_cast<u16>(nca->GetStatus()); + LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})", + partition_names[static_cast<size_t>(part)], nca->GetName(), error_id, + Loader::GetMessageForResultStatus(nca->GetStatus())); + } } return Loader::ResultStatus::Success; diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index d3007d981..47afcad9b 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -113,17 +113,27 @@ boost::optional<Core::Crypto::Key128> NCA::GetKeyAreaKey(NCASectionCryptoType ty return out; } -boost::optional<Core::Crypto::Key128> NCA::GetTitlekey() const { +boost::optional<Core::Crypto::Key128> NCA::GetTitlekey() { const auto master_key_id = GetCryptoRevision(); u128 rights_id{}; memcpy(rights_id.data(), header.rights_id.data(), 16); - if (rights_id == u128{}) + if (rights_id == u128{}) { + status = Loader::ResultStatus::ErrorInvalidRightsID; return boost::none; + } auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]); - if (titlekey == Core::Crypto::Key128{}) + if (titlekey == Core::Crypto::Key128{}) { + status = Loader::ResultStatus::ErrorMissingTitlekey; + return boost::none; + } + + if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) { + status = Loader::ResultStatus::ErrorMissingTitlekek; return boost::none; + } + Core::Crypto::AESCipher<Core::Crypto::Key128> cipher( keys.GetKey(Core::Crypto::S128KeyType::Titlekek, master_key_id), Core::Crypto::Mode::ECB); cipher.Transcode(titlekey.data(), titlekey.size(), titlekey.data(), Core::Crypto::Op::Decrypt); @@ -131,7 +141,7 @@ boost::optional<Core::Crypto::Key128> NCA::GetTitlekey() const { return titlekey; } -VirtualFile NCA::Decrypt(NCASectionHeader s_header, VirtualFile in, u64 starting_offset) const { +VirtualFile NCA::Decrypt(NCASectionHeader s_header, VirtualFile in, u64 starting_offset) { if (!encrypted) return in; @@ -143,15 +153,22 @@ VirtualFile NCA::Decrypt(NCASectionHeader s_header, VirtualFile in, u64 starting LOG_DEBUG(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset); { boost::optional<Core::Crypto::Key128> key = boost::none; - if (std::find_if_not(header.rights_id.begin(), header.rights_id.end(), - [](char c) { return c == 0; }) == header.rights_id.end()) { - key = GetKeyAreaKey(NCASectionCryptoType::CTR); - } else { + if (has_rights_id) { + status = Loader::ResultStatus::Success; key = GetTitlekey(); + if (key == boost::none) { + if (status == Loader::ResultStatus::Success) + status = Loader::ResultStatus::ErrorMissingTitlekey; + return nullptr; + } + } else { + key = GetKeyAreaKey(NCASectionCryptoType::CTR); + if (key == boost::none) { + status = Loader::ResultStatus::ErrorMissingKeyAreaKey; + return nullptr; + } } - if (key == boost::none) - return nullptr; auto out = std::make_shared<Core::Crypto::CTREncryptionLayer>( std::move(in), key.value(), starting_offset); std::vector<u8> iv(16); @@ -170,16 +187,31 @@ VirtualFile NCA::Decrypt(NCASectionHeader s_header, VirtualFile in, u64 starting } NCA::NCA(VirtualFile file_) : file(std::move(file_)) { + status = Loader::ResultStatus::Success; + if (file == nullptr) { - status = Loader::ResultStatus::ErrorInvalidFormat; + status = Loader::ResultStatus::ErrorNullFile; return; } - if (sizeof(NCAHeader) != file->ReadObject(&header)) + + if (sizeof(NCAHeader) != file->ReadObject(&header)) { LOG_ERROR(Loader, "File reader errored out during header read."); + status = Loader::ResultStatus::ErrorBadNCAHeader; + return; + } encrypted = false; if (!IsValidNCA(header)) { + if (header.magic == Common::MakeMagic('N', 'C', 'A', '2')) { + status = Loader::ResultStatus::ErrorNCA2; + return; + } + if (header.magic == Common::MakeMagic('N', 'C', 'A', '0')) { + status = Loader::ResultStatus::ErrorNCA0; + return; + } + NCAHeader dec_header{}; Core::Crypto::AESCipher<Core::Crypto::Key256> cipher( keys.GetKey(Core::Crypto::S256KeyType::Header), Core::Crypto::Mode::XTS); @@ -189,14 +221,26 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { header = dec_header; encrypted = true; } else { + if (dec_header.magic == Common::MakeMagic('N', 'C', 'A', '2')) { + status = Loader::ResultStatus::ErrorNCA2; + return; + } + if (dec_header.magic == Common::MakeMagic('N', 'C', 'A', '0')) { + status = Loader::ResultStatus::ErrorNCA0; + return; + } + if (!keys.HasKey(Core::Crypto::S256KeyType::Header)) - status = Loader::ResultStatus::ErrorMissingKeys; + status = Loader::ResultStatus::ErrorMissingHeaderKey; else - status = Loader::ResultStatus::ErrorDecrypting; + status = Loader::ResultStatus::ErrorIncorrectHeaderKey; return; } } + has_rights_id = std::find_if_not(header.rights_id.begin(), header.rights_id.end(), + [](char c) { return c == '\0'; }) != header.rights_id.end(); + const std::ptrdiff_t number_sections = std::count_if(std::begin(header.section_tables), std::end(header.section_tables), [](NCASectionTableEntry entry) { return entry.media_offset > 0; }); @@ -229,7 +273,12 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { files.push_back(std::move(dec)); romfs = files.back(); } else { - status = Loader::ResultStatus::ErrorMissingKeys; + if (status != Loader::ResultStatus::Success) + return; + if (has_rights_id) + status = Loader::ResultStatus::ErrorIncorrectTitlekeyOrTitlekek; + else + status = Loader::ResultStatus::ErrorIncorrectKeyAreaKey; return; } } else if (section.raw.header.filesystem_type == NCASectionFilesystemType::PFS0) { @@ -249,7 +298,12 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { exefs = dirs.back(); } } else { - status = Loader::ResultStatus::ErrorMissingKeys; + if (status != Loader::ResultStatus::Success) + return; + if (has_rights_id) + status = Loader::ResultStatus::ErrorIncorrectTitlekeyOrTitlekek; + else + status = Loader::ResultStatus::ErrorIncorrectKeyAreaKey; return; } } diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index 5cfd5031a..b82e65ad5 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -98,8 +98,8 @@ protected: private: u8 GetCryptoRevision() const; boost::optional<Core::Crypto::Key128> GetKeyAreaKey(NCASectionCryptoType type) const; - boost::optional<Core::Crypto::Key128> GetTitlekey() const; - VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset) const; + boost::optional<Core::Crypto::Key128> GetTitlekey(); + VirtualFile Decrypt(NCASectionHeader header, VirtualFile in, u64 starting_offset); std::vector<VirtualDir> dirs; std::vector<VirtualFile> files; @@ -109,6 +109,7 @@ private: VirtualFile file; NCAHeader header{}; + bool has_rights_id{}; Loader::ResultStatus status{}; diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 47e032b19..c377edc9c 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -24,19 +24,19 @@ bool PartitionFilesystem::Header::HasValidMagicValue() const { PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // At least be as large as the header if (file->GetSize() < sizeof(Header)) { - status = Loader::ResultStatus::Error; + status = Loader::ResultStatus::ErrorBadPFSHeader; return; } // For cartridges, HFSs can get very large, so we need to calculate the size up to // the actual content itself instead of just blindly reading in the entire file. if (sizeof(Header) != file->ReadObject(&pfs_header)) { - status = Loader::ResultStatus::Error; + status = Loader::ResultStatus::ErrorBadPFSHeader; return; } if (!pfs_header.HasValidMagicValue()) { - status = Loader::ResultStatus::ErrorInvalidFormat; + status = Loader::ResultStatus::ErrorBadPFSHeader; return; } @@ -51,7 +51,7 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { const size_t total_size = file_data.size(); if (total_size != metadata_size) { - status = Loader::ResultStatus::Error; + status = Loader::ResultStatus::ErrorIncorrectPFSFileSize; return; } diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index 63d4b6e4f..279f987d4 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp @@ -12,26 +12,26 @@ namespace FileSys { Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { size_t total_size = static_cast<size_t>(file->GetSize()); if (total_size < sizeof(Header)) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadNPDMHeader; // TODO(DarkLordZach): Use ReadObject when Header/AcidHeader becomes trivially copyable. std::vector<u8> npdm_header_data = file->ReadBytes(sizeof(Header)); if (sizeof(Header) != npdm_header_data.size()) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadNPDMHeader; std::memcpy(&npdm_header, npdm_header_data.data(), sizeof(Header)); std::vector<u8> acid_header_data = file->ReadBytes(sizeof(AcidHeader), npdm_header.acid_offset); if (sizeof(AcidHeader) != acid_header_data.size()) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadACIDHeader; std::memcpy(&acid_header, acid_header_data.data(), sizeof(AcidHeader)); if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset)) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadACIHeader; if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset)) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadFileAccessControl; if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset)) - return Loader::ResultStatus::Error; + return Loader::ResultStatus::ErrorBadFileAccessHeader; return Loader::ResultStatus::Success; } diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 2d776c693..9dd493efb 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -8,6 +8,8 @@ #include "core/frontend/input.h" #include "core/settings.h" +namespace Core::Frontend { + class EmuWindow::TouchState : public Input::Factory<Input::TouchDevice>, public std::enable_shared_from_this<TouchState> { public: @@ -108,3 +110,5 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { NotifyFramebufferLayoutChanged(Layout::DefaultFrameLayout(width, height)); } + +} // namespace Core::Frontend diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index e8c29adfb..384dc7822 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h @@ -10,6 +10,8 @@ #include "common/common_types.h" #include "core/frontend/framebuffer_layout.h" +namespace Core::Frontend { + /** * Abstraction class used to provide an interface between emulation code and the frontend * (e.g. SDL, QGLWidget, GLFW, etc...). @@ -166,3 +168,5 @@ private: */ std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y); }; + +} // namespace Core::Frontend diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 93560152f..d09ca5992 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -71,6 +71,14 @@ ResultCode ServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& con const u32 object_id{context.GetDomainMessageHeader()->object_id}; switch (domain_message_header->command) { case IPC::DomainMessageHeader::CommandType::SendMessage: + if (object_id > domain_request_handlers.size()) { + LOG_CRITICAL(IPC, + "object_id {} is too big! This probably means a recent service call " + "to {} needed to return a new interface!", + object_id, name); + UNREACHABLE(); + return RESULT_SUCCESS; // Ignore error if asserts are off + } return domain_request_handlers[object_id - 1]->HandleSyncRequest(context); case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: { diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index fb4d89068..f2b0e509a 100644 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp @@ -9,10 +9,110 @@ namespace Service::Friend { +class IFriendService final : public ServiceFramework<IFriendService> { +public: + IFriendService() : ServiceFramework("IFriendService") { + static const FunctionInfo functions[] = { + {0, nullptr, "GetCompletionEvent"}, + {1, nullptr, "Cancel"}, + {10100, nullptr, "GetFriendListIds"}, + {10101, nullptr, "GetFriendList"}, + {10102, nullptr, "UpdateFriendInfo"}, + {10110, nullptr, "GetFriendProfileImage"}, + {10200, nullptr, "SendFriendRequestForApplication"}, + {10211, nullptr, "AddFacedFriendRequestForApplication"}, + {10400, nullptr, "GetBlockedUserListIds"}, + {10500, nullptr, "GetProfileList"}, + {10600, nullptr, "DeclareOpenOnlinePlaySession"}, + {10601, &IFriendService::DeclareCloseOnlinePlaySession, + "DeclareCloseOnlinePlaySession"}, + {10610, &IFriendService::UpdateUserPresence, "UpdateUserPresence"}, + {10700, nullptr, "GetPlayHistoryRegistrationKey"}, + {10701, nullptr, "GetPlayHistoryRegistrationKeyWithNetworkServiceAccountId"}, + {10702, nullptr, "AddPlayHistory"}, + {11000, nullptr, "GetProfileImageUrl"}, + {20100, nullptr, "GetFriendCount"}, + {20101, nullptr, "GetNewlyFriendCount"}, + {20102, nullptr, "GetFriendDetailedInfo"}, + {20103, nullptr, "SyncFriendList"}, + {20104, nullptr, "RequestSyncFriendList"}, + {20110, nullptr, "LoadFriendSetting"}, + {20200, nullptr, "GetReceivedFriendRequestCount"}, + {20201, nullptr, "GetFriendRequestList"}, + {20300, nullptr, "GetFriendCandidateList"}, + {20301, nullptr, "GetNintendoNetworkIdInfo"}, + {20302, nullptr, "GetSnsAccountLinkage"}, + {20303, nullptr, "GetSnsAccountProfile"}, + {20304, nullptr, "GetSnsAccountFriendList"}, + {20400, nullptr, "GetBlockedUserList"}, + {20401, nullptr, "SyncBlockedUserList"}, + {20500, nullptr, "GetProfileExtraList"}, + {20501, nullptr, "GetRelationship"}, + {20600, nullptr, "GetUserPresenceView"}, + {20700, nullptr, "GetPlayHistoryList"}, + {20701, nullptr, "GetPlayHistoryStatistics"}, + {20800, nullptr, "LoadUserSetting"}, + {20801, nullptr, "SyncUserSetting"}, + {20900, nullptr, "RequestListSummaryOverlayNotification"}, + {21000, nullptr, "GetExternalApplicationCatalog"}, + {30100, nullptr, "DropFriendNewlyFlags"}, + {30101, nullptr, "DeleteFriend"}, + {30110, nullptr, "DropFriendNewlyFlag"}, + {30120, nullptr, "ChangeFriendFavoriteFlag"}, + {30121, nullptr, "ChangeFriendOnlineNotificationFlag"}, + {30200, nullptr, "SendFriendRequest"}, + {30201, nullptr, "SendFriendRequestWithApplicationInfo"}, + {30202, nullptr, "CancelFriendRequest"}, + {30203, nullptr, "AcceptFriendRequest"}, + {30204, nullptr, "RejectFriendRequest"}, + {30205, nullptr, "ReadFriendRequest"}, + {30210, nullptr, "GetFacedFriendRequestRegistrationKey"}, + {30211, nullptr, "AddFacedFriendRequest"}, + {30212, nullptr, "CancelFacedFriendRequest"}, + {30213, nullptr, "GetFacedFriendRequestProfileImage"}, + {30214, nullptr, "GetFacedFriendRequestProfileImageFromPath"}, + {30215, nullptr, "SendFriendRequestWithExternalApplicationCatalogId"}, + {30216, nullptr, "ResendFacedFriendRequest"}, + {30217, nullptr, "SendFriendRequestWithNintendoNetworkIdInfo"}, + {30300, nullptr, "GetSnsAccountLinkPageUrl"}, + {30301, nullptr, "UnlinkSnsAccount"}, + {30400, nullptr, "BlockUser"}, + {30401, nullptr, "BlockUserWithApplicationInfo"}, + {30402, nullptr, "UnblockUser"}, + {30500, nullptr, "GetProfileExtraFromFriendCode"}, + {30700, nullptr, "DeletePlayHistory"}, + {30810, nullptr, "ChangePresencePermission"}, + {30811, nullptr, "ChangeFriendRequestReception"}, + {30812, nullptr, "ChangePlayLogPermission"}, + {30820, nullptr, "IssueFriendCode"}, + {30830, nullptr, "ClearPlayLog"}, + {49900, nullptr, "DeleteNetworkServiceAccountCache"}, + }; + + RegisterHandlers(functions); + } + +private: + void DeclareCloseOnlinePlaySession(Kernel::HLERequestContext& ctx) { + // Stub used by Splatoon 2 + LOG_WARNING(Service_ACC, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + + void UpdateUserPresence(Kernel::HLERequestContext& ctx) { + // Stub used by Retro City Rampage + LOG_WARNING(Service_ACC, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } +}; + void Module::Interface::CreateFriendService(Kernel::HLERequestContext& ctx) { - IPC::ResponseBuilder rb{ctx, 2}; + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - LOG_WARNING(Service_Friend, "(STUBBED) called"); + rb.PushIpcInterface<IFriendService>(); + LOG_DEBUG(Service_ACC, "called"); } Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) 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; } |