switch back to strings for simplicity

This commit is contained in:
psucien 2025-01-01 17:43:38 +01:00
parent 827214b237
commit 309fc59d16
3 changed files with 18 additions and 11 deletions

View File

@ -67,7 +67,7 @@ static int cursorHideTimeout = 5; // 5 seconds (default)
static bool separateupdatefolder = false; static bool separateupdatefolder = false;
static bool compatibilityData = false; static bool compatibilityData = false;
static bool checkCompatibilityOnStartup = false; static bool checkCompatibilityOnStartup = false;
static std::vector<u8> trophyKey; static std::string trophyKey;
// Gui // Gui
std::vector<std::filesystem::path> settings_install_dirs = {}; std::vector<std::filesystem::path> settings_install_dirs = {};
@ -92,11 +92,11 @@ std::string emulator_language = "en";
// Language // Language
u32 m_language = 1; // english u32 m_language = 1; // english
std::vector<u8> getTrophyKey() { std::string getTrophyKey() {
return trophyKey; return trophyKey;
} }
void setTrophyKey(std::vector<u8> key) { void setTrophyKey(std::string key) {
trophyKey = key; trophyKey = key;
} }
@ -664,9 +664,7 @@ void load(const std::filesystem::path& path) {
if (data.contains("Keys")) { if (data.contains("Keys")) {
const toml::value& keys = data.at("Keys"); const toml::value& keys = data.at("Keys");
if (keys.contains("TrophyKey") && keys.at("TrophyKey").is_array()) { trophyKey = toml::find_or<std::string>(keys, "TrophyKey", "");
trophyKey = toml::find<std::vector<u8>>(keys, "TrophyKey");
}
} }
} }

View File

@ -15,8 +15,8 @@ void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path); void save(const std::filesystem::path& path);
void saveMainWindow(const std::filesystem::path& path); void saveMainWindow(const std::filesystem::path& path);
std::vector<u8> getTrophyKey(); std::string getTrophyKey();
void setTrophyKey(std::vector<u8> key); void setTrophyKey(std::string key);
bool isNeoMode(); bool isNeoMode();
bool isFullscreenMode(); bool isFullscreenMode();

View File

@ -34,6 +34,13 @@ static void removePadding(std::vector<u8>& 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) { bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string titleId) {
std::filesystem::path gameSysDir = trophyPath / "sce_sys/trophy/"; std::filesystem::path gameSysDir = trophyPath / "sce_sys/trophy/";
if (!std::filesystem::exists(gameSysDir)) { if (!std::filesystem::exists(gameSysDir)) {
@ -41,13 +48,15 @@ bool TRP::Extract(const std::filesystem::path& trophyPath, const std::string tit
return false; return false;
} }
const auto user_key = Config::getTrophyKey(); const auto user_key_str = Config::getTrophyKey();
if (user_key.size() != 16) { if (user_key_str.size() != 32) {
LOG_CRITICAL(Common_Filesystem, "Trophy decryption key is not specified"); LOG_CRITICAL(Common_Filesystem, "Trophy decryption key is not specified");
return false; return false;
} }
const std::span<CryptoPP::byte, 16> key{(CryptoPP::byte*)user_key.data(), 16}; std::array<CryptoPP::byte, 16> user_key{};
hexToBytes(user_key_str.c_str(), user_key.data());
const std::span<CryptoPP::byte, 16> key{user_key.data(), user_key.size()};
for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) { for (int index = 0; const auto& it : std::filesystem::directory_iterator(gameSysDir)) {
if (it.is_regular_file()) { if (it.is_regular_file()) {