From 75699b7a653bf45a1569b787c5ec190d0d2585b6 Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 08:53:06 +0800 Subject: [PATCH 1/7] Update main.py --- main.py | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index f5c3b18..1344627 100644 --- a/main.py +++ b/main.py @@ -147,15 +147,6 @@ def judge_file(cx_id: int): else: return False - -# 通过判断新字段的有无来判断是否是新配置 -def get_true_query_id(ac_info): - short_udid = ac_info['SHORT_UDID_lowBits'] if 'SHORT_UDID_lowBits' in ac_info else ac_info['SHORT_UDID'] - viewer_id = ac_info['VIEWER_ID_lowBits'] if 'VIEWER_ID_lowBits' in ac_info else ac_info['VIEWER_ID'] - is_new = True if 'SHORT_UDID_lowBits' in ac_info else False - return short_udid, viewer_id, is_new - - # 获取配置文件 def get_client(): global first_client_cache, other_client_cache @@ -167,16 +158,8 @@ def get_client(): if first_client_cache is None: if judge_file(1): ac_info_first = decrypt_xml(join(curPath, 'first_tw.sonet.princessconnect.v2.playerprefs.xml'), 'i') - short_udid_first, viewer_id_first, is_new_first = get_true_query_id(ac_info_first) - # 如果是新的就换用key重新unpack - if is_new_first: - sv.logger.info('当前[台服1服]配置文件使用的是【新版】用户文件') - ac_info_first = decrypt_xml(join(curPath, 'first_tw.sonet.princessconnect.v2.playerprefs.xml'), 'I') - short_udid_first, viewer_id_first, is_new_first = get_true_query_id(ac_info_first) - else: - sv.logger.info('当前[台服1服]配置文件使用的是【旧版】用户文件') - client_first = pcr_client(ac_info_first['UDID'], short_udid_first, viewer_id_first, - ac_info_first['TW_SERVER_ID'], pInfo['proxy'], is_new_first) + client_first = pcr_client(ac_info_first['UDID'], ac_info_first['SHORT_UDID'], ac_info_first['VIEWER_ID'], + ac_info_first['TW_SERVER_ID'], pInfo['proxy']) else: client_first = None first_client_cache = client_first @@ -185,16 +168,8 @@ def get_client(): if other_client_cache is None: if judge_file(0): ac_info_other = decrypt_xml(join(curPath, 'other_tw.sonet.princessconnect.v2.playerprefs.xml'), 'i') - short_udid_other, viewer_id_other, is_new_other = get_true_query_id(ac_info_other) - # 如果是新的就换用key重新unpack - if is_new_other: - sv.logger.info('当前[台服其他服]配置文件使用的是【新版】用户文件') - ac_info_other = decrypt_xml(join(curPath, 'other_tw.sonet.princessconnect.v2.playerprefs.xml'), 'I') - short_udid_other, viewer_id_other, is_new_other = get_true_query_id(ac_info_other) - else: - sv.logger.info('当前[台服其他服]配置文件使用的是【旧版】用户文件') - client_other = pcr_client(ac_info_other['UDID'], short_udid_other, viewer_id_other, - ac_info_other['TW_SERVER_ID'], pInfo['proxy'], is_new_other) + client_other = pcr_client(ac_info_other['UDID'], ac_info_other['SHORT_UDID'], ac_info_other['VIEWER_ID'], + ac_info_other['TW_SERVER_ID'], pInfo['proxy']) else: client_other = None other_client_cache = client_other From 985481d4e19fc4ed600197d9ffe51f216963d9a4 Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 08:54:16 +0800 Subject: [PATCH 2/7] Update pcr_client.py --- pcr_client.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pcr_client.py b/pcr_client.py index 3839687..c7921db 100644 --- a/pcr_client.py +++ b/pcr_client.py @@ -75,12 +75,8 @@ class pcr_client: def _makemd5(data_str) -> str: return md5((data_str + 'r!I@nt8e5i=').encode('utf8')).hexdigest() - def __init__(self, udid, short_udid, viewer_id, platform, proxy, is_new): - # 如果是旧配置ID就需要加上服务器编号 - viewer_id = viewer_id if is_new else platform + viewer_id - # 如果是旧配置short_udid就需要加上服务器编号 - self.short_udid = short_udid if is_new else platform + short_udid - self.is_new = is_new + def __init__(self, udid, short_udid, viewer_id, platform, proxy): + self.short_udid = short_udid self.viewer_id = viewer_id self.udid = udid self.proxy = proxy @@ -93,7 +89,7 @@ def __init__(self, udid, short_udid, viewer_id, platform, proxy, is_new): self.headers = json.load(f) self.headers['SID'] = pcr_client._makemd5(viewer_id + udid) # 如果是旧配置服务器就要设置为2,新版需要设置为1 - self.headers['platform'] = '1' if is_new else '2' + self.headers['platform'] = 2 @staticmethod def create_key() -> bytes: From 2a310dec8089e99e400f9211ececae3500a3780c Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 08:54:55 +0800 Subject: [PATCH 3/7] Update playerpref.py --- playerpref.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/playerpref.py b/playerpref.py index 73b7eb7..bbb4baa 100644 --- a/playerpref.py +++ b/playerpref.py @@ -18,24 +18,33 @@ def _dec_val(k, s): return bytes([key2[i % len(key2)] ^ b[i] for i in range(len(b))]) -def decrypt_xml(filename, pack_key): +def decrypt_xml(filename): result = {} with open(filename, 'r') as fp: content = fp.read() - for re in finditer(r'(.*)', content): g = re.groups() try: - xml_key = _dec_key(g[0]).decode('utf8') - except Exception as _: + key = _deckey(g[0]).decode('utf8') + except: continue - val = _dec_val(xml_key, g[1]) - if xml_key == 'UDID': + val = _decval(key, g[1]) + if key == 'UDID': val = ''.join([chr(val[4 * i + 6] - 10) for i in range(36)]) + elif key == 'SHORT_UDID_lowBits': + val = str(unpack('I', val)[0]) + key = 'SHORT_UDID' + elif key == 'VIEWER_ID_lowBits': + val = str(unpack('I', val)[0]) + key = 'VIEWER_ID' elif len(val) == 4: - val = str(unpack(pack_key, val)[0]) - result[xml_key] = val - # except: + val = str(unpack('i', val)[0]) + result[key] = val + #except: # pass + if len(result['VIEWER_ID'])==9: + result['VIEWER_ID'] = result['TW_SERVER_ID']+result['VIEWER_ID'] + if len(result['SHORT_UDID'])==9: + result['SHORT_UDID'] = result['TW_SERVER_ID']+result['SHORT_UDID'] return result From 9e7beef67634f3e66395b6a9fa2af584c010c01f Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 08:55:59 +0800 Subject: [PATCH 4/7] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 1344627..c179f84 100644 --- a/main.py +++ b/main.py @@ -157,7 +157,7 @@ def get_client(): # 1服 if first_client_cache is None: if judge_file(1): - ac_info_first = decrypt_xml(join(curPath, 'first_tw.sonet.princessconnect.v2.playerprefs.xml'), 'i') + ac_info_first = decrypt_xml(join(curPath, 'first_tw.sonet.princessconnect.v2.playerprefs.xml')) client_first = pcr_client(ac_info_first['UDID'], ac_info_first['SHORT_UDID'], ac_info_first['VIEWER_ID'], ac_info_first['TW_SERVER_ID'], pInfo['proxy']) else: @@ -167,7 +167,7 @@ def get_client(): # 其他服 if other_client_cache is None: if judge_file(0): - ac_info_other = decrypt_xml(join(curPath, 'other_tw.sonet.princessconnect.v2.playerprefs.xml'), 'i') + ac_info_other = decrypt_xml(join(curPath, 'other_tw.sonet.princessconnect.v2.playerprefs.xml')) client_other = pcr_client(ac_info_other['UDID'], ac_info_other['SHORT_UDID'], ac_info_other['VIEWER_ID'], ac_info_other['TW_SERVER_ID'], pInfo['proxy']) else: From d5f392a868bcb9480d7a63a8c18a4a6165ef0ff7 Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 09:01:48 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=90=8D=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E5=8F=AF=E8=BF=98=E8=A1=8C=EF=BC=8C=E5=AF=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playerpref.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/playerpref.py b/playerpref.py index bbb4baa..32647ce 100644 --- a/playerpref.py +++ b/playerpref.py @@ -2,23 +2,18 @@ from re import finditer from base64 import b64decode from struct import unpack - key = b'e806f6' - - -def _dec_key(s) -> bytes: +def _dec_key(s) -> str: b = b64decode(unquote(s)) return bytes([key[i % len(key)] ^ b[i] for i in range(len(b))]) - def _dec_val(k, s): b = b64decode(unquote(s)) key2 = k.encode('utf8') + key b = b[0:len(b) - (11 if b[-5] != 0 else 7)] return bytes([key2[i % len(key2)] ^ b[i] for i in range(len(b))]) - -def decrypt_xml(filename): +def decryptxml(filename): result = {} with open(filename, 'r') as fp: @@ -26,10 +21,10 @@ def decrypt_xml(filename): for re in finditer(r'(.*)', content): g = re.groups() try: - key = _deckey(g[0]).decode('utf8') + key = _dec_key(g[0]).decode('utf8') + val = _dec_val(key, g[1]) except: continue - val = _decval(key, g[1]) if key == 'UDID': val = ''.join([chr(val[4 * i + 6] - 10) for i in range(36)]) elif key == 'SHORT_UDID_lowBits': @@ -48,3 +43,5 @@ def decrypt_xml(filename): if len(result['SHORT_UDID'])==9: result['SHORT_UDID'] = result['TW_SERVER_ID']+result['SHORT_UDID'] return result + + From c8011519e1effa64412b505b107c8728d408168e Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 09:02:32 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=B0=E8=80=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=83=BD=E8=A6=81=E5=B8=A6twserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pcr_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pcr_client.py b/pcr_client.py index c7921db..6751e8f 100644 --- a/pcr_client.py +++ b/pcr_client.py @@ -140,7 +140,6 @@ async def callapi(self, api_url: str, request: dict, noerr: bool = False): try: if self.viewer_id is not None: request['viewer_id'] = b64encode(self.encrypt(str(self.viewer_id), key)) - if not self.is_new: request['tw_server_id'] = str(self.platform) packed, crypto = self.pack(request, key) self.headers['PARAM'] = sha1( From dc823e8757ae0c6fec25cc3ec4e57e44a9de642d Mon Sep 17 00:00:00 2001 From: layvsan <81149534+layvsan@users.noreply.github.com> Date: Sun, 18 Jun 2023 09:05:35 +0800 Subject: [PATCH 7/7] Update playerpref.py --- playerpref.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playerpref.py b/playerpref.py index 32647ce..00142f1 100644 --- a/playerpref.py +++ b/playerpref.py @@ -13,7 +13,7 @@ def _dec_val(k, s): b = b[0:len(b) - (11 if b[-5] != 0 else 7)] return bytes([key2[i % len(key2)] ^ b[i] for i in range(len(b))]) -def decryptxml(filename): +def decrypt_xml(filename): result = {} with open(filename, 'r') as fp: