fix(sockets): 探针 WS 字节读取兼容 DataView(此前 hex 恒为空)

游戏实际发的是 DataView(有 byteLength、无 slice),走 buffer+byteOffset 取视图;此前 new Uint8Array(dataView,0,24) 得到长度 0 视图,导致 SEND 行 hex 恒空。
This commit is contained in:
TermiNexus committed 2026-10-12 10:35:39 +08:00
1 parent 712d24e059
commit e154c1ab14
1 file changed
+12 -2
+12 -2
View File
@@ -69,8 +69,18 @@
Buf.push('[+' + Now() + 'ms] SEND blob len=' + size + ' hex=' + Hex(new Uint8Array(ab)));
}).catch(function () {});
} else if (d && d.byteLength !== undefined) {
var u = new Uint8Array(d.slice ? d.slice(0, 24) : d, 0, Math.min(24, d.byteLength));
Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + Hex(u));
// 注意:游戏实际发的是 DataView / TypedArray / ArrayBuffer(实测 DataView),
// 且有 .byteLength 但没有 .slice —— 必须走 buffer+byteOffset 取视图,
// 否则 new Uint8Array(dataView, 0, 24) 会得到长度 0 的视图(hex 恒为空)。
var View;
if (d.buffer && typeof d.byteOffset === 'number') {
View = new Uint8Array(d.buffer, d.byteOffset, Math.min(24, d.byteLength));
} else if (typeof d.slice === 'function') {
View = new Uint8Array(d.slice(0, 24));
} else {
View = new Uint8Array(d, 0, Math.min(24, d.byteLength));
}
Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + Hex(View));
}
} catch (e) {}
return Orig.apply(this, arguments);