+27
-12
@@ -53,7 +53,6 @@ std::string DBDCrypt::encrypt(const std::string& data, const std::string& access
|
|||||||
return "DbdDAQEB" + b64Enc(fullPayload);
|
return "DbdDAQEB" + b64Enc(fullPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type == TYPE_2)
|
if (type == TYPE_2)
|
||||||
{
|
{
|
||||||
auto transformedKey = transformCDNKey(CDN_KEY_BASE64);
|
auto transformedKey = transformCDNKey(CDN_KEY_BASE64);
|
||||||
@@ -183,13 +182,11 @@ std::string DBDCrypt::decType3(const std::string& data, const std::string& key,
|
|||||||
for (char& c : decrypted)
|
for (char& c : decrypted)
|
||||||
c = (char)((unsigned char)c + 1);
|
c = (char)((unsigned char)c + 1);
|
||||||
|
|
||||||
if (decrypted.length() >= 2 && decrypted.at(1) == '\0')
|
if (decrypted.length() >= 2 && decrypted.at(1) == '\0') decrypted = utf16ToUtf8(decrypted);
|
||||||
decrypted = utf16ToUtf8(decrypted);
|
|
||||||
|
|
||||||
decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x01), decrypted.end());
|
decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x01), decrypted.end());
|
||||||
decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x00), decrypted.end());
|
decrypted.erase(std::remove(decrypted.begin(), decrypted.end(), (char)0x00), decrypted.end());
|
||||||
|
|
||||||
|
|
||||||
for (size_t offset : {0ULL, 4ULL})
|
for (size_t offset : {0ULL, 4ULL})
|
||||||
{
|
{
|
||||||
if (offset + 1 < decrypted.size() && (unsigned char)decrypted[offset] == 0x78)
|
if (offset + 1 < decrypted.size() && (unsigned char)decrypted[offset] == 0x78)
|
||||||
@@ -430,19 +427,38 @@ std::string DBDCrypt::utf8ToUtf16(const std::string& utf8)
|
|||||||
{
|
{
|
||||||
if (utf8.empty()) return "";
|
if (utf8.empty()) return "";
|
||||||
std::string utf16;
|
std::string utf16;
|
||||||
for (size_t i = 0; i < utf8.length(); )
|
for (size_t i = 0; i < utf8.length();)
|
||||||
{
|
{
|
||||||
uint32_t cp = 0;
|
uint32_t cp = 0;
|
||||||
unsigned char c = utf8[i];
|
unsigned char c = utf8[i];
|
||||||
if (c < 0x80) { cp = c; i += 1; }
|
if (c < 0x80)
|
||||||
else if (c < 0xE0) { cp = ((c & 0x1F) << 6) | (utf8[i + 1] & 0x3F); i += 2; }
|
{
|
||||||
else if (c < 0xF0) { cp = ((c & 0x0F) << 12) | ((utf8[i + 1] & 0x3F) << 6) | (utf8[i + 2] & 0x3F); i += 3; }
|
cp = c;
|
||||||
else { cp = ((c & 0x07) << 18) | ((utf8[i + 1] & 0x3F) << 12) | ((utf8[i + 2] & 0x3F) << 6) | (utf8[i + 3] & 0x3F); i += 4; }
|
i += 1;
|
||||||
|
}
|
||||||
|
else if (c < 0xE0)
|
||||||
|
{
|
||||||
|
cp = ((c & 0x1F) << 6) | (utf8[i + 1] & 0x3F);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
else if (c < 0xF0)
|
||||||
|
{
|
||||||
|
cp = ((c & 0x0F) << 12) | ((utf8[i + 1] & 0x3F) << 6) | (utf8[i + 2] & 0x3F);
|
||||||
|
i += 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cp = ((c & 0x07) << 18) | ((utf8[i + 1] & 0x3F) << 12) | ((utf8[i + 2] & 0x3F) << 6) | (utf8[i + 3] & 0x3F);
|
||||||
|
i += 4;
|
||||||
|
}
|
||||||
|
|
||||||
if (cp < 0x10000) {
|
if (cp < 0x10000)
|
||||||
|
{
|
||||||
utf16.push_back((char)(cp & 0xFF));
|
utf16.push_back((char)(cp & 0xFF));
|
||||||
utf16.push_back((char)(cp >> 8));
|
utf16.push_back((char)(cp >> 8));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
cp -= 0x10000;
|
cp -= 0x10000;
|
||||||
uint16_t high = (uint16_t)(0xD800 | (cp >> 10));
|
uint16_t high = (uint16_t)(0xD800 | (cp >> 10));
|
||||||
uint16_t low = (uint16_t)(0xDC00 | (cp & 0x3FF));
|
uint16_t low = (uint16_t)(0xDC00 | (cp & 0x3FF));
|
||||||
@@ -455,4 +471,3 @@ std::string DBDCrypt::utf8ToUtf16(const std::string& utf8)
|
|||||||
}
|
}
|
||||||
return utf16;
|
return utf16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user