summaryrefslogtreecommitdiff
path: root/src/common/hex_util.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-10-08 12:30:33 -0400
committerGravatar GitHub2018-10-08 12:30:33 -0400
commit6b48ba52712e5ea9cadb1177c06cb3ca65492c38 (patch)
tree365bb902d31fd5d5d585fc2f5d9e9dac274b02ec /src/common/hex_util.cpp
parentMerge pull request #1456 from ogniK5377/aoc-u-fixups (diff)
parentips_layer: Fix inaccuracies with comments and flags (diff)
downloadyuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.gz
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.tar.xz
yuzu-6b48ba52712e5ea9cadb1177c06cb3ca65492c38.zip
Merge pull request #1424 from DarkLordZach/ips-witch
ips_layer: Add support for IPSwitch executable patches
Diffstat (limited to 'src/common/hex_util.cpp')
-rw-r--r--src/common/hex_util.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp
index 589ae5cbf..5b63f9e81 100644
--- a/src/common/hex_util.cpp
+++ b/src/common/hex_util.cpp
@@ -18,6 +18,25 @@ u8 ToHexNibble(char c1) {
18 return 0; 18 return 0;
19} 19}
20 20
21std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) {
22 std::vector<u8> out(str.size() / 2);
23 if (little_endian) {
24 for (std::size_t i = str.size() - 2; i <= str.size(); i -= 2)
25 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
26 } else {
27 for (std::size_t i = 0; i < str.size(); i += 2)
28 out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]);
29 }
30 return out;
31}
32
33std::string HexVectorToString(const std::vector<u8>& vector, bool upper) {
34 std::string out;
35 for (u8 c : vector)
36 out += fmt::format(upper ? "{:02X}" : "{:02x}", c);
37 return out;
38}
39
21std::array<u8, 16> operator""_array16(const char* str, std::size_t len) { 40std::array<u8, 16> operator""_array16(const char* str, std::size_t len) {
22 if (len != 32) { 41 if (len != 32) {
23 LOG_ERROR(Common, 42 LOG_ERROR(Common,