Created a whitelist of system archives to prevent false positives creating dialogs.

This commit is contained in:
TheKoopaKingdom 2017-04-13 01:18:54 -04:00
parent 0409bdfea5
commit a8aef599e0
9 changed files with 70 additions and 35 deletions

View File

@ -99,7 +99,7 @@ signals:
*/ */
void DebugModeLeft(); void DebugModeLeft();
void ErrorThrown(Core::System::ResultStatus, boost::optional<std::string>); void ErrorThrown(Core::System::ResultStatus, std::string);
}; };
class GRenderWindow : public QWidget, public EmuWindow { class GRenderWindow : public QWidget, public EmuWindow {

View File

@ -553,10 +553,9 @@ void GMainWindow::OnMenuRecentFile() {
void GMainWindow::OnStartGame() { void GMainWindow::OnStartGame() {
emu_thread->SetRunning(true); emu_thread->SetRunning(true);
qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus");
qRegisterMetaType<boost::optional<std::string>>("boost::optional<std::string>"); qRegisterMetaType<std::string>("std::string");
connect(emu_thread.get(), connect(emu_thread.get(), SIGNAL(ErrorThrown(Core::System::ResultStatus, std::string)), this,
SIGNAL(ErrorThrown(Core::System::ResultStatus, boost::optional<std::string>)), this, SLOT(OnCoreError(Core::System::ResultStatus, std::string)));
SLOT(OnCoreError(Core::System::ResultStatus, boost::optional<std::string>)));
ui.action_Start->setEnabled(false); ui.action_Start->setEnabled(false);
ui.action_Start->setText(tr("Continue")); ui.action_Start->setText(tr("Continue"));
@ -649,8 +648,7 @@ void GMainWindow::UpdateStatusBar() {
emu_frametime_label->setVisible(true); emu_frametime_label->setVisible(true);
} }
void GMainWindow::OnCoreError(Core::System::ResultStatus result, void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
boost::optional<std::string> details) {
QMessageBox::StandardButton answer; QMessageBox::StandardButton answer;
QString status_message; QString status_message;
const QString common_message = const QString common_message =
@ -664,8 +662,8 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result,
switch (result) { switch (result) {
case Core::System::ResultStatus::ErrorSystemFiles: { case Core::System::ResultStatus::ErrorSystemFiles: {
QString message = "Citra was unable to locate a 3DS system archive"; QString message = "Citra was unable to locate a 3DS system archive";
if (details) if (details != std::string())
message.append(tr(": %1. ").arg(details.get().c_str())); message.append(tr(": %1. ").arg(details.c_str()));
else else
message.append(". "); message.append(". ");
message.append(common_message); message.append(common_message);
@ -693,7 +691,7 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result,
"<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to " "<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to "
"Upload the Log File</a>.<br/><br/>Would you like to quit back to the game list?"), "Upload the Log File</a>.<br/><br/>Would you like to quit back to the game list?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No); QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
status_message = "Fatal Error encountered."; status_message = "Fatal Error encountered";
break; break;
} }

View File

@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <QMainWindow> #include <QMainWindow>
#include <QTimer> #include <QTimer>
#include "core/core.h"
#include "ui_main.h" #include "ui_main.h"
class Config; class Config;
@ -125,7 +126,7 @@ private slots:
void OnDisplayTitleBars(bool); void OnDisplayTitleBars(bool);
void ToggleWindowMode(); void ToggleWindowMode();
void OnCreateGraphicsSurfaceViewer(); void OnCreateGraphicsSurfaceViewer();
void OnCoreError(Core::System::ResultStatus, boost::optional<std::string>); void OnCoreError(Core::System::ResultStatus, std::string);
private: private:
void UpdateStatusBar(); void UpdateStatusBar();

View File

@ -4,9 +4,6 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include <boost/optional.hpp>
#include "audio_core/audio_core.h" #include "audio_core/audio_core.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/arm/arm_interface.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(); app_loader->LoadKernelSystemMode();
if (system_mode.second != Loader::ResultStatus::Success) { 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<int>(system_mode.second));
System::Shutdown(); System::Shutdown();
switch (system_mode.second) { switch (system_mode.second) {

View File

@ -6,9 +6,6 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <boost/optional.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/memory.h" #include "core/memory.h"
#include "core/perf_stats.h" #include "core/perf_stats.h"
@ -117,13 +114,10 @@ public:
void SetStatus(ResultStatus new_status, std::string details = std::string()) { void SetStatus(ResultStatus new_status, std::string details = std::string()) {
status = new_status; status = new_status;
if (details == std::string())
status_details = boost::none;
else
status_details = details; status_details = details;
} }
boost::optional<std::string> GetStatusDetails() { std::string GetStatusDetails() {
return status_details; return status_details;
} }
@ -154,7 +148,7 @@ private:
static System s_instance; static System s_instance;
ResultStatus status; ResultStatus status;
boost::optional<std::string> status_details; std::string status_details;
}; };
inline ARM_Interface& CPU() { inline ARM_Interface& CPU() {

View File

@ -281,8 +281,7 @@ void CancelParameter(Service::Interface* self) {
rb.Push(RESULT_SUCCESS); // No error rb.Push(RESULT_SUCCESS); // No error
rb.Push(true); // Set to Success rb.Push(true); // Set to Success
LOG_WARNING(Service_APT, LOG_WARNING(Service_APT, "(STUBBED) called check_sender=0x%08X, sender_appid=0x%08X, "
"(STUBBED) called check_sender=0x%08X, sender_appid=0x%08X, "
"check_receiver=0x%08X, receiver_appid=0x%08X", "check_receiver=0x%08X, receiver_appid=0x%08X",
check_sender, sender_appid, check_receiver, receiver_appid); check_sender, sender_appid, check_receiver, receiver_appid);
} }

View File

@ -130,14 +130,61 @@ static void OpenFileDirectly(Service::Interface* self) {
ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path); ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path);
if (archive_handle.Failed()) { if (archive_handle.Failed()) {
LOG_ERROR(Service_FS,
"failed to get a handle for archive archive_id=0x%08X archive_path=%s",
static_cast<u32>(archive_id), archive_path.DebugStr().c_str());
cmd_buff[1] = archive_handle.Code().raw; cmd_buff[1] = archive_handle.Code().raw;
cmd_buff[3] = 0; cmd_buff[3] = 0;
if (static_cast<FS::ArchiveIdCode>(archive_id) == ArchiveIdCode::NCCH) { if (static_cast<FS::ArchiveIdCode>(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<u8> shared_data_archive = {0x9B, 0x00, 0x04, 0x00};
const std::vector<u8> system_data_archive = {0xDB, 0x00, 0x04, 0x00};
// Low Title IDs.
const std::vector<u8> mii_data = {0x02, 0x02, 0x01, 0x00};
const std::vector<u8> region_manifest = {0x02, 0x04, 0x01, 0x00};
const std::vector<u8> 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<u8> binary_archive_path = archive_path.AsBinary();
std::vector<u8> category(binary_archive_path.begin() + 4,
binary_archive_path.begin() + 8);
std::vector<u8> 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<u32>(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<u32>(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<u32>(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<u32>(archive_id), archive_path.DebugStr().c_str());
return; return;
} }
SCOPE_EXIT({ CloseArchive(*archive_handle); }); SCOPE_EXIT({ CloseArchive(*archive_handle); });

View File

@ -10,9 +10,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
@ -103,7 +101,7 @@ public:
* Loads the system mode that this application needs. * Loads the system mode that this application needs.
* This function defaults to 2 (96MB allocated to the application) if it can't read the * This function defaults to 2 (96MB allocated to the application) if it can't read the
* information. * 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<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() { virtual std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() {
// 96MB allocated to the application. // 96MB allocated to the application.

View File

@ -179,7 +179,7 @@ public:
/** /**
* Loads the Exheader and returns the system mode for this application. * 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<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() override; std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() override;