From 472844474f3e3d41c865a70c9d72d72b4cb97a71 Mon Sep 17 00:00:00 2001 From: Remik1r3n Date: Wed, 11 Jun 2025 09:38:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E8=83=BD=E7=94=A8=E4=BA=86?= =?UTF-8?q?=20=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_TitleServer.py | 67 +++++++++++++++++++++++++++++++++++----------- HelperUserAll.py | 2 +- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/API_TitleServer.py b/API_TitleServer.py index 4496ad2..fc7227b 100644 --- a/API_TitleServer.py +++ b/API_TitleServer.py @@ -15,9 +15,9 @@ import certifi # 舞萌DX 2024 # omg it's leaking -AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@" -AesIV = ";;KjR1C3hgB1ovXa" -ObfuscateParam = "BEs2D5vW" +#AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@" +#AesIV = ";;KjR1C3hgB1ovXa" +#ObfuscateParam = "BEs2D5vW" # 2025 AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP bytes: - # if content is str, convert to bytes - #if isinstance(content, str): - # encodedData = content.encode('utf-8') + + def encrypt(self, content: bytes) -> bytes: cipher = AES.new(self.key, self.mode, self.iv) content_padded = pad(content, AES.block_size) encrypted_bytes = cipher.encrypt(content_padded) return encrypted_bytes - # 解密 - def decrypt(self, encrypted_content: bytes) -> str: + + def decrypt(self, content): cipher = AES.new(self.key, self.mode, self.iv) - decrypted_padded = cipher.decrypt(encrypted_content) + decrypted_padded = cipher.decrypt(content) decrypted = unpad(decrypted_padded, AES.block_size) return decrypted + def pkcs7unpadding(self, text): + length = len(text) + unpadding = ord(text[length - 1]) + return text[0:length - unpadding] + + def pkcs7padding(self, text): + bs = 16 + length = len(text) + bytes_length = len(text.encode('utf-8')) + padding_size = length if (bytes_length == length) else bytes_length + padding = bs - padding_size % bs + padding_text = chr(padding) * padding + return text + padding_text + def getSDGBApiHash(api): # API 的 Hash 的生成 # 有空做一下 Hash 的彩虹表? @@ -70,7 +80,32 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t """ maxRetries = 3 agentExtra = str(userAgentExtraData) - aes = AESPKCS7(AesKey, AesIV) + aes = aes_pkcs7(AesKey,AesIV) + + data = bytes(data, encoding="utf-8") + data_def = zlib.compress(data) + data_enc = aes.encrypt(data_def) + endpoint = "https://maimai-gm.wahlap.com:42081/Maimai2Servlet/" + r = httpx.post( + endpoint + getSDGBApiHash(targetApi), + headers = { + "User-Agent": f"{getSDGBApiHash(targetApi)}#{agentExtra}", + "Content-Type": "application/json", + "Mai-Encoding": "1.50", + "Accept-Encoding": "", + "Charset": "UTF-8", + "Content-Encoding": "deflate", + "Expect": "100-continue" + }, + data = data_enc + ) + resp_enc = r.content + try: + resp_def = aes.decrypt(resp_enc) + except: + resp_def = resp_enc + return zlib.decompress(resp_def).decode('utf-8') + # Begin Build requestDataFinal = aes.encrypt(zlib.compress(data.encode('utf-8'))) # End Build @@ -127,7 +162,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t logger.warning(f"解密失败,得到的原始响应: {responseContentRaw}") raise SDGBResponseError("解密失败") try: - responseDataFinal = zlib.decompress(responseContentDecrypted) + zlib.decompress(responseContentDecrypted).decode('utf-8') logger.debug("成功解压响应!") except: logger.warning(f"无法解压,解密的原始响应: {responseContentDecrypted}") @@ -136,7 +171,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t if not noLog: logger.debug(f"响应: {responseContentDecrypted}") - return responseContentDecrypted + return responseContentDecrypted.decode('utf-8') # 异常处理 except SDGBRequestError as e: diff --git a/HelperUserAll.py b/HelperUserAll.py index c17153a..244dfab 100644 --- a/HelperUserAll.py +++ b/HelperUserAll.py @@ -160,7 +160,7 @@ def generateUserAllData(userId, currentLoginResult, currentLoginTimestamp, curre "userGamePlaylogList": [ { "playlogId": currentLoginResult['loginId'], - "version": "1.41.00", + "version": "1.50.00", "playDate": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S') + '.0', "playMode": 0, "useTicketId": -1,