Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

寄中寄 #5

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 6 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -166,35 +157,19 @@ 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')
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)
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:
client_first = None
first_client_cache = client_first

# 其他服
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)
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:
client_other = None
other_client_cache = client_other
Expand Down
11 changes: 3 additions & 8 deletions pcr_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -144,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(
Expand Down
36 changes: 21 additions & 15 deletions playerpref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
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, pack_key):
def decrypt_xml(filename):
result = {}

with open(filename, 'r') as fp:
content = fp.read()

for re in finditer(r'<string name="(.*)">(.*)</string>', content):
g = re.groups()
try:
xml_key = _dec_key(g[0]).decode('utf8')
except Exception as _:
key = _dec_key(g[0]).decode('utf8')
val = _dec_val(key, g[1])
except:
continue
val = _dec_val(xml_key, g[1])
if xml_key == 'UDID':
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