summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-07-30 12:46:23 -0400
committerGravatar Zach Hilman2018-08-01 00:16:54 -0400
commit187d8e215fb157edaa9f3976bebba9a9a7ed103d (patch)
tree140cbfbd109281adc87c9c79ee07976ba54888cd /src/core
parentUse static const instead of const static (diff)
downloadyuzu-187d8e215fb157edaa9f3976bebba9a9a7ed103d.tar.gz
yuzu-187d8e215fb157edaa9f3976bebba9a9a7ed103d.tar.xz
yuzu-187d8e215fb157edaa9f3976bebba9a9a7ed103d.zip
Use more descriptive error codes and messages
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.cpp12
-rw-r--r--src/core/core.h14
-rw-r--r--src/core/crypto/key_manager.cpp27
-rw-r--r--src/core/crypto/key_manager.h2
-rw-r--r--src/core/file_sys/content_archive.cpp10
-rw-r--r--src/core/loader/loader.h3
-rw-r--r--src/core/loader/xci.cpp2
7 files changed, 51 insertions, 19 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index b7f4b4532..0ef6af3fe 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -101,8 +101,10 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
101 static_cast<int>(system_mode.second)); 101 static_cast<int>(system_mode.second));
102 102
103 switch (system_mode.second) { 103 switch (system_mode.second) {
104 case Loader::ResultStatus::ErrorEncrypted: 104 case Loader::ResultStatus::ErrorMissingKeys:
105 return ResultStatus::ErrorLoader_ErrorEncrypted; 105 return ResultStatus::ErrorLoader_ErrorMissingKeys;
106 case Loader::ResultStatus::ErrorDecrypting:
107 return ResultStatus::ErrorLoader_ErrorDecrypting;
106 case Loader::ResultStatus::ErrorInvalidFormat: 108 case Loader::ResultStatus::ErrorInvalidFormat:
107 return ResultStatus::ErrorLoader_ErrorInvalidFormat; 109 return ResultStatus::ErrorLoader_ErrorInvalidFormat;
108 case Loader::ResultStatus::ErrorUnsupportedArch: 110 case Loader::ResultStatus::ErrorUnsupportedArch:
@@ -126,8 +128,10 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
126 System::Shutdown(); 128 System::Shutdown();
127 129
128 switch (load_result) { 130 switch (load_result) {
129 case Loader::ResultStatus::ErrorEncrypted: 131 case Loader::ResultStatus::ErrorMissingKeys:
130 return ResultStatus::ErrorLoader_ErrorEncrypted; 132 return ResultStatus::ErrorLoader_ErrorMissingKeys;
133 case Loader::ResultStatus::ErrorDecrypting:
134 return ResultStatus::ErrorLoader_ErrorDecrypting;
131 case Loader::ResultStatus::ErrorInvalidFormat: 135 case Loader::ResultStatus::ErrorInvalidFormat:
132 return ResultStatus::ErrorLoader_ErrorInvalidFormat; 136 return ResultStatus::ErrorLoader_ErrorInvalidFormat;
133 case Loader::ResultStatus::ErrorUnsupportedArch: 137 case Loader::ResultStatus::ErrorUnsupportedArch:
diff --git a/src/core/core.h b/src/core/core.h
index c123fe401..a90bff3df 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -43,12 +43,14 @@ public:
43 43
44 /// Enumeration representing the return values of the System Initialize and Load process. 44 /// Enumeration representing the return values of the System Initialize and Load process.
45 enum class ResultStatus : u32 { 45 enum class ResultStatus : u32 {
46 Success, ///< Succeeded 46 Success, ///< Succeeded
47 ErrorNotInitialized, ///< Error trying to use core prior to initialization 47 ErrorNotInitialized, ///< Error trying to use core prior to initialization
48 ErrorGetLoader, ///< Error finding the correct application loader 48 ErrorGetLoader, ///< Error finding the correct application loader
49 ErrorSystemMode, ///< Error determining the system mode 49 ErrorSystemMode, ///< Error determining the system mode
50 ErrorLoader, ///< Error loading the specified application 50 ErrorLoader, ///< Error loading the specified application
51 ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption 51 ErrorLoader_ErrorMissingKeys, ///< Error because the key/keys needed to run could not be
52 ///< found.
53 ErrorLoader_ErrorDecrypting, ///< Error loading the specified application due to encryption
52 ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an 54 ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an
53 /// invalid format 55 /// invalid format
54 ErrorSystemFiles, ///< Error in finding system files 56 ErrorSystemFiles, ///< Error in finding system files
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 33633de7e..678ac5752 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -53,8 +53,8 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
53 53
54KeyManager::KeyManager() { 54KeyManager::KeyManager() {
55 // Initialize keys 55 // Initialize keys
56 std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); 56 const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
57 std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); 57 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
58 if (Settings::values.use_dev_keys) { 58 if (Settings::values.use_dev_keys) {
59 dev_mode = true; 59 dev_mode = true;
60 AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false); 60 AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
@@ -109,9 +109,9 @@ void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) {
109 109
110void KeyManager::AttemptLoadKeyFile(std::string_view dir1_, std::string_view dir2_, 110void KeyManager::AttemptLoadKeyFile(std::string_view dir1_, std::string_view dir2_,
111 std::string_view filename_, bool title) { 111 std::string_view filename_, bool title) {
112 std::string dir1(dir1_); 112 const std::string dir1(dir1_);
113 std::string dir2(dir2_); 113 const std::string dir2(dir2_);
114 std::string filename(filename_); 114 const std::string filename(filename_);
115 if (FileUtil::Exists(dir1 + DIR_SEP + filename)) 115 if (FileUtil::Exists(dir1 + DIR_SEP + filename))
116 LoadFromFile(dir1 + DIR_SEP + filename, title); 116 LoadFromFile(dir1 + DIR_SEP + filename, title);
117 else if (FileUtil::Exists(dir2 + DIR_SEP + filename)) 117 else if (FileUtil::Exists(dir2 + DIR_SEP + filename))
@@ -146,6 +146,23 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) {
146 s256_keys[{id, field1, field2}] = key; 146 s256_keys[{id, field1, field2}] = key;
147} 147}
148 148
149bool KeyManager::KeyFileExists(bool title) {
150 const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
151 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
152 if (title) {
153 return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "title.keys") ||
154 FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "title.keys");
155 }
156
157 if (Settings::values.use_dev_keys) {
158 return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "dev.keys") ||
159 FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "dev.keys");
160 }
161
162 return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "prod.keys") ||
163 FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "prod.keys");
164}
165
149const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { 166const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = {
150 {"master_key_00", {S128KeyType::Master, 0, 0}}, 167 {"master_key_00", {S128KeyType::Master, 0, 0}},
151 {"master_key_01", {S128KeyType::Master, 1, 0}}, 168 {"master_key_01", {S128KeyType::Master, 1, 0}},
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index c09a6197e..03152a12c 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -102,6 +102,8 @@ public:
102 void SetKey(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); 102 void SetKey(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0);
103 void SetKey(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); 103 void SetKey(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0);
104 104
105 static bool KeyFileExists(bool title);
106
105private: 107private:
106 std::unordered_map<KeyIndex<S128KeyType>, Key128> s128_keys; 108 std::unordered_map<KeyIndex<S128KeyType>, Key128> s128_keys;
107 std::unordered_map<KeyIndex<S256KeyType>, Key256> s256_keys; 109 std::unordered_map<KeyIndex<S256KeyType>, Key256> s256_keys;
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index cb59c0a2b..2deb727cc 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -156,9 +156,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) {
156 encrypted = true; 156 encrypted = true;
157 } else { 157 } else {
158 if (!keys.HasKey(Core::Crypto::S256KeyType::Header)) 158 if (!keys.HasKey(Core::Crypto::S256KeyType::Header))
159 status = Loader::ResultStatus::ErrorEncrypted; 159 status = Loader::ResultStatus::ErrorMissingKeys;
160 else 160 else
161 status = Loader::ResultStatus::ErrorInvalidFormat; 161 status = Loader::ResultStatus::ErrorDecrypting;
162 return; 162 return;
163 } 163 }
164 } 164 }
@@ -194,6 +194,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) {
194 if (dec != nullptr) { 194 if (dec != nullptr) {
195 files.emplace_back(); 195 files.emplace_back();
196 romfs = files.back(); 196 romfs = files.back();
197 } else {
198 status = Loader::ResultStatus::ErrorMissingKeys;
199 return;
197 } 200 }
198 } else if (section.raw.header.filesystem_type == NCASectionFilesystemType::PFS0) { 201 } else if (section.raw.header.filesystem_type == NCASectionFilesystemType::PFS0) {
199 u64 offset = (static_cast<u64>(header.section_tables[i].media_offset) * 202 u64 offset = (static_cast<u64>(header.section_tables[i].media_offset) *
@@ -211,6 +214,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) {
211 if (IsDirectoryExeFS(dirs.back())) 214 if (IsDirectoryExeFS(dirs.back()))
212 exefs = dirs.back(); 215 exefs = dirs.back();
213 } 216 }
217 } else {
218 status = Loader::ResultStatus::ErrorMissingKeys;
219 return;
214 } 220 }
215 } 221 }
216 } 222 }
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index dc8d28311..cd8b41bb6 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -73,7 +73,8 @@ enum class ResultStatus {
73 ErrorNotUsed, 73 ErrorNotUsed,
74 ErrorAlreadyLoaded, 74 ErrorAlreadyLoaded,
75 ErrorMemoryAllocationFailed, 75 ErrorMemoryAllocationFailed,
76 ErrorEncrypted, 76 ErrorMissingKeys,
77 ErrorDecrypting,
77 ErrorUnsupportedArch, 78 ErrorUnsupportedArch,
78}; 79};
79 80
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp
index 74940fb83..d757862f0 100644
--- a/src/core/loader/xci.cpp
+++ b/src/core/loader/xci.cpp
@@ -49,7 +49,7 @@ ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) {
49 } 49 }
50 50
51 if (xci->GetNCAFileByType(FileSys::NCAContentType::Program) == nullptr) { 51 if (xci->GetNCAFileByType(FileSys::NCAContentType::Program) == nullptr) {
52 return ResultStatus::ErrorEncrypted; 52 return ResultStatus::ErrorDecrypting;
53 } 53 }
54 54
55 auto result = nca_loader->Load(process); 55 auto result = nca_loader->Load(process);