From 309fc59d16978d1f0f6a8dd8f839b34da8f57c0a Mon Sep 17 00:00:00 2001 From: psucien Date: Wed, 1 Jan 2025 17:43:38 +0100 Subject: [PATCH] switch back to strings for simplicity --- src/common/config.cpp | 10 ++++------ src/common/config.h | 4 ++-- src/core/file_format/trp.cpp | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 2a8352fbd..246644e2d 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -67,7 +67,7 @@ static int cursorHideTimeout = 5; // 5 seconds (default) static bool separateupdatefolder = false; static bool compatibilityData = false; static bool checkCompatibilityOnStartup = false; -static std::vector trophyKey; +static std::string trophyKey; // Gui std::vector settings_install_dirs = {}; @@ -92,11 +92,11 @@ std::string emulator_language = "en"; // Language u32 m_language = 1; // english -std::vector getTrophyKey() { +std::string getTrophyKey() { return trophyKey; } -void setTrophyKey(std::vector key) { +void setTrophyKey(std::string key) { trophyKey = key; } @@ -664,9 +664,7 @@ void load(const std::filesystem::path& path) { if (data.contains("Keys")) { const toml::value& keys = data.at("Keys"); - if (keys.contains("TrophyKey") && keys.at("TrophyKey").is_array()) { - trophyKey = toml::find>(keys, "TrophyKey"); - } + trophyKey = toml::find_or(keys, "TrophyKey", ""); } } diff --git a/src/common/config.h b/src/common/config.h index 9e7dff2a9..9d943008b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -15,8 +15,8 @@ void load(const std::filesystem::path& path); void save(const std::filesystem::path& path); void saveMainWindow(const std::filesystem::path& path); -std::vector getTrophyKey(); -void setTrophyKey(std::vector key); +std::string getTrophyKey(); +void setTrophyKey(std::string key); bool isNeoMode(); bool isFullscreenMode(); diff --git a/src/core/file_format/trp.cpp b/src/core/file_format/trp.cpp index 187dd8d9d..28e3910a1 100644 --- a/src/core/file_format/trp.cpp +++ b/src/core/file_format/trp.cpp @@ -34,6 +34,13 @@ static void removePadding(std::vector& vec) { } } +static void hexToBytes(const char* hex, unsigned char* dst) { + for (size_t i = 0; hex[i] != 0; i++) { + const unsigned char value = (hex[i] < 0x3A) ? (hex[i] - 0x30) : (hex[i] - 0x37); + dst[i / 2] |= ((i % 2) == 0) ? (value << 4) : (value); + } +} + bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string titleId) { std::filesystem::path gameSysDir = trophyPath / "sce_sys/trophy/"; if (!std::filesystem::exists(gameSysDir)) { @@ -41,13 +48,15 @@ bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string tit return false; } - const auto user_key = Config::getTrophyKey(); - if (user_key.size() != 16) { + const auto user_key_str = Config::getTrophyKey(); + if (user_key_str.size() != 32) { LOG_CRITICAL(Common_Filesystem, "Trophy decryption key is not specified"); return false; } - const std::span key{(CryptoPP::byte*)user_key.data(), 16}; + std::array user_key{}; + hexToBytes(user_key_str.c_str(), user_key.data()); + const std::span key{user_key.data(), user_key.size()}; for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) { if (it.is_regular_file()) {