From 3710a4211244505ef766a9113544fdf94f85832e Mon Sep 17 00:00:00 2001 From: Kohaku Date: Wed, 19 Mar 2025 16:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=85=AC=E5=BC=80?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E7=BB=93=E6=9E=9C=EF=BC=88=E8=BF=98?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=BA=9B=E6=9C=AA=E8=A7=A3=E5=86=B3=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_TitleServer.py | 9 ++++++--- ActionLoginBonus.py | 2 +- ...yptAuthLite.py => DecryptAuthLiteTraffic.py} | 0 ...cryptHDD.py => DecryptTitleServerTraffic.py} | 17 ++++++++--------- 4 files changed, 15 insertions(+), 13 deletions(-) rename Standalone/{DecryptAuthLite.py => DecryptAuthLiteTraffic.py} (100%) rename Standalone/{DecryptHDD.py => DecryptTitleServerTraffic.py} (82%) diff --git a/API_TitleServer.py b/API_TitleServer.py index c8da162..7186b60 100644 --- a/API_TitleServer.py +++ b/API_TitleServer.py @@ -35,9 +35,12 @@ class AESPKCS7: self.iv = iv.encode('utf-8') self.mode = AES.MODE_CBC # 加密 - def encrypt(self, content: bytes) -> bytes: + def encrypt(self, content) -> bytes: + # if content is str, convert to bytes + if isinstance(content, str): + encodedData = content.encode('utf-8') cipher = AES.new(self.key, self.mode, self.iv) - content_padded = pad(content, AES.block_size) + content_padded = pad(encodedData, AES.block_size) encrypted_bytes = cipher.encrypt(content_padded) return encrypted_bytes # 解密 @@ -108,7 +111,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t logger.warning(f"无法解压,得到的原始响应: {responseRAWContent}") raise SDGBResponseError("解压失败") try: - resultResponse = unpad(aes.decrypt(responseDecompressed), 16).decode() + resultResponse = aes.decrypt(responseDecompressed) logger.debug(f"成功解密响应!") except: logger.warning(f"解密失败,得到的原始响应: {responseDecompressed}") diff --git a/ActionLoginBonus.py b/ActionLoginBonus.py index 0b5a9ee..f076648 100644 --- a/ActionLoginBonus.py +++ b/ActionLoginBonus.py @@ -140,7 +140,7 @@ def generateLoginBonusList(UserLoginBonusList, generateMode=1): } bonusList.append(data) else: - raise ValueError("generateMode は 1 または 2 でなければなりません") + raise SyntaxError("generateMode は 1 または 2 でなければなりません") logger.debug(f"ログインボーナスリスト: {bonusList}") return bonusList diff --git a/Standalone/DecryptAuthLite.py b/Standalone/DecryptAuthLiteTraffic.py similarity index 100% rename from Standalone/DecryptAuthLite.py rename to Standalone/DecryptAuthLiteTraffic.py diff --git a/Standalone/DecryptHDD.py b/Standalone/DecryptTitleServerTraffic.py similarity index 82% rename from Standalone/DecryptHDD.py rename to Standalone/DecryptTitleServerTraffic.py index 0482aa1..3c25d4c 100644 --- a/Standalone/DecryptHDD.py +++ b/Standalone/DecryptTitleServerTraffic.py @@ -8,14 +8,13 @@ import zlib from Crypto.Cipher import AES from Crypto.Util.Padding import unpad, pad -# 密钥和 IV # CN 2024 -aesKey2024 = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@" -aesIV2024 = ";;KjR1C3hgB1ovXa" +AES_KEY_SDGB_1_40 = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@" +AES_IV_SDGB_1_40 = ";;KjR1C3hgB1ovXa" # 国际服 PRiSM -aesKeyPrism = "A;mv5YUpHBK3YxTy5KB^[;5]C2AL50Bq" -aesIVPrism = "9FM:sd9xA91X14v]" +AES_KEY_SDGA_1_50 = "A;mv5YUpHBK3YxTy5KB^[;5]C2AL50Bq" +AES_IV_SDGA_1_50 = "9FM:sd9xA91X14v]" class AESPKCS7: # 实现了 maimai 通讯所用的 AES 加密的类 @@ -24,9 +23,9 @@ class AESPKCS7: self.iv = iv.encode('utf-8') self.mode = AES.MODE_CBC # 加密 - def encrypt(self, content: bytes) -> bytes: + def encrypt(self, content: str) -> bytes: cipher = AES.new(self.key, self.mode, self.iv) - content_padded = pad(content, AES.block_size) + content_padded = pad(content.encode(), AES.block_size) encrypted_bytes = cipher.encrypt(content_padded) return encrypted_bytes # 解密 @@ -40,7 +39,7 @@ def main_sdga(): # 填入你的想解密的数据的 base64 编码 base64_encoded_data = "KSGm2qo7qVHz1wrK15PckYC5/kLjKcTtEXOgHeHt1Xn6DPdo3pltoPLADHpe8+Wq" - aes = AESPKCS7(aesKeyPrism, aesIVPrism) + aes = AESPKCS7(AES_KEY_SDGA_1_50, AES_IV_SDGA_1_50) # 首先解码 base64 decodedData = base64.b64decode(base64_encoded_data) @@ -55,7 +54,7 @@ def main_sdgb(): # 填入你的想解密的数据的 base64 编码 base64_encoded_data = "eJyrTVvpuGwCR32OdodwtVXZ7/Ofmfhin7k/K61q3XNoad1rAPGwECU=" - aes = AESPKCS7(aesKey2024, aesIV2024) + aes = AESPKCS7(AES_KEY_SDGB_1_40, AES_IV_SDGB_1_40) # 首先解码 base64 decodedData = base64.b64decode(base64_encoded_data)