feat(huya): 分身 CK 支持 cred0 解密补全,WSS 帧改为 JCE WebSocketCommand

- scripts/huya_clone_ck.py: root 读取小X分身/真身 WebView Cookie,默认
  用 AES-128-ECB(UDB 主密钥前 16B) 解 cred0 注入 udb_cred,新增
  --anon-device 补匿名设备字段、--no-cred0 退回旧行为
- core/huya/wss_client.py: 帧层改用浏览器 HUYA.WebSocketCommand(JCE)
  结构,vData 直接放 Wup 原包,按 WUP iRequestId 匹配响应,初始化顺序
  对齐 RegisterGroup→wsLaunch→VerifyCookie→getConfig→UpdateUserExps
- tests: 帧级断言改为新结构,假 WS 按 requestId 兑现
- docs: 新增分身 CK 提取、HAR 提取 CK 与积分中心说明

实测:四个分身 cred0 解出 udb_cred(39/43 字段),WSS
PlayMallUI.queryAllocation 返回 code=200、18 个商品;tests -k huya 394 passed
This commit is contained in:
yml2213
2026-10-26 11:23:29 +08:00
parent 6fc453017c
commit 03bc0818dd
9 changed files with 1188 additions and 156 deletions
+7 -16
View File
@@ -11,7 +11,7 @@ from core.huya.shop_structs import (
ShopCodeRsp,
)
from core.huya.taf_protocol import TafInputStream, TafOutputStream, TafType
from core.huya.wss_client import TAIL_BYTES, HuyaWssClient, WssCommand, WssMessage
from core.huya.wss_client import HuyaWssClient, WssCommand, WssMessage
from web.backend.services.huya_runner_core import HuyaBatchRunnerCore
@@ -108,9 +108,8 @@ def test_wss_requires_web_device_cookie_fields():
def test_activity_auth_frame_matches_latest_capture_layout():
"""对齐 9.1 活动 AUTH(828 连接)逐字段结构。
9.1: tag3 ZERO 首字段 -> tag0 uid -> tag1 UA -> tag2 cookie(STRING4)
-> tag3 STRING1 guid(32hex) -> tag4 INT8=1 -> tag5 "HUYA&ZH&2052"
-> tag6 "" -> TAIL_BYTES
2026-10-25 对齐 huya-go:tag0 uid -> tag1 UA -> tag2 cookie(STRING4)
-> tag3 STRING1 guid(32hex) -> tag4 INT32=1 -> tag5 "HUYA&ZH&2052"
"""
async def build_frame():
@@ -126,12 +125,9 @@ def test_activity_auth_frame_matches_latest_capture_layout():
message = WssMessage.decode(asyncio.run(build_frame()))
assert message.command == WssCommand.AUTH
assert message.sequence == 0x1D000109
assert message.body.endswith(TAIL_BYTES)
assert message.sequence == 0
stream = TafInputStream(message.body[: -len(TAIL_BYTES)])
# 首字段:tag3 ZERO(9.1 活动帧的占位字段)
assert stream.read_head() == (3, TafType.ZERO)
stream = TafInputStream(message.body)
assert stream.read_int64(0) == 1199664135026
assert stream.read_string(1) == "webh5&0.0.1&websocket&&diypc_52775"
assert stream.read_head() == (2, TafType.STRING4)
@@ -141,12 +137,8 @@ def test_activity_auth_frame_matches_latest_capture_layout():
# tag3 = STRING1 guid(9.1 中为 Cookie 里的 32hex guid)
guid = stream.read_string(3)
assert guid == "0a" * 16
assert stream.read_int8(4) == 1
assert stream.read_int32(4) == 1
assert stream.read_string(5) == "HUYA&ZH&2052"
assert stream.read_string(6) == ""
# body 必须与 9.1 828 AUTH 同样以 TAIL_BYTES 收尾
assert message.body[-len(TAIL_BYTES) :] == TAIL_BYTES
def test_activity_cookie_guid_is_replaced_by_launch_guid():
@@ -173,8 +165,7 @@ def test_activity_auth_accepts_explicit_launch_guid_over_cookie_guid():
return client.ws.send.call_args.args[0]
message = WssMessage.decode(asyncio.run(build_frame()))
stream = TafInputStream(message.body[: -len(TAIL_BYTES)])
assert stream.read_head() == (3, TafType.ZERO)
stream = TafInputStream(message.body)
stream.read_int64(0)
stream.read_string(1)
assert stream.read_head() == (2, TafType.STRING4)