From a8aef599e02e336f9ecb8d5cfc50aa856ea0a1c7 Mon Sep 17 00:00:00 2001 From: TheKoopaKingdom Date: Thu, 13 Apr 2017 01:18:54 -0400 Subject: Created a whitelist of system archives to prevent false positives creating dialogs. --- src/core/core.cpp | 6 ++-- src/core/core.h | 12 ++------ src/core/hle/service/apt/apt.cpp | 5 ++-- src/core/hle/service/fs/fs_user.cpp | 55 ++++++++++++++++++++++++++++++++++--- src/core/loader/loader.h | 4 +-- src/core/loader/ncch.h | 2 +- 6 files changed, 60 insertions(+), 24 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 2a9664cb4..2456d8aa2 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -4,9 +4,6 @@ #include #include - -#include - #include "audio_core/audio_core.h" #include "common/logging/log.h" #include "core/arm/arm_interface.h" @@ -81,7 +78,8 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file app_loader->LoadKernelSystemMode(); if (system_mode.second != Loader::ResultStatus::Success) { - LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", system_mode.second); + LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!", + static_cast(system_mode.second)); System::Shutdown(); switch (system_mode.second) { diff --git a/src/core/core.h b/src/core/core.h index bc363ed97..6e555f954 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -6,9 +6,6 @@ #include #include - -#include - #include "common/common_types.h" #include "core/memory.h" #include "core/perf_stats.h" @@ -117,13 +114,10 @@ public: void SetStatus(ResultStatus new_status, std::string details = std::string()) { status = new_status; - if (details == std::string()) - status_details = boost::none; - else - status_details = details; + status_details = details; } - boost::optional GetStatusDetails() { + std::string GetStatusDetails() { return status_details; } @@ -154,7 +148,7 @@ private: static System s_instance; ResultStatus status; - boost::optional status_details; + std::string status_details; }; inline ARM_Interface& CPU() { diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index a92abb58f..4c587e3c8 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -281,9 +281,8 @@ void CancelParameter(Service::Interface* self) { rb.Push(RESULT_SUCCESS); // No error rb.Push(true); // Set to Success - LOG_WARNING(Service_APT, - "(STUBBED) called check_sender=0x%08X, sender_appid=0x%08X, " - "check_receiver=0x%08X, receiver_appid=0x%08X", + LOG_WARNING(Service_APT, "(STUBBED) called check_sender=0x%08X, sender_appid=0x%08X, " + "check_receiver=0x%08X, receiver_appid=0x%08X", check_sender, sender_appid, check_receiver, receiver_appid); } diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index 0538ffc9c..c65d46238 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp @@ -130,14 +130,61 @@ static void OpenFileDirectly(Service::Interface* self) { ResultVal archive_handle = OpenArchive(archive_id, archive_path); if (archive_handle.Failed()) { - LOG_ERROR(Service_FS, - "failed to get a handle for archive archive_id=0x%08X archive_path=%s", - static_cast(archive_id), archive_path.DebugStr().c_str()); cmd_buff[1] = archive_handle.Code().raw; cmd_buff[3] = 0; + if (static_cast(archive_id) == ArchiveIdCode::NCCH) { - Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles); + // High Title ID of the archive: The category (https://3dbrew.org/wiki/Title_list). + // (Note: The values there are big endian, these must be little endian.) + const std::vector shared_data_archive = {0x9B, 0x00, 0x04, 0x00}; + const std::vector system_data_archive = {0xDB, 0x00, 0x04, 0x00}; + + // Low Title IDs. + const std::vector mii_data = {0x02, 0x02, 0x01, 0x00}; + const std::vector region_manifest = {0x02, 0x04, 0x01, 0x00}; + const std::vector ng_word_list = {0x02, 0x03, 0x01, 0x00}; + + // Make a copy of the binary path because reusing AsBinary() for creating category + // results in bad_alloc being thrown. + std::vector binary_archive_path = archive_path.AsBinary(); + std::vector category(binary_archive_path.begin() + 4, + binary_archive_path.begin() + 8); + std::vector path(binary_archive_path.begin(), binary_archive_path.begin() + 4); + + if (category == shared_data_archive) { + if (path == mii_data) { + LOG_ERROR(Service_FS, + "Failed to get a handle for shared data archive: Mii data. " + "Archive ID=0x%08X Archive Path=%s", + static_cast(archive_id), archive_path.DebugStr().c_str()); + Core::System::GetInstance().SetStatus( + Core::System::ResultStatus::ErrorSystemFiles, "Mii data"); + return; + } else if (path == region_manifest) { + LOG_ERROR(Service_FS, + "Failed to get a handle for shared data archive: region manifest. " + "Archive ID=0x%08X Archive Path=%s", + static_cast(archive_id), archive_path.DebugStr().c_str()); + Core::System::GetInstance().SetStatus( + Core::System::ResultStatus::ErrorSystemFiles, "Region manifest"); + return; + } + } else if (category == system_data_archive) { + if (path == ng_word_list) { + LOG_ERROR(Service_FS, + "Failed to get a handle for system data archive: NG bad word list. " + "Archive ID=0x%08X Archive Path=%s", + static_cast(archive_id), archive_path.DebugStr().c_str()); + Core::System::GetInstance().SetStatus( + Core::System::ResultStatus::ErrorSystemFiles, "NG bad word list"); + return; + } + } } + + LOG_ERROR(Service_FS, + "Failed to get a handle for archive archive_id=0x%08X archive_path=%s", + static_cast(archive_id), archive_path.DebugStr().c_str()); return; } SCOPE_EXIT({ CloseArchive(*archive_handle); }); diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 0a2d4a10e..adb3ffdcf 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -10,9 +10,7 @@ #include #include #include - #include - #include "common/common_types.h" #include "common/file_util.h" @@ -103,7 +101,7 @@ public: * Loads the system mode that this application needs. * This function defaults to 2 (96MB allocated to the application) if it can't read the * information. - * @return A pair with the system mode (If found) and the result. + * @returns a pair of Optional with the kernel system mode and ResultStatus. */ virtual std::pair, ResultStatus> LoadKernelSystemMode() { // 96MB allocated to the application. diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 712d496a4..507da7550 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -179,7 +179,7 @@ public: /** * Loads the Exheader and returns the system mode for this application. - * @return A pair with the system mode (If found) and the result. + * @returns a pair of Optional with the kernel system mode and ResultStatus */ std::pair, ResultStatus> LoadKernelSystemMode() override; -- cgit v1.2.3