From 533b992a4506c38873af38f40009aa55b5ee951c Mon Sep 17 00:00:00 2001 From: neru Date: Sun, 12 Apr 2026 23:18:52 -0300 Subject: [PATCH] fix: incorrect str fmt --- src/unlocker/dbdcrypt.cpp | 33 ++++++++++++++++++++++++++++++++- src/unlocker/dbdcrypt.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/unlocker/dbdcrypt.cpp b/src/unlocker/dbdcrypt.cpp index cd73416..a373397 100644 --- a/src/unlocker/dbdcrypt.cpp +++ b/src/unlocker/dbdcrypt.cpp @@ -112,6 +112,8 @@ std::string DBDCrypt::decType1(const std::string& data, const std::string& key, std::vector body(decoded.begin() + 4, decoded.end()); std::string decompressed = zlibDecompress(body); + if (decompressed.length() >= 2 && decompressed[1] == '\0') decompressed = utf16ToUtf8(decompressed); + if (decompressed.starts_with("DbdD")) return decrypt(decompressed, key, outType); return decompressed; } @@ -133,10 +135,11 @@ std::string DBDCrypt::decType2(const std::string& data, const std::string& key, for (char& c : decrypted) c = (char)((unsigned char)c + 1); + if (decrypted.length() >= 2 && decrypted[1] == '\0') decrypted = utf16ToUtf8(decrypted); + decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x01), decrypted.end()); decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x00), decrypted.end()); - for (size_t offset : {0ULL, 4ULL}) { if (offset + 1 < decrypted.size() && (unsigned char)decrypted[offset] == 0x78) @@ -175,6 +178,9 @@ std::string DBDCrypt::decType3(const std::string& data, const std::string& key, for (char& c : decrypted) c = (char)((unsigned char)c + 1); + if (decrypted.length() >= 2 && decrypted.at(1) == '\0') + decrypted = utf16ToUtf8(decrypted); + decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x01), decrypted.end()); decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x00), decrypted.end()); @@ -389,3 +395,28 @@ std::string DBDCrypt::shiftKeyID(const std::string& id, int shift) c = (char)((unsigned char)c + shift); return res; } + +std::string DBDCrypt::utf16ToUtf8(const std::string& utf16) +{ + if (utf16.empty()) return ""; + std::string utf8; + for (size_t i = 0; i < utf16.length(); i += 2) + { + uint16_t cp = *(uint16_t*)(utf16.data() + i); + if (cp == 0) break; + if (cp < 0x80) + utf8 += (char)cp; + else if (cp < 0x800) + { + utf8 += (char)(0xC0 | (cp >> 6)); + utf8 += (char)(0x80 | (cp & 0x3F)); + } + else + { + utf8 += (char)(0xE0 | (cp >> 12)); + utf8 += (char)(0x80 | ((cp >> 6) & 0x3F)); + utf8 += (char)(0x80 | (cp & 0x3F)); + } + } + return utf8; +} diff --git a/src/unlocker/dbdcrypt.h b/src/unlocker/dbdcrypt.h index f4a64e8..3b2e81c 100644 --- a/src/unlocker/dbdcrypt.h +++ b/src/unlocker/dbdcrypt.h @@ -46,4 +46,6 @@ class DBDCrypt static std::vector transformCDNKey(const std::string& b64CDNKey); static std::string shiftKeyID(const std::string& id, int shift); + static std::string utf16ToUtf8(const std::string& utf16); + };