summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/hex_util.cpp4
-rw-r--r--src/common/hex_util.h4
-rw-r--r--src/core/crypto/key_manager.cpp8
-rw-r--r--src/core/file_sys/registered_cache.cpp18
4 files changed, 22 insertions, 12 deletions
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index ae17c89d4..609144def 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -4,6 +4,8 @@
4 4
5#include "common/hex_util.h" 5#include "common/hex_util.h"
6 6
7namespace Common {
8
7u8 ToHexNibble(char c1) { 9u8 ToHexNibble(char c1) {
8 if (c1 >= 65 && c1 <= 70) 10 if (c1 >= 65 && c1 <= 70)
9 return c1 - 55; 11 return c1 - 55;
@@ -25,3 +27,5 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
25 throw std::logic_error("Not of correct size."); 27 throw std::logic_error("Not of correct size.");
26 return HexStringToArray<32>(str); 28 return HexStringToArray<32>(str);
27} 29}
30
31} // namespace Common
diff --git a/src/common/hex_util.h b/src/common/hex_util.h
index 13d586015..5fb79bb72 100644
--- a/src/common/hex_util.h
+++ b/src/common/hex_util.h
@@ -10,6 +10,8 @@
10#include <fmt/format.h> 10#include <fmt/format.h>
11#include "common/common_types.h" 11#include "common/common_types.h"
12 12
13namespace Common {
14
13u8 ToHexNibble(char c1); 15u8 ToHexNibble(char c1);
14 16
15template <size_t Size, bool le = false> 17template <size_t Size, bool le = false>
@@ -35,3 +37,5 @@ std::string HexArrayToString(std::array<u8, Size> array, bool upper = true) {
35 37
36std::array<u8, 0x10> operator"" _array16(const char* str, size_t len); 38std::array<u8, 0x10> operator"" _array16(const char* str, size_t len);
37std::array<u8, 0x20> operator"" _array32(const char* str, size_t len); 39std::array<u8, 0x20> operator"" _array32(const char* str, size_t len);
40
41} // namespace Common
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 94d92579f..db8b22c85 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -52,20 +52,20 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
52 out[1].erase(std::remove(out[1].begin(), out[1].end(), ' '), out[1].end()); 52 out[1].erase(std::remove(out[1].begin(), out[1].end(), ' '), out[1].end());
53 53
54 if (is_title_keys) { 54 if (is_title_keys) {
55 auto rights_id_raw = HexStringToArray<16>(out[0]); 55 auto rights_id_raw = Common::HexStringToArray<16>(out[0]);
56 u128 rights_id{}; 56 u128 rights_id{};
57 std::memcpy(rights_id.data(), rights_id_raw.data(), rights_id_raw.size()); 57 std::memcpy(rights_id.data(), rights_id_raw.data(), rights_id_raw.size());
58 Key128 key = HexStringToArray<16>(out[1]); 58 Key128 key = Common::HexStringToArray<16>(out[1]);
59 SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); 59 SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]);
60 } else { 60 } else {
61 std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower); 61 std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower);
62 if (s128_file_id.find(out[0]) != s128_file_id.end()) { 62 if (s128_file_id.find(out[0]) != s128_file_id.end()) {
63 const auto index = s128_file_id.at(out[0]); 63 const auto index = s128_file_id.at(out[0]);
64 Key128 key = HexStringToArray<16>(out[1]); 64 Key128 key = Common::HexStringToArray<16>(out[1]);
65 SetKey(index.type, key, index.field1, index.field2); 65 SetKey(index.type, key, index.field1, index.field2);
66 } else if (s256_file_id.find(out[0]) != s256_file_id.end()) { 66 } else if (s256_file_id.find(out[0]) != s256_file_id.end()) {
67 const auto index = s256_file_id.at(out[0]); 67 const auto index = s256_file_id.at(out[0]);
68 Key256 key = HexStringToArray<32>(out[1]); 68 Key256 key = Common::HexStringToArray<32>(out[1]);
69 SetKey(index.type, key, index.field1, index.field2); 69 SetKey(index.type, key, index.field1, index.field2);
70 } 70 }
71 } 71 }
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index a5e935f64..d25eeee34 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -37,11 +37,12 @@ static bool FollowsNcaIdFormat(std::string_view name) {
37static std::string GetRelativePathFromNcaID(const std::array<u8, 16>& nca_id, bool second_hex_upper, 37static std::string GetRelativePathFromNcaID(const std::array<u8, 16>& nca_id, bool second_hex_upper,
38 bool within_two_digit) { 38 bool within_two_digit) {
39 if (!within_two_digit) 39 if (!within_two_digit)
40 return fmt::format("/{}.nca", HexArrayToString(nca_id, second_hex_upper)); 40 return fmt::format("/{}.nca", Common::HexArrayToString(nca_id, second_hex_upper));
41 41
42 Core::Crypto::SHA256Hash hash{}; 42 Core::Crypto::SHA256Hash hash{};
43 mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0); 43 mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0);
44 return fmt::format("/000000{:02X}/{}.nca", hash[0], HexArrayToString(nca_id, second_hex_upper)); 44 return fmt::format("/000000{:02X}/{}.nca", hash[0],
45 Common::HexArrayToString(nca_id, second_hex_upper));
45} 46}
46 47
47static std::string GetCNMTName(TitleType type, u64 title_id) { 48static std::string GetCNMTName(TitleType type, u64 title_id) {
@@ -170,7 +171,7 @@ std::vector<NcaID> RegisteredCache::AccumulateFiles() const {
170 std::vector<NcaID> ids; 171 std::vector<NcaID> ids;
171 for (const auto& d2_dir : dir->GetSubdirectories()) { 172 for (const auto& d2_dir : dir->GetSubdirectories()) {
172 if (FollowsNcaIdFormat(d2_dir->GetName())) { 173 if (FollowsNcaIdFormat(d2_dir->GetName())) {
173 ids.push_back(HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20))); 174 ids.push_back(Common::HexStringToArray<0x10, true>(d2_dir->GetName().substr(0, 0x20)));
174 continue; 175 continue;
175 } 176 }
176 177
@@ -181,20 +182,21 @@ std::vector<NcaID> RegisteredCache::AccumulateFiles() const {
181 if (!FollowsNcaIdFormat(nca_dir->GetName())) 182 if (!FollowsNcaIdFormat(nca_dir->GetName()))
182 continue; 183 continue;
183 184
184 ids.push_back(HexStringToArray<0x10, true>(nca_dir->GetName().substr(0, 0x20))); 185 ids.push_back(Common::HexStringToArray<0x10, true>(nca_dir->GetName().substr(0, 0x20)));
185 } 186 }
186 187
187 for (const auto& nca_file : d2_dir->GetFiles()) { 188 for (const auto& nca_file : d2_dir->GetFiles()) {
188 if (!FollowsNcaIdFormat(nca_file->GetName())) 189 if (!FollowsNcaIdFormat(nca_file->GetName()))
189 continue; 190 continue;
190 191
191 ids.push_back(HexStringToArray<0x10, true>(nca_file->GetName().substr(0, 0x20))); 192 ids.push_back(
193 Common::HexStringToArray<0x10, true>(nca_file->GetName().substr(0, 0x20)));
192 } 194 }
193 } 195 }
194 196
195 for (const auto& d2_file : dir->GetFiles()) { 197 for (const auto& d2_file : dir->GetFiles()) {
196 if (FollowsNcaIdFormat(d2_file->GetName())) 198 if (FollowsNcaIdFormat(d2_file->GetName()))
197 ids.push_back(HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20))); 199 ids.push_back(Common::HexStringToArray<0x10, true>(d2_file->GetName().substr(0, 0x20)));
198 } 200 }
199 return ids; 201 return ids;
200} 202}
@@ -339,7 +341,7 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
339} 341}
340 342
341static std::shared_ptr<NCA> GetNCAFromXCIForID(std::shared_ptr<XCI> xci, const NcaID& id) { 343static std::shared_ptr<NCA> GetNCAFromXCIForID(std::shared_ptr<XCI> xci, const NcaID& id) {
342 const auto filename = fmt::format("{}.nca", HexArrayToString(id, false)); 344 const auto filename = fmt::format("{}.nca", Common::HexArrayToString(id, false));
343 const auto iter = 345 const auto iter =
344 std::find_if(xci->GetNCAs().begin(), xci->GetNCAs().end(), 346 std::find_if(xci->GetNCAs().begin(), xci->GetNCAs().end(),
345 [&filename](std::shared_ptr<NCA> nca) { return nca->GetName() == filename; }); 347 [&filename](std::shared_ptr<NCA> nca) { return nca->GetName() == filename; });
@@ -361,7 +363,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, bool overw
361 363
362 // Install Metadata File 364 // Install Metadata File
363 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32); 365 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
364 const auto meta_id = HexStringToArray<16>(meta_id_raw); 366 const auto meta_id = Common::HexStringToArray<16>(meta_id_raw);
365 367
366 const auto res = RawInstallNCA(*meta_iter, copy, overwrite_if_exists, meta_id); 368 const auto res = RawInstallNCA(*meta_iter, copy, overwrite_if_exists, meta_id);
367 if (res != InstallResult::Success) 369 if (res != InstallResult::Success)