Files
live-hub-py/core/huya/fingerprint/runner.js
T
yml2213 06a0a1e7d3 虎牙登录: 接入hydevice高信任设备指纹与App场景验证支持
- 新增 fingerprint/: node仿真Android WebView运行官方hydevice.js(含WASM加密), 产出与真机同构的高信任sdid
- 新增 device_fingerprint.py: py编排node runner获取sdid, 失败自动降级旧无指纹流程
- login.py: prepare_device优先高信任指纹; 增加App场景常量(appId=5008, appSign=md5(appId+verCode+appKey)[:8], 逆向自APK UdbNetHelper)
- solver: 支持appId/page_url/use_touch_events参数化(App模式); get3使用csid会话id; 识别qr_auth扫码(冷却)与dx_auth短信策略并抛专用异常
2026-08-23 17:32:34 +08:00

81 lines
3.6 KiB
JavaScript

// hydevice 指纹运行器: 仿真 Android WebView 环境 -> 真实请求 df/token + df/collect -> 输出 sdid
process.on('uncaughtException', e => { console.error('[uncaught]', String(e && e.message).slice(0, 120)); });
const fs = require('fs');
const path = require('path');
const https = require('https');
globalThis.window = globalThis;
require(path.join(__dirname, 'env.js')).makeEnv();
// ---- localStorage 持久化(设备稳定性) ----
const stateDir = process.argv[2] || '.';
try { fs.mkdirSync(stateDir, {recursive: true}); } catch (e) {}
const lsFile = path.join(stateDir, 'localstorage.json');
let _ls = {};
try { _ls = JSON.parse(fs.readFileSync(lsFile, 'utf8')); } catch (e) {}
globalThis.localStorage = {
getItem: k => (k in _ls ? _ls[k] : null),
setItem: (k, v) => { _ls[k] = String(v); try { fs.writeFileSync(lsFile, JSON.stringify(_ls)); } catch (e) {} },
removeItem: k => { delete _ls[k]; try { fs.writeFileSync(lsFile, JSON.stringify(_ls)); } catch (e) {} },
clear: () => { _ls = {}; try { fs.writeFileSync(lsFile, JSON.stringify(_ls)); } catch (e) {} },
key: i => Object.keys(_ls)[i] || null,
get length() { return Object.keys(_ls).length; },
};
globalThis.sessionStorage = {getItem: () => null, setItem(){}, removeItem(){}, clear(){}, key: () => null, get length(){ return 0; }};
// ---- 真实 XHR ----
function xhr(url, body, headers) {
return new Promise((resolve) => {
const u = new URL(url);
const data = body == null ? null : Buffer.from(String(body), 'utf8');
const req = https.request({
hostname: u.hostname, port: 443, path: u.pathname + u.search, method: 'POST',
headers: Object.assign({
'accept': 'application/json, text/javascript, */*; q=0.01',
'content-type': 'application/json',
'origin': 'https://aq.huya.com',
'referer': 'https://aq.huya.com/',
'user-agent': globalThis.navigator.userAgent,
'accept-language': 'zh-CN,zh;q=0.9',
}, headers || {}),
timeout: 15000,
}, res => {
let chunks = [];
res.on('data', c => chunks.push(c));
res.on('end', () => resolve({status: res.statusCode, text: Buffer.concat(chunks).toString('utf8')}));
});
req.on('timeout', () => { req.destroy(); resolve({status: 0, text: ''}); });
req.on('error', () => resolve({status: 0, text: ''}));
if (data) req.write(data);
req.end();
});
}
globalThis.XMLHttpRequest = class {
open(m, u){ this._m = m; this._u = u; this._h = {}; }
setRequestHeader(k, v){ this._h[k] = v; }
getAllResponseHeaders(){ return ''; }
addEventListener(t, f){ if (t === 'load' || t === 'readystatechange') this._on = f; }
send(d){
xhr(this._u, d, this._h).then(r => {
this.status = r.status; this.readyState = 4;
this.responseText = r.text; this.response = r.text;
const done = () => {
if (String(this._u).includes('/collect')) {
try {
const j = JSON.parse(r.text);
if (j && j.data && j.data.sdid) { console.log('__SDID__' + j.data.sdid); setTimeout(() => process.exit(0), 200); }
} catch (e) {}
}
try { this.onreadystatechange && this.onreadystatechange(); } catch (e) {}
try { this._on && this._on(); } catch (e) {}
try { this.onload && this.onload(); } catch (e) {}
};
setTimeout(done, 30);
});
}
};
eval(fs.readFileSync(path.join(__dirname, 'hydevice-prod-1.2.45-min.js'), 'utf8'));
try { globalThis.initFingerprint(process.argv[3] || '5008'); } catch (e) { console.error('[init]', e.message.slice(0, 120)); }
setTimeout(() => { console.error('__TIMEOUT__'); process.exit(2); }, 25000);