From cbf23737cdc2d8fe09efa53e38fa0a815cab8d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Mon, 14 Nov 2022 15:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Update=20hex=5Fdigest=20for=20re?= =?UTF-8?q?quests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/apihelper/helpers.py | 8 ++++---- utils/patch/genshin.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/apihelper/helpers.py b/modules/apihelper/helpers.py index 0098ee5d..0c084d06 100644 --- a/modules/apihelper/helpers.py +++ b/modules/apihelper/helpers.py @@ -18,11 +18,11 @@ RECOGNIZE_SERVER = { } -def get_device_id(name: str = None): +def get_device_id(name: str = ""): return str(uuid.uuid3(uuid.NAMESPACE_URL, name)) -def _hexdigest(text): +def hex_digest(text): _md5 = hashlib.md5() # nosec B303 _md5.update(text.encode()) return _md5.hexdigest() @@ -43,13 +43,13 @@ def get_ds(ds_type: str = None, new_ds: bool = False, data: Mapping[str, str] = r = str(random.randint(100001, 200000)) # nosec b = json.dumps(data) if data else '' q = urlencode(params) if params else '' - c = _hexdigest(f'salt={salt}&t={t}&r={r}&b={b}&q={q}') + c = hex_digest(f'salt={salt}&t={t}&r={r}&b={b}&q={q}') return f'{t},{r},{c}' def old(): t = str(int(time.time())) r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) - c = _hexdigest(f'salt={salt}&t={t}&r={r}') + c = hex_digest(f'salt={salt}&t={t}&r={r}') return f'{t},{r},{c}' app_version = '2.36.1' diff --git a/utils/patch/genshin.py b/utils/patch/genshin.py index 61740b51..bade5c2f 100644 --- a/utils/patch/genshin.py +++ b/utils/patch/genshin.py @@ -7,9 +7,10 @@ from genshin import constants, types from genshin.client import routes from genshin.utility import ds -from modules.apihelper.helpers import get_ds, get_ua, get_device_id +from modules.apihelper.helpers import get_ds, get_ua, get_device_id, hex_digest from utils.patch.methods import patch, patchable +DEVICE_ID = get_device_id() @patch(genshin.client.components.calculator.CalculatorClient) # noqa class CalculatorClient: @@ -79,8 +80,13 @@ class BaseClient: "ds": ds.generate_dynamic_secret(), } elif region == types.Region.CHINESE: + uid = self.cookie_manager.get_user_id() + if uid: + device_id = hex_digest(str(uid)) + else: + device_id = DEVICE_ID _app_version, _client_type, _ds = get_ds(new_ds=True, data=data, params=params) - ua = get_ua(version=_app_version) + ua = get_ua(device="Paimon Build " + device_id[0:5], version=_app_version) headers = { "User-Agent": ua, "X_Requested_With": "com.mihoyo.hoyolab",