feat(flash-transfer): QQ flash transfer (fileset) upload, share, download (#113)

* feat(proto-defs): add flash-transfer OIDB proto types

QQ 闪传(FlashTransfer / fileset)的 protobuf 类型定义:
- FlashFileEntry(0x93d2/0x93d3 文件条目)
- 0x93cf 申请 fileSet / 0x93d0 commit / 0x93db 完成 / 0x93d1 设状态
- 0x93d3 文件集详情 / 0x93d4 下载 URL(含主文件 fileId + 缩略图)
- 0x12a9 sub=100/103/200 prepare/apply/get-download
- sliceupload body + Sha1StateV
- 0x9407 删除 / 0x9427 重命名 / 0x93d7 发送
注册到 oidb-actions/index.ts,package.json 加 exports。

* feat(protocol): add flash-transfer OIDB services + sha1-stream

闪传协议层(OIDB namespace,复用 invokeOidb/OidbCallSpec):
- apply-fileset / commit-file / complete-fileset / set-status(上传流程)
- prepare-upload (0x12a9_100) / apply-upload (0x12a9_103)(sliceupload 凭证)
- get-fileset-detail (0x93d3) / list-filesets (0x93d2) / get-download-url (0x93d4)
- get-flash-download (0x12a9_200,主文件下载直链)
- delete-file (0x9407) / rename-file (0x9427,sub=0+uinForm) / send-flash (0x93d7)
- sha1-stream:SHA1 中间 state 计算器(sliceupload f107.f6 需要,Node crypto 不支持)
- byte-oracle 单测(apply/prepare/get-download-url/send-flash)+ sha1-stream 单测
package.json 加 exports。

* feat(core): add FlashTransferApi facade

FlashTransferApi 编排闪传全流程,复用 OIDB 基础设施(invokeOidb)+
computeHashes/loadBinarySource/fetch:
- createFlashTask:统一走 sub=100/103+sliceupload(含缩略图),不走小文件 PUT
  (PUT 不上报主文件 sha1,fileset 卡在未完成;QQ 客户端小文件也走 sliceupload)
- buildFileId:主文件 appid=14901(进 f14.f1),缩略图 png=14903/jpg=14902
- uploadThumbnail:随机纯色 PNG 占位(手写编码,不引入图像库),关联主文件下载入口
- getFilesetInfo/getFlashFileList/getShareLink/getFlashFileUrl/downloadFileset
- sendFlashMsg(私聊 uid / 群聊 groupId)/ getFilesetIdByCode(网页解析)
- deleteFlashFile / renameFlashFile / listFilesets
注册到 ApiHub(flashTransfer 字段)+ export。

* feat(onebot): add flash-transfer actions

OneBot action(extended.ts)10 个:
create_flash_task / get_fileset_info / get_flash_file_list /
get_flash_file_url / get_share_link / download_fileset /
send_flash_msg(私聊 user_id / 群聊 group_id)/ get_fileset_id /
rename_flash_file / delete_flash_file
MCP catalog(生成文件)同步新增 action 元数据。
extended-actions 接线单测覆盖。

* fix(onebot): align flash file list field name with NapCat

flashFileInfoToJson 的文件大小字段从 file_size 改为 size,对齐 NapCat
get_flash_file_list 响应(NapCat 用 size)。get_fileset_info 的 file_list
复用同一映射,一并生效。便于 NapCat 客户端 drop-in 迁移。

* feat(proto-defs): support multi-file commit in flash-transfer

0x93d0 commit 的 f4 改为 repeated,一个请求携带 fileset 内全部文件条目。
FlashCommitFileInfo 的 f3/f5/f6/f7/f10/f12 用 pb_optional,强制 0 值上 wire
(服务端多文件时严格校验字段存在,省略 0 会导致后续文件不计入 fileset)。

* feat(protocol): parameterize flash-transfer upload for multi-file

CommitFile.Params 改为 entries 数组,serialize 输出 repeated f4,每条 f6=文件序号。
PrepareUpload/ApplyUpload 加 fileIndex + formatCode 参数:filesetWrap.f4 用 fileIndex
(与 commit f6 对齐),f7 用 formatCode(mp4=2 非 26),f9=1。

* feat(core): multi-file flash-transfer upload

createFlashTask 支持多文件共用一个 fileset。关键改动:
- ApplyFileset 多文件时 fileName 用「<首文件名>等N个文件」、fileSize 用总和,
  服务端据此判定 fileset 为多文件,commit 的后续 entry 才被计入
- 一次性 CommitFile 提交所有文件元数据(f4 repeated)
- 两阶段上传:先全部 prepare+apply 注册 fileId,再全部 sliceupload 落盘
- 拆分原 uploadLargeFile 为 prepareAndApply + sliceuploadFile
- fileTypeCode mp4 formatCode 26→2(与 commit f7/filesetWrap.f7 一致)

* feat(onebot): multi-file create_flash_task + list_filesets action

create_flash_task 的 files 参数支持 string 或 string[],多文件共用一个 fileset。
新增 list_filesets action(facade.listFilesets 之前未暴露)。MCP catalog 同步更新
files schema(anyOf string/array)与 list_filesets 条目。

* fix(flash-transfer): multi-file download by fileIndex

0x93d4 响应 f1.f3 是 repeated fileInfo(多文件 fileset 每个文件一条,f6=序号、
f14=主文件 fileId),之前定义成单个导致多文件只能拿到第一个文件。
FlashDownloadEntry.fileInfo 改 pb_repeated,GetDownloadUrl 返回所有文件元信息,
download_fileset 按 fileIndex 选中目标文件走 0x12a9 sub=200 拿直链。

* test(protocol): inline byte-oracle hex fixtures

两个 flash-transfer byte-oracle 测试原先用 readFileSync 读仓库外的
.claude/reverse/scripts/proto/*.hex(本地逆向笔记目录),CI 上不存在导致失败。
把 hex 内容内联成常量,测试自包含。

* fix(flash-transfer): address review feedback

1. get_flash_file_url 接 file_index 参数并在 action 透传(之前漏接,多文件永远返回首文件)
2. getFileDownload 越界 fileIndex 不再静默回退首文件,找不到返回 null
3. postSliceupload status 缺失不再当成功,非 success 一律抛错
4. computeSha1StateV 改 O(n) 增量 update(之前每片 reset 重算整个前缀,O(n²))
5. get_flash_file_url 找不到文件抛错(之前返回空串当成功)
6. create_flash_task files 数组拒绝空字符串
This commit is contained in:
Qiao authored and GitHub committed 2026-06-21 14:24:51 +08:00
1 parent ebadfb968b
commit 127f2cd2d6
29 files changed
+3213 -20

No files matched your search

+56
View File
@@ -72,6 +72,58 @@
"types": "./src/oidb-services/custom-face/order-custom-face.ts",
"default": "./src/oidb-services/custom-face/order-custom-face.ts"
},
"./oidb-services/flash-transfer/get-fileset-detail": {
"types": "./src/oidb-services/flash-transfer/get-fileset-detail.ts",
"default": "./src/oidb-services/flash-transfer/get-fileset-detail.ts"
},
"./oidb-services/flash-transfer/list-filesets": {
"types": "./src/oidb-services/flash-transfer/list-filesets.ts",
"default": "./src/oidb-services/flash-transfer/list-filesets.ts"
},
"./oidb-services/flash-transfer/get-download-url": {
"types": "./src/oidb-services/flash-transfer/get-download-url.ts",
"default": "./src/oidb-services/flash-transfer/get-download-url.ts"
},
"./oidb-services/flash-transfer/delete-file": {
"types": "./src/oidb-services/flash-transfer/delete-file.ts",
"default": "./src/oidb-services/flash-transfer/delete-file.ts"
},
"./oidb-services/flash-transfer/rename-file": {
"types": "./src/oidb-services/flash-transfer/rename-file.ts",
"default": "./src/oidb-services/flash-transfer/rename-file.ts"
},
"./oidb-services/flash-transfer/apply-fileset": {
"types": "./src/oidb-services/flash-transfer/apply-fileset.ts",
"default": "./src/oidb-services/flash-transfer/apply-fileset.ts"
},
"./oidb-services/flash-transfer/commit-file": {
"types": "./src/oidb-services/flash-transfer/commit-file.ts",
"default": "./src/oidb-services/flash-transfer/commit-file.ts"
},
"./oidb-services/flash-transfer/complete-fileset": {
"types": "./src/oidb-services/flash-transfer/complete-fileset.ts",
"default": "./src/oidb-services/flash-transfer/complete-fileset.ts"
},
"./oidb-services/flash-transfer/set-status": {
"types": "./src/oidb-services/flash-transfer/set-status.ts",
"default": "./src/oidb-services/flash-transfer/set-status.ts"
},
"./oidb-services/flash-transfer/apply-upload": {
"types": "./src/oidb-services/flash-transfer/apply-upload.ts",
"default": "./src/oidb-services/flash-transfer/apply-upload.ts"
},
"./oidb-services/flash-transfer/prepare-upload": {
"types": "./src/oidb-services/flash-transfer/prepare-upload.ts",
"default": "./src/oidb-services/flash-transfer/prepare-upload.ts"
},
"./oidb-services/flash-transfer/send-flash": {
"types": "./src/oidb-services/flash-transfer/send-flash.ts",
"default": "./src/oidb-services/flash-transfer/send-flash.ts"
},
"./oidb-services/flash-transfer/get-flash-download": {
"types": "./src/oidb-services/flash-transfer/get-flash-download.ts",
"default": "./src/oidb-services/flash-transfer/get-flash-download.ts"
},
"./oidb-services/interaction/send-poke": {
"types": "./src/oidb-services/interaction/send-poke.ts",
"default": "./src/oidb-services/interaction/send-poke.ts"
@@ -380,6 +432,10 @@
"types": "./src/highway/utils.ts",
"default": "./src/highway/utils.ts"
},
"./highway/sha1-stream": {
"types": "./src/highway/sha1-stream.ts",
"default": "./src/highway/sha1-stream.ts"
},
"./highway/pipeline": {
"types": "./src/highway/pipeline.ts",
"default": "./src/highway/pipeline.ts"
@@ -0,0 +1,112 @@
// 流式 SHA1 计算器,支持输出中间 state(不 finalize)。
// 闪传 sliceupload 的 f107.f6 (Sha1StateV) 需要每片对应的累积 SHA1 中间 state,
// Node.js 内置 crypto 只能算完整 digest,这里自行实现 transform 以暴露中间 state。
import { createHash } from 'node:crypto';
const SHA1_BLOCK_SIZE = 64;
const SHA1_DIGEST_SIZE = 20;
function rotl(x: number, n: number): number {
return ((x << n) | (x >>> (32 - n))) >>> 0;
}
export class Sha1Stream {
private readonly state = new Uint32Array(5);
private readonly count = new Uint32Array(2); // [low, high] bit count
private readonly buffer = new Uint8Array(SHA1_BLOCK_SIZE);
constructor() { this.reset(); }
reset(): void {
this.state[0] = 0x67452301;
this.state[1] = 0xEFCDAB89;
this.state[2] = 0x98BADCFE;
this.state[3] = 0x10325476;
this.state[4] = 0xC3D2E1F0;
this.count[0] = 0;
this.count[1] = 0;
}
private transform(data: Uint8Array, offset: number): void {
const w = new Uint32Array(80);
const dv = new DataView(data.buffer, data.byteOffset + offset, 64);
for (let i = 0; i < 16; i++) w[i] = dv.getUint32(i * 4, false); // big-endian
for (let i = 16; i < 80; i++) {
w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
}
let a = this.state[0], b = this.state[1], c = this.state[2], d = this.state[3], e = this.state[4];
for (let i = 0; i < 80; i++) {
let temp: number;
if (i < 20) temp = ((b & c) | (~b & d)) + 0x5A827999;
else if (i < 40) temp = (b ^ c ^ d) + 0x6ED9EBA1;
else if (i < 60) temp = ((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC;
else temp = (b ^ c ^ d) + 0xCA62C1D6;
temp = (temp + rotl(a, 5) + e + w[i]) >>> 0;
e = d; d = c; c = rotl(b, 30); b = a; a = temp;
}
this.state[0] = (this.state[0] + a) >>> 0;
this.state[1] = (this.state[1] + b) >>> 0;
this.state[2] = (this.state[2] + c) >>> 0;
this.state[3] = (this.state[3] + d) >>> 0;
this.state[4] = (this.state[4] + e) >>> 0;
}
update(data: Uint8Array): void {
const len = data.length;
let index = (this.count[0] >>> 3) & 0x3F;
this.count[0] = (this.count[0] + (len << 3)) >>> 0;
if (this.count[0] < (len << 3)) this.count[1] = (this.count[1] + 1) >>> 0;
this.count[1] = (this.count[1] + (len >>> 29)) >>> 0;
let partLen = SHA1_BLOCK_SIZE - index;
let i = 0;
if (len >= partLen) {
this.buffer.set(data.subarray(0, partLen), index);
this.transform(this.buffer, 0);
i = partLen;
while (i + SHA1_BLOCK_SIZE <= len) {
this.transform(data, i);
i += SHA1_BLOCK_SIZE;
}
index = 0;
}
this.buffer.set(data.subarray(i), index);
}
/** 输出当前 state(20B)。littleEndian=true 小端,false 大端。不 finalize。 */
hash(littleEndian: boolean): Uint8Array {
const digest = new Uint8Array(SHA1_DIGEST_SIZE);
const dv = new DataView(digest.buffer);
for (let i = 0; i < 5; i++) {
if (littleEndian) dv.setUint32(i * 4, this.state[i], true);
else dv.setUint32(i * 4, this.state[i], false);
}
return digest;
}
}
/**
* 计算闪传 sliceupload 的 Sha1StateV(累积 SHA1 state list)。
* states[i] = SHA1 中间 state(从初始 state 处理 file[0:(i+1)*sliceSize] 后,无 finalize,小端 20B)。
* 最后一片 states[last] = 标准整文件 SHA1(有 finalize)。
*
* 用单个 Sha1Stream 增量 update:每片只喂新增的 sliceSize 字节再快照,O(n)。
* (sliceSize=1MB 是 SHA1 块大小 64B 的整数倍,增量 update 不会残留半块。)
*/
export function computeSha1StateV(bytes: Uint8Array, sliceCount: number, sliceSize: number): Uint8Array[] {
const states: Uint8Array[] = [];
const sha1 = new Sha1Stream();
for (let i = 0; i < sliceCount; i++) {
const start = i * sliceSize;
const end = Math.min(start + sliceSize, bytes.length);
sha1.update(bytes.subarray(start, end));
if (i !== sliceCount - 1) {
states.push(sha1.hash(true)); // 小端中间 state,不 finalize
} else {
// 最后一片:标准整文件 SHA1(有 finalize)
states.push(new Uint8Array(createHash('sha1').update(Buffer.from(bytes)).digest()));
}
}
return states;
}
@@ -0,0 +1,66 @@
// OIDB 0x93cf_1 — 申请创建 fileSet(上传起点)。
// 请求 f1=1, f2=FileInfo{filename,origName,type=1,size,uploader}, f3=类型码, f12=1。
// 响应 f1=filesetUuid, f2=uploadKey(同f1), f3=上传URL(qfile.qq.com/q/<code>), f4=expire, f5=ttl。
// subCommand=1, reserved=0(真客户端 envelope 实测确认)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashApplyFilesetReq,
FlashApplyFilesetResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface FlashUploaderInfo {
uin: string;
nickname: string;
uid: string;
}
export namespace ApplyFileset {
export const command = 0x93cf;
export const subCommand = 1;
export interface Params {
fileName: string;
origName: string;
fileSize: number;
/** 文件类型码:rar=2, png/mp4=7。 */
typeCode: number;
uploader: FlashUploaderInfo;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashApplyFilesetReq => ({
field1: 1,
fileInfo: {
fileName: p.fileName,
origName: p.origName,
fileType: 1,
fileSize: BigInt(p.fileSize),
uploader: {
uin: p.uploader.uin,
nickname: p.uploader.nickname,
uid: p.uploader.uid,
field4: {},
},
field16: 1,
field20: 0,
field21: 0,
},
typeCode: p.typeCode,
field12: 1,
});
export const deserialize = (_ctx: Deps, body: FlashApplyFilesetResp): FlashApplyFilesetResp => body;
export const encode = (env: OidbBase<FlashApplyFilesetReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashApplyFilesetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashApplyFilesetResp> =>
protobuf_decode<OidbBase<FlashApplyFilesetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<FlashApplyFilesetResp> =>
invokeOidb(deps, ApplyFileset, params);
}
@@ -0,0 +1,98 @@
// OIDB 0x12a9_103 — apply-upload(注册 fileId,sliceupload 前调用)。
// uinForm=true。带 MD5 + 客户端构造的 fileId。响应无 rkey(rkey 来自 sub=100)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashApplyUploadReq,
FlashApplyUploadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 100;
export namespace ApplyUpload {
export const command = 0x12a9;
export const subCommand = 103;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string;
fileId: string; // 来自 sub=100 响应
fileName: string;
fileSize: number;
md5: string; // 32 hex
sha1: string; // 40 hex
/** fileset 内序号(1,2,3...),与 0x93d0 commit f6 一致。 */
fileIndex: number;
/** 格式码:与 commit f7 一致(mp4=2, rar/zip=4)。主文件 filesetWrap.f7 用此值;
* 缩略图固定 png=26/jpg=2。 */
formatCode: number;
/** 缩略图类型:undefined=主文件, 'png'=png 缩略图, 'jpg'=jpg 缩略图。 */
thumbType?: 'png' | 'jpg';
width?: number;
height?: number;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashApplyUploadReq => {
// 缩略图与主文件字段差异:config.f103、FileInfo.f5.f1/f6/f7/f9、
// filesetWrap.f4/f5/f6/f7/f9。filesetWrap.f4 统一用 fileIndex。
const isThumb = p.thumbType !== undefined;
const isJpg = p.thumbType === 'jpg';
return {
head: {
sub: { seq: seqCounter++, sub: 103 },
config: { field101: 2, field102: 4, field103: isThumb ? (isJpg ? 24 : 23) : 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: p.fileSize,
md5: p.md5,
sha1: p.sha1,
fileName: p.fileName,
field5: { field1: isJpg ? 1 : 0, field2: 0, field3: 0, field4: 0 },
field6: p.width ?? 0,
field7: p.height ?? 0,
field8: 0,
field9: isJpg ? 0 : 1,
},
fileId: p.fileId,
field3: 1,
field4: Math.floor(Date.now() / 1000),
field5: 1209600, // TTL 14 天
field6: 0,
},
flag2: { field1: 2 },
field3: { field1: 0, field2: 0, field3: 0, field4: {} },
filesetWrap: {
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
fileUuid: p.fileUuid,
field4: p.fileIndex,
field5: isThumb && !isJpg ? 1 : 0, // png=1, jpg/mp4=0
field6: isThumb ? (isJpg ? 1 : 0) : 0, // png缩略图=0, jpg缩略图=1, 主文件=0
field7: isThumb ? (isJpg ? 2 : 26) : p.formatCode, // 主文件=formatCode(mp4=2), png缩略图=26, jpg缩略图=2
field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
};
export const deserialize = (_ctx: Deps, _body: FlashApplyUploadResp): void => {
// sub=103 resp f12={f1:filesetWrap}(注册确认,无 rkey)。rkey 来自 sub=100。
};
export const encode = (env: OidbBase<FlashApplyUploadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashApplyUploadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashApplyUploadResp> =>
protobuf_decode<OidbBase<FlashApplyUploadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, ApplyUpload, params);
}
@@ -0,0 +1,70 @@
// OIDB 0x93d0_1 — fileset 内所有文件的元数据上报(commit)。
// 多文件机制:f4 是 repeated,一个请求同时携带 fileset 内全部文件条目,
// 每条 f6=文件序号(1,2,3...),f7=formatCode。单文件时只有一个条目。
// 响应 f1=1(ack), f2/f3=filesetUuid。subCommand=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashCommitFileReq,
FlashCommitFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace CommitFile {
export const command = 0x93d0;
export const subCommand = 1;
/** 单个文件的 commit 元数据。fileIndex 为 fileset 内序号(从 1 递增)。 */
export interface CommitEntry {
fileUuid: string;
fileName: string;
origName: string;
fileSize: number;
/** 格式码:rar=4, mp4=2。 */
formatCode: number;
/** fileset 内序号(1,2,3...),与 0x12a9 filesetWrap.f4 一致。 */
fileIndex: number;
}
export interface Params {
filesetUuid: string;
/** fileset 内全部文件条目;一次 0x93d0 请求同时上报。 */
entries: CommitEntry[];
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashCommitFileReq => ({
field1: 1,
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
commitInfo: p.entries.map((e) => ({
filesetUuid: p.filesetUuid,
fileUuid: e.fileUuid,
field3: 0,
field4: {},
field5: 1,
field6: e.fileIndex,
formatCode: e.formatCode,
fileName: e.fileName,
origName: e.origName,
field10: 0,
fileSize: BigInt(e.fileSize),
field12: 0,
field24: {},
})),
field5: 1,
field6: 1,
});
export const deserialize = (_ctx: Deps, body: FlashCommitFileResp): FlashCommitFileResp => body;
export const encode = (env: OidbBase<FlashCommitFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashCommitFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashCommitFileResp> =>
protobuf_decode<OidbBase<FlashCommitFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<FlashCommitFileResp> =>
invokeOidb(deps, CommitFile, params);
}
@@ -0,0 +1,38 @@
// OIDB 0x93db_1 — fileSet 完成。请求 f1=filesetUuid, f2=""。响应 ack。sub=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashCompleteFilesetReq,
FlashCompleteFilesetResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace CompleteFileset {
export const command = 0x93db;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashCompleteFilesetReq => ({
filesetUuid: p.filesetUuid,
field2: '',
});
export const deserialize = (_ctx: Deps, _body: FlashCompleteFilesetResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashCompleteFilesetReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashCompleteFilesetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashCompleteFilesetResp> =>
protobuf_decode<OidbBase<FlashCompleteFilesetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, CompleteFileset, params);
}
@@ -0,0 +1,40 @@
// OIDB 0x9407_1 — 删除闪传文件(OneBot 标准未定义,QQ 面板有此操作)。
// 请求 f1=filesetUuid, f2="", f3=7。响应短 ack(envelope errorCode=0 即成功)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashDeleteFileReq,
FlashDeleteFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace DeleteFlashFile {
export const command = 0x9407;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashDeleteFileReq => ({
filesetUuid: p.filesetUuid,
field2: '',
field3: 7,
});
export const deserialize = (_ctx: Deps, _body: FlashDeleteFileResp): void => {
// 成功靠 envelope errorCode=0(invokeOidb 已校验),业务体空。
};
export const encode = (env: OidbBase<FlashDeleteFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashDeleteFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashDeleteFileResp> =>
protobuf_decode<OidbBase<FlashDeleteFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, DeleteFlashFile, params);
}
@@ -0,0 +1,78 @@
// OIDB 0x93d4_1 — 拉取下载URL(完整参数 + fldc)。
// 响应下载URL: multimedia.qfile.qq.com/download?appid=14902&client_type=win
// &client_ver=...&fileid=...&fldc=...(无 rkey,用 fldc)。
// 响应结构与 0x93d3 不同:downloadUrl 在 f1.f3.f13.f2.f2(非 f9.fileIdWrap)。
// 用于 get_flash_file_url / download_fileset 的完整链接变体。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDownloadUrlReq,
FlashGetDownloadUrlResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetDownloadUrl {
export const command = 0x93d4;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
/** 指定下载 fileset 内第几个文件(1-based)。默认 1(主文件)。 */
fileIndex?: number;
}
/** 单个文件的下载元信息;无主文件 fileId 时该条目 null。 */
export type FileMeta = {
fileIndex: number;
fileId: string;
filesetUuid: string;
fileUuid: string;
fileName: string;
fileSize: number;
};
/** fileset 内所有文件元信息(按 fileIndex 升序)。 */
export type Result = FileMeta[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDownloadUrlReq => ({
filesetUuid: p.filesetUuid,
inner: {
field1: '',
field2: 1,
field3: 18,
field4: '',
field5: { field1: 0 },
field6: { field1: 0, field2: 0 },
},
field3: 7,
field4: 1,
});
export const deserialize = (_ctx: Deps, body: FlashGetDownloadUrlResp): Result => {
// f1.f3 是 repeated fileInfo,多文件 fileset 时每个文件一条(f6=序号,f14=主文件 fileId)。
// f13 是缩略图(appid=14902),主文件下载 URL 需 0x12a9 sub=200 拿。
const infos = body.entry?.fileInfo ?? [];
return infos.map((info, idx) => {
const fileId = info?.mainFile?.fileId ?? '';
const fileIndex = info?.field6 ?? idx + 1;
return {
fileIndex,
fileId,
filesetUuid: info?.filesetUuid ?? '',
fileUuid: info?.fileUuid ?? '',
fileName: info?.fileName ?? '',
fileSize: Number(info?.fileSize ?? 0),
};
});
};
export const encode = (env: OidbBase<FlashGetDownloadUrlReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDownloadUrlReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDownloadUrlResp> =>
protobuf_decode<OidbBase<FlashGetDownloadUrlResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetDownloadUrl, params);
}
@@ -0,0 +1,42 @@
// OIDB 0x93d3_1 — 拉取文件集详情(点"分享"显示链接时触发)。
// 请求 f1=filesetUuid, f2=7。响应 f1=repeated FlashFileEntry(含文件名/大小/
// 上传分享URL qfile.qq.com/q/<code> / fileId / 下载URL,URL 里已含 rkey)。
// 用于 get_fileset_info / get_flash_file_list / get_flash_file_url / get_share_link。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDetailReq,
FlashGetDetailResp,
FlashFileEntry,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetFilesetDetail {
export const command = 0x93d3;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
}
export type Result = FlashFileEntry[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDetailReq => ({
filesetUuid: p.filesetUuid,
field2: 7,
});
export const deserialize = (_ctx: Deps, body: FlashGetDetailResp): Result =>
body.entries ?? [];
export const encode = (env: OidbBase<FlashGetDetailReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDetailReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDetailResp> =>
protobuf_decode<OidbBase<FlashGetDetailResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetFilesetDetail, params);
}
@@ -0,0 +1,82 @@
// OIDB 0x12a9_200 — get-download(拿主文件下载直链)。
// 请求 payload @ f3(不同于 sub=100 的 f2 / sub=103 的 f12)。响应 f3 含 host + path
// (主文件下载 URL,appid=14901 + 主文件fileId + fldc + rkey)。
// 主文件 fileId 来自 0x93d4 f14.f1。0x93d3/0x93d4 的 downloadUrl 是缩略图(appid=14903/14902),
// 主文件下载 URL 必须走 sub=200。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashGetDownloadReq,
FlashGetDownloadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 300;
export namespace GetFlashDownload {
export const command = 0x12a9;
export const subCommand = 200;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string; // 主文件 fileUuid(0x93d4 f1.f3.f2)
fileId: string; // 主文件 fileId(0x93d4 f14.f1)
fileName: string;
}
export type Result = string | null; // 主文件下载 URL
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashGetDownloadReq => ({
head: {
sub: { seq: seqCounter++, sub: 200 },
config: { field101: 2, field102: 4, field103: 22, field200: 5 }, // mp4 f103=22
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
field1: 0,
field4: p.fileName,
field5: { field1: 0, field2: 0, field3: 0, field4: 0 },
field6: 0, field7: 0, field8: 0, field9: 0,
},
fileId: p.fileId,
field3: 0, field4: 0, field5: 0, field6: 0,
},
field2: {
// 固定下载参数(QQ 客户端实测值,未观察到随文件变化)。
field2: { field1: 4294967294, field3: 4294967295, field5: 111, field6: { field1: 3403722988 } },
field4: { field1: 0 },
// field3 必须是主文件类型码 26;用 2 会被服务端拒(170019002 Service Failure)。
filesetWrap: { filesetUuid: p.filesetUuid, fileUuid: p.fileUuid, field3: 26, field4: p.fileUuid },
},
field3: 0,
},
});
export const deserialize = (_ctx: Deps, body: FlashGetDownloadResp): Result => {
// 响应 f3 含 rkey + host(multimedia.qfile.qq.com)+ path(/download?appid=14901...&fldc=...)。
// rkey 在 f3 单独字段(path 不含 rkey),拼完整 URL 需拼接 &rkey=。
const raw = body.body;
if (!raw || raw.length === 0) return null;
const text = Buffer.from(raw).toString('latin1');
const host = /multimedia\.qfile\.qq\.com/.exec(text);
const path = /\/download\?appid=14901[\x20-\x7e]*/.exec(text);
const rkey = /rkey=([A-Za-z0-9_-]+)/.exec(text);
if (!host || !path) return null;
const base = `https://${host[0]}${path[0]}`;
return rkey ? `${base}&${rkey[0]}` : base;
};
export const encode = (env: OidbBase<FlashGetDownloadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashGetDownloadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashGetDownloadResp> =>
protobuf_decode<OidbBase<FlashGetDownloadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<Result> =>
invokeOidb(deps, GetFlashDownload, params);
}
@@ -0,0 +1,42 @@
// OIDB 0x93d2_1 — 查询 fileset 列表(全部 fileset,无 UUID 入参)。
// 请求 f1=3, f2="", f3=10。响应 f1=repeated FlashFileEntry。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashListFilesetsReq,
FlashListFilesetsResp,
FlashFileEntry,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace ListFilesets {
export const command = 0x93d2;
export const subCommand = 1;
export interface Params {
field1?: number; // 默认 3
field3?: number; // 默认 10
}
export type Result = FlashFileEntry[];
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashListFilesetsReq => ({
field1: p.field1 ?? 3,
field2: '',
field3: p.field3 ?? 10,
});
export const deserialize = (_ctx: Deps, body: FlashListFilesetsResp): Result =>
body.entries ?? [];
export const encode = (env: OidbBase<FlashListFilesetsReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashListFilesetsReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashListFilesetsResp> =>
protobuf_decode<OidbBase<FlashListFilesetsResp>>(bytes);
export const invoke = (deps: Deps, params: Params = {}): Promise<Result> =>
invokeOidb(deps, ListFilesets, params);
}
@@ -0,0 +1,103 @@
// OIDB 0x12a9_100 — prepare-upload(大文件分片上传前申请 sliceupload rkey)。
// sub=100,uinForm=true。sub=100 的 payload 在 f2(sub=103 在 f12),结构完全不同。
// 响应 f2.f1 是 sliceupload rkey;秒传(文件已在服务端)时 f1 缺失,deserialize 返回 null。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashPrepareUploadReq,
FlashPrepareUploadResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
let seqCounter = 200;
export namespace PrepareUpload {
export const command = 0x12a9;
export const subCommand = 100;
export const uinForm = true;
export interface Params {
filesetUuid: string;
fileUuid: string;
fileName: string;
fileSize: number;
sha1: string; // 40 hex
/** fileset 内序号(1,2,3...),与 0x93d0 commit f6 一致。缩略图序号在主文件之后递增。 */
fileIndex: number;
/** 格式码:与 commit f7 一致(mp4=2, rar/zip=4)。主文件 filesetWrap.f7 用此值;
* 缩略图固定 png=26/jpg=2。 */
formatCode: number;
/** 缩略图类型:undefined=主文件, 'png'=png 缩略图, 'jpg'=jpg 缩略图。
* 主文件下载入口需要缩略图关联才会被服务端填充,缩略图字段差异据此切换。 */
thumbType?: 'png' | 'jpg';
width?: number; // 缩略图宽(主文件=0)
height?: number; // 缩略图高(主文件=0)
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashPrepareUploadReq => {
// 缩略图与主文件字段差异:config.f103、FileInfo.f5.f1/f6/f7/f9、filesetWrap.f6/f7。
// filesetWrap.f4 统一用 fileIndex(主文件和缩略图都从 facade 传入,保证与 commit f6 一致)。
const isThumb = p.thumbType !== undefined;
const isJpg = p.thumbType === 'jpg';
return {
head: {
sub: { seq: seqCounter++, sub: 100 },
config: { field101: 2, field102: 4, field103: isThumb ? (isJpg ? 24 : 23) : 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: p.fileSize,
md5: '', // sub=100 不带 MD5
sha1: p.sha1,
fileName: p.fileName,
field5: { field1: isJpg ? 1 : 0, field2: 0, field3: 0, field4: 0 },
field6: p.width ?? 0,
field7: p.height ?? 0,
field8: 0,
field9: isJpg ? 0 : 1,
},
field2: 0, // wrapper.f2=0(varint,不是 fileId)
},
field2: 1,
field3: 0,
field4: 0,
field5: 0,
field6: {
field1: { field1: 0, field2: {} },
field2: { field3: {} },
field3: { field11: {}, field12: {} },
field10: 0,
},
field7: 0,
field8: 0,
filesetWrap: {
filesetUuid: p.filesetUuid,
uploadKey: p.filesetUuid,
fileUuid: p.fileUuid,
field4: p.fileIndex,
field5: 0,
field6: isThumb ? 1 : 0, // 缩略图=1, 主文件=0
field7: isThumb ? (isJpg ? 2 : 26) : p.formatCode, // 主文件=formatCode(mp4=2), png缩略图=26, jpg缩略图=2
field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
};
export const deserialize = (_ctx: Deps, body: FlashPrepareUploadResp): string | null => {
// sub-100 resp f2={f1:rkey}(正常上传,CAES/CAIS/CAQS/CAMS)。
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方跳过 sliceupload。
return body.rkeyWrap?.rkey ?? null;
};
export const encode = (env: OidbBase<FlashPrepareUploadReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashPrepareUploadReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashPrepareUploadResp> =>
protobuf_decode<OidbBase<FlashPrepareUploadResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<string | null> =>
invokeOidb(deps, PrepareUpload, params);
}
@@ -0,0 +1,45 @@
// OIDB 0x9427_0 — 重命名闪传文件(OneBot 标准未定义,QQ 面板有此操作)。
// 请求 f1=filesetUuid, f2={f1=新文件名, f2=显示名}, f3={f1=0}。
// 注意 envelope 与其他闪传 cmd 不同:subCommand=0(不是 1)+ uinForm=true(reserved=1)。
// 不能按 0x93cf_1 类推,用 sub=1 会被服务端拒(no privilege)。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashRenameFileReq,
FlashRenameFileResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace RenameFlashFile {
export const command = 0x9427;
export const subCommand = 0;
export const uinForm = true;
export interface Params {
filesetUuid: string;
/** 新文件名(同时用作显示名,与 QQ 面板行为一致)。 */
newName: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashRenameFileReq => ({
filesetUuid: p.filesetUuid,
name: { newName: p.newName, displayName: p.newName },
flag: { field1: 0 },
});
export const deserialize = (_ctx: Deps, _body: FlashRenameFileResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashRenameFileReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashRenameFileReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashRenameFileResp> =>
protobuf_decode<OidbBase<FlashRenameFileResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, RenameFlashFile, params);
}
@@ -0,0 +1,52 @@
// OIDB 0x93d7_1 — 发送闪传文件给用户(send_flash_msg)。
// 请求 f1={f1:1, f2:{f1:targetUid}}, f2=filesetUuid。响应仅回显目标 uid(无 message_id)。
// 0x93d7 是「分享 fileset 给用户」(对端通过 fileset 链接下载),非传统消息。
// envelope 用 0x93xx 默认的 sub=1/reserved=0,实测通过。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashSendReq,
FlashSendResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SendFlashMsg {
export const command = 0x93d7;
export const subCommand = 1;
export interface Params {
targetUid?: string; // 私聊(与 groupId 二选一)
groupId?: number; // 群聊
filesetUuid: string;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashSendReq => {
// 群聊:f1={f1:2, f3:{f1:groupId}}(groupId 直接用群号,无需转 uid)。
if (p.groupId !== undefined) {
return {
target: { field1: 2, targetGroup: { groupId: p.groupId } },
filesetUuid: p.filesetUuid,
};
}
// 私聊:f1={f1:1, f2:{f1:targetUid}}。
return {
target: { field1: 1, targetUid: { targetUid: p.targetUid! } },
filesetUuid: p.filesetUuid,
};
};
export const deserialize = (_ctx: Deps, _body: FlashSendResp): void => {
// 响应仅回显目标 uid,无 message_id。
};
export const encode = (env: OidbBase<FlashSendReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashSendReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashSendResp> =>
protobuf_decode<OidbBase<FlashSendResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SendFlashMsg, params);
}
@@ -0,0 +1,39 @@
// OIDB 0x93d1_1 — 设置 fileSet 状态。请求 f1=filesetUuid, f2=6(状态码)。响应 ack。sub=1, reserved=0。
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
FlashSetStatusReq,
FlashSetStatusResp,
} from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace SetFilesetStatus {
export const command = 0x93d1;
export const subCommand = 1;
export interface Params {
filesetUuid: string;
status?: number; // 默认 6
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): FlashSetStatusReq => ({
filesetUuid: p.filesetUuid,
status: p.status ?? 6,
});
export const deserialize = (_ctx: Deps, _body: FlashSetStatusResp): void => {
// 成功靠 envelope errorCode=0。
};
export const encode = (env: OidbBase<FlashSetStatusReq>): Uint8Array =>
protobuf_encode<OidbBase<FlashSetStatusReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<FlashSetStatusResp> =>
protobuf_decode<OidbBase<FlashSetStatusResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, SetFilesetStatus, params);
}
@@ -0,0 +1,190 @@
import { describe, expect, it } from 'vitest';
import { createHash } from 'node:crypto';
import { Sha1Stream, computeSha1StateV } from '@snowluma/protocol/highway/sha1-stream';
// SHA1 标准填充:msg + 0x80 + 0x00...(k 个) + 8 字节大端 bit 长度,总长为 64 倍数。
// 用于把任意输入变成「已 finalize」的完整 block 序列——这样 Sha1Stream 对它逐 block
// transform 后取大端 state,应当等于 Node crypto 对原始 msg 的 digest。
function sha1Pad(msg: Uint8Array): Uint8Array {
const msgLen = msg.length;
const k = (56 - ((msgLen + 1) % 64) + 64) % 64;
const padded = new Uint8Array(msgLen + 1 + k + 8);
padded.set(msg, 0);
padded[msgLen] = 0x80;
const view = new DataView(padded.buffer, padded.byteOffset + padded.byteLength - 8, 8);
view.setBigUint64(0, BigInt(msgLen) * 8n, false); // 大端 bit 长度
return padded;
}
// padding oracle 的核心:Node crypto 的 SHA1 digest 内部就是对 padding 后的输入逐 block
// transform、取最终 state 的大端表示。Sha1Stream 自行实现 transform 且不 finalize,
// 因此对「已 padding 的输入」transform 后大端输出必须等于 digest。Node crypto 走
// OpenSSL,与本实现完全独立,是验证 transform 正确性的可靠参照。
function expectSha1StreamMatchesCrypto(msg: Uint8Array): void {
const expected = createHash('sha1').update(Buffer.from(msg)).digest();
const stream = new Sha1Stream();
stream.update(sha1Pad(msg));
const bigEndian = stream.hash(false);
expect(Buffer.from(bigEndian).equals(expected)).toBe(true);
}
describe('Sha1Stream transform (padding oracle vs Node crypto)', () => {
it('matches for empty input (single padded block)', () => {
expectSha1StreamMatchesCrypto(Buffer.alloc(0));
});
it('matches for "abc" (single padded block)', () => {
expectSha1StreamMatchesCrypto(Buffer.from('abc', 'utf8'));
});
it('matches across the 56-byte boundary (forces a second padded block)', () => {
// 56 字节:0x80 后只剩 0 字节给 zeros 不够放 8 字节长度,padding 溢出到第二块。
expectSha1StreamMatchesCrypto(Buffer.alloc(56, 0x41));
});
it('matches for exactly one block (64 bytes → two padded blocks)', () => {
expectSha1StreamMatchesCrypto(Buffer.alloc(64, 0x42));
});
it('matches for multi-block input (200 bytes → four padded blocks)', () => {
expectSha1StreamMatchesCrypto(Buffer.alloc(200, 0x43));
});
it('matches for pseudo-random multi-block input', () => {
const data = Buffer.alloc(313, 0);
for (let i = 0; i < data.length; i++) data[i] = (i * 1103515245 + 12345) & 0xff;
expectSha1StreamMatchesCrypto(data);
});
});
describe('Sha1Stream update chunk-equivalence', () => {
// update 内部维护 64 字节 buffer + 128 位 bit 计数;分块喂入必须与一次性喂入
// 产生相同的内部 state。切分点覆盖 block 边界附近以暴露 buffer/count 管理 bug。
it('two-chunk split at various boundaries yields the same state as one update', () => {
const data = Buffer.alloc(200, 0x44);
const full = new Sha1Stream();
full.update(data);
const fullHash = Buffer.from(full.hash(true));
for (const split of [0, 1, 32, 63, 64, 65, 127, 128, 129, 199]) {
const s = new Sha1Stream();
s.update(data.subarray(0, split));
s.update(data.subarray(split));
expect(Buffer.from(s.hash(true)).equals(fullHash)).toBe(true);
}
});
it('three-chunk split yields the same state as one update', () => {
const data = Buffer.alloc(300, 0x45);
const full = new Sha1Stream();
full.update(data);
const fullHash = Buffer.from(full.hash(true));
const s = new Sha1Stream();
s.update(data.subarray(0, 100));
s.update(data.subarray(100, 200));
s.update(data.subarray(200));
expect(Buffer.from(s.hash(true)).equals(fullHash)).toBe(true);
});
it('empty updates do not change the state', () => {
const data = Buffer.alloc(130, 0x46);
const full = new Sha1Stream();
full.update(data);
const fullHash = Buffer.from(full.hash(true));
const s = new Sha1Stream();
s.update(Buffer.alloc(0));
s.update(data);
s.update(Buffer.alloc(0));
expect(Buffer.from(s.hash(true)).equals(fullHash)).toBe(true);
});
});
describe('Sha1Stream hash endianness', () => {
// hash(true) 小端与 hash(false) 大端是同一组 5 个 state word 的不同字节序表示。
// 结合上面的 padding oracle(大端 == digest),即可间接确认小端中间 state 的值。
it('little-endian is the per-word byte-swap of big-endian', () => {
const s = new Sha1Stream();
s.update(Buffer.alloc(64, 0x47));
const le = Buffer.from(s.hash(true));
const be = Buffer.from(s.hash(false));
expect(le.length).toBe(20);
for (let i = 0; i < 5; i++) {
expect(le.readUInt32LE(i * 4)).toBe(be.readUInt32BE(i * 4));
}
});
it('reset restores the initial SHA1 state', () => {
const s = new Sha1Stream();
s.update(Buffer.alloc(200, 0x48));
s.reset();
const initial = Buffer.from(s.hash(false));
const expected = Buffer.from([
0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89,
0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76,
0xc3, 0xd2, 0xe1, 0xf0,
]);
expect(initial.equals(expected)).toBe(true);
});
});
describe('computeSha1StateV', () => {
const SLICE = 1024 * 1024; // 1 MB,与上传链路一致,且是 64 的倍数
it('returns one 20-byte state per slice', () => {
const data = Buffer.alloc(SLICE + 100, 0x49); // 2 片
const states = computeSha1StateV(data, 2, SLICE);
expect(states.length).toBe(2);
for (const st of states) expect(st.length).toBe(20);
});
// 末片定义为「标准整文件 SHA1(有 finalize/padding)」,直接对齐 Node crypto。
it('last slice equals the standard full-file SHA1 digest', () => {
const data = Buffer.alloc(SLICE + 100, 0x4a);
const states = computeSha1StateV(data, 2, SLICE);
const expected = createHash('sha1').update(data).digest();
expect(Buffer.from(states[1]).equals(expected)).toBe(true);
});
it('last slice equals full-file SHA1 for a three-slice file', () => {
const data = Buffer.alloc(SLICE * 2 + 1, 0x4b);
const states = computeSha1StateV(data, 3, SLICE);
expect(Buffer.from(states[2]).equals(createHash('sha1').update(data).digest())).toBe(true);
});
// 非末片是「累积 SHA1 中间 state(不 finalize,小端)」。若误用标准 finalize
// 计算,会得到 file[0:slice] 的完整 digest,与本实现必然不等——以此锁定
// 「中间 state 而非独立片 digest」的语义。
it('non-last slice is NOT the finalized digest of the prefix', () => {
const data = Buffer.alloc(SLICE + 100, 0x4c);
const states = computeSha1StateV(data, 2, SLICE);
const prefixDigest = createHash('sha1').update(data.subarray(0, SLICE)).digest();
expect(Buffer.from(states[0]).equals(prefixDigest)).toBe(false);
});
// 非末片中间 state 的正确性来自 transform(padding oracle 已验)与 update
// 分块等价(已验)。这里再做一次直接对照:computeSha1StateV 对首片的处理
// 等价于手动 reset + update(prefix) + 小端输出。
it('non-last slice equals manual Sha1Stream reset+update of the prefix', () => {
const data = Buffer.alloc(SLICE + 100, 0x4d);
const states = computeSha1StateV(data, 2, SLICE);
const manual = new Sha1Stream();
manual.update(data.subarray(0, SLICE));
expect(Buffer.from(states[0]).equals(Buffer.from(manual.hash(true)))).toBe(true);
});
// 单片文件只有末片,直接是整文件 digest。
it('single-slice file has only the finalized digest', () => {
const data = Buffer.alloc(100, 0x4e);
const states = computeSha1StateV(data, 1, SLICE);
expect(states.length).toBe(1);
expect(Buffer.from(states[0]).equals(createHash('sha1').update(data).digest())).toBe(true);
});
// 中间 state 与「把它当末片算出的 digest」必须不同——这是 sliceupload 服务端
// 校验「累积 state 而非独立片 digest」的核心区分点。
it('non-last slice differs from a single-slice digest of the same prefix', () => {
const data = Buffer.alloc(SLICE + 100, 0x4f);
const multiFirst = computeSha1StateV(data, 2, SLICE)[0];
const singleAsLast = computeSha1StateV(data.subarray(0, SLICE), 1, SLICE)[0];
expect(Buffer.from(multiFirst).equals(Buffer.from(singleAsLast))).toBe(false);
});
});
@@ -0,0 +1,70 @@
import { describe, expect, it } from 'vitest';
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
import type { FlashApplyUploadReq } from '@snowluma/proto-defs/oidb-actions/flash-transfer';
// ENC#8: 0x12a9 sub=103 apply-upload 真实客户端请求 body(frida 抓包,QQ 9.9.26-44343,
// 2026-06-19)。用 ENC#8 的精确值手工构造 req,encode 后必须 byte-for-byte 匹配 ENC#8 hex。
// 这是真正的 byte-oracle:字段号/wire type/0值显式编码任一错误都会 hex 不等。
const ENC8_HEX =
'0a190a0508ac011067120ca80602b00604b80616c00c051a020801629d030a81020a870108b4cdcc01122063396631303334663062303431653933353339653937663839356363333139621a28306636326234663763646463373965326662666431343065646531326431633434646462373937612222e5b18fe5b995e5bd95e588b620323032352d30312d3135203030323133302e6d70342a0808001000180020003000380040004801126745685150597254337a64783534767639464137654574484554647435656869307a637742494c56304b4b4b516938796a6b3555444d675277636d396b5549447153566f51496f38546b56454c72776f454c5746544c6a433268586f445947505f676745435a336f180120fae4d4d1062880ea493000120208021a0808001000180022005288010a2438363866633433312d336361372d346130632d383538322d666135656365613062666134122438363866633433312d336361372d346130632d383538322d6661356563656130626661341a2436656639316166322d363830302d373633632d313936642d38353231303537353536343020012800300138024200480150005800600068007000';
// ENC#8 抓包值(sub=103 mp4)。
const ENC8_REQ: FlashApplyUploadReq = {
head: {
sub: { seq: 172, sub: 103 },
config: { field101: 2, field102: 4, field103: 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: 3352244,
md5: 'c9f1034f0b041e93539e97f895cc319b',
sha1: '0f62b4f7cddc79e2fbfd140ede12d1c44ddb797a',
fileName: '屏幕录制 2025-01-15 002130.mp4',
field5: { field1: 0, field2: 0, field3: 0, field4: 0 },
field6: 0, field7: 0, field8: 0, field9: 1,
},
fileId: 'EhQPYrT3zdx54vv9FA7eEtHETdt5ehi0zcwBILV0KKKQi8yjk5UDMgRwcm9kUIDqSVoQIo8TkVELrwoELWFTLjC2hXoDYGP_ggECZ3o',
field3: 1, field4: 1781871226, field5: 1209600, field6: 0,
},
flag2: { field1: 2 },
field3: { field1: 0, field2: 0, field3: 0, field4: {} },
filesetWrap: {
filesetUuid: '868fc431-3ca7-4a0c-8582-fa5ecea0bfa4',
uploadKey: '868fc431-3ca7-4a0c-8582-fa5ecea0bfa4',
fileUuid: '6ef91af2-6800-763c-196d-852105755640',
field4: 1, field5: 0, field6: 1, field7: 2, field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
describe('ApplyUpload byte-oracle (0x12a9_103 encode == ENC#8)', () => {
it('encodes the ENC#8 field values to the exact frida-captured wire bytes', () => {
const out = Buffer.from(protobuf_encode<FlashApplyUploadReq>(ENC8_REQ)).toString('hex');
if (out !== ENC8_HEX) {
// 定位首个差异字节
const n = Math.min(out.length, ENC8_HEX.length);
let i = 0;
while (i < n && out[i] === ENC8_HEX[i]) i++;
throw new Error(
`hex mismatch at char ${i} (byte ${i >> 1}):\n` +
` bot: ...${out.slice(Math.max(0, i - 20), i + 20)}\n` +
` ENC#8: ...${ENC8_HEX.slice(Math.max(0, i - 20), i + 20)}\n` +
` bot len=${out.length / 2}B, ENC#8 len=${ENC8_HEX.length / 2}B`,
);
}
expect(out).toBe(ENC8_HEX);
});
it('round-trips: encode → decode preserves the field tree', () => {
const bytes = protobuf_encode<FlashApplyUploadReq>(ENC8_REQ);
const back = protobuf_decode<FlashApplyUploadReq>(bytes);
expect(back.head?.sub?.sub).toBe(103);
expect(back.head?.config?.field103).toBe(22);
expect(back.payload?.wrapper?.fileInfo?.field9).toBe(1);
expect(back.payload?.wrapper?.fileInfo?.field5?.field4).toBe(0);
expect(back.payload?.filesetWrap?.fileUuid).toBe('6ef91af2-6800-763c-196d-852105755640');
});
});
@@ -0,0 +1,60 @@
import { describe, expect, it } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { FlashApplyUploadReq } from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { ApplyUpload } from '../../../src/oidb-services/flash-transfer/apply-upload';
// ENC#8: 0x12a9 sub=103 apply-upload 真实客户端请求 body(frida 抓包,QQ 9.9.26-44343,
// 2026-06-19)。字段树逐字节解码见 flash_transfer_protocol_full.md §9.5。
// 独立 byte-oracle:从 frida 抓的 hex decode 回来,字段号/wire type 错则值读不出。
const ENC8_HEX =
'0a190a0508ac011067120ca80602b00604b80616c00c051a020801629d030a81020a870108b4cdcc01122063396631303334663062303431653933353339653937663839356363333139621a28306636326234663763646463373965326662666431343065646531326431633434646462373937612222e5b18fe5b995e5bd95e588b620323032352d30312d3135203030323133302e6d70342a0808001000180020003000380040004801126745685150597254337a64783534767639464137654574484554647435656869307a637742494c56304b4b4b516938796a6b3555444d675277636d396b5549447153566f51496f38546b56454c72776f454c5746544c6a433268586f445947505f676745435a336f180120fae4d4d1062880ea493000120208021a0808001000180022005288010a2438363866633433312d336361372d346130632d383538322d666135656365613062666134122438363866633433312d336361372d346130632d383538322d6661356563656130626661341a2436656639316166322d363830302d373633632d313936642d38353231303537353536343020012800300138024200480150005800600068007000';
describe('ApplyUpload namespace (0x12a9_103)', () => {
it('declares command 0x12a9 sub 103 uinForm=true', () => {
expect(ApplyUpload.command).toBe(0x12a9);
expect(ApplyUpload.subCommand).toBe(103);
expect(ApplyUpload.uinForm).toBe(true);
});
it('decodes ENC#8 frida capture with the exact field tree', () => {
const req = protobuf_decode<FlashApplyUploadReq>(Buffer.from(ENC8_HEX, 'hex'));
// head: { f1:{seq,sub}, f2:config{f101,f102,f103,f200}, f3:{f1:1} }
expect(req.head?.sub?.seq).toBe(172);
expect(req.head?.sub?.sub).toBe(103);
expect(req.head?.config).toMatchObject({ field101: 2, field102: 4, field103: 22, field200: 5 });
expect(req.head?.field3?.field1).toBe(1);
// payload.wrapper.fileInfo(f12.f1.f1)
const fi = req.payload?.wrapper?.fileInfo;
expect(fi?.fileSize).toBe(3352244);
expect(fi?.md5).toBe('c9f1034f0b041e93539e97f895cc319b');
expect(fi?.sha1).toBe('0f62b4f7cddc79e2fbfd140ede12d1c44ddb797a');
expect(fi?.fileName).toBe('屏幕录制 2025-01-15 002130.mp4');
// field5 = {f1:0,f2:0,f3:0,f4:0},f4 是 varint(不是 message)
expect(fi?.field5).toMatchObject({ field1: 0, field2: 0, field3: 0, field4: 0 });
expect(fi?.field9).toBe(1);
// payload.wrapper(f12.f1):fileId + 时间戳 + TTL
expect(req.payload?.wrapper?.fileId).toBe('EhQPYrT3zdx54vv9FA7eEtHETdt5ehi0zcwBILV0KKKQi8yjk5UDMgRwcm9kUIDqSVoQIo8TkVELrwoELWFTLjC2hXoDYGP_ggECZ3o');
expect(req.payload?.wrapper?.field3).toBe(1);
expect(req.payload?.wrapper?.field4).toBe(1781871226);
expect(req.payload?.wrapper?.field5).toBe(1209600);
// payload.flag2(f12.f2 = {f1:2})
expect(req.payload?.flag2?.field1).toBe(2);
// payload.field3(f12.f3 = {f1:0,f2:0,f3:0,f4:空message})
expect(req.payload?.field3).toMatchObject({ field1: 0, field2: 0, field3: 0 });
// payload.filesetWrap(f12.f10 = filesetUuid + fileUuid + flags)
const fw = req.payload?.filesetWrap;
expect(fw?.filesetUuid).toBe('868fc431-3ca7-4a0c-8582-fa5ecea0bfa4');
expect(fw?.uploadKey).toBe('868fc431-3ca7-4a0c-8582-fa5ecea0bfa4');
expect(fw?.fileUuid).toBe('6ef91af2-6800-763c-196d-852105755640');
expect(fw?.field4).toBe(1);
expect(fw?.field6).toBe(1);
expect(fw?.field7).toBe(2);
expect(fw?.field9).toBe(1);
});
});
@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { FlashGetDownloadUrlResp } from '@snowluma/proto-defs/oidb-actions/flash-transfer';
import { GetDownloadUrl } from '@snowluma/protocol/oidb-services/flash-transfer/get-download-url';
// 0x93d4 真实响应(send_packet 抓于 QQ 9.9.26-44343, 2026-06-20, fileset e7453377 已发送)。
// byte-oracle:decode + deserialize 必须从 f1.f3.f14.f1 提取到主文件 fileId。
// 0x93d4 响应结构与 0x93d3 不同(downloadUrl 在深层嵌套,非 f9.fileIdWrap),这个测试
// 锁定该结构,防止 deserialize 退回错误的 FlashFileEntry 解读。
const RESP_HEX = '08d4a7021001180022b8090ab50910011afa080a2465373435333337372d633865612d343034652d393238352d353361613566616431393832122466613038663938332d323337662d303833632d656536332d6139646164336161616565352801300138024222e5b18fe5b995e5bd95e588b620323032352d30352d3033203135313234312e6d70344a2162696e676d756c757a686920323032352d30352d3033203135313234312e6d703458bcf7e3036ae9050a6645685330442d4c3261494b306b74314d51424f764f5377746465753574426a7939774567746e516f724c6d736d5961566c514d794248427962325251674f704a5768424d3744724a3276364843594c766576376b6f30587565674d4d61502d4341514a6e656712a804080212a30468747470733a2f2f6d756c74696d656469612e7166696c652e71712e636f6d2f646f776e6c6f61643f61707069643d313439303226636c69656e745f747970653d77696e26636c69656e745f7665723d392e322e33342666696c6569643d45685330442d4c3261494b306b74314d51424f764f5377746465753574426a7939774567746e516f724c6d736d5961566c514d794248427962325251674f704a5768424d3744724a3276364843594c766576376b6f30587565674d4d61502d4341514a6e656726666c64633d696358456459355a6b5346395f59347239514f526e58562d6a6b31536d397753546b4a316a6876334f357a5f747331484966612d4c6a7662416b52494531526c4373704a4776336c453469635434467437414a794c33577242304b78696a555f423270386a75367a3371314d26726b65793d43414d5371414878697a55514532647437517975726675552d78446d3568666a4d727073325a69723764535f42354d55694349644e594c495167792d5264776d495a797a584a6f31714a687834464d756b346a337042306a5f37787850315a7a6748706469315f3158376178422d736541556c5f3646546f4679597638564d5337645a577036414275597a3875517a79306c487574676a6762714271477138336d70417a6465426475555833513043732d426b54676952767768664b3835696661774a3874477371576e70784871394f444c762d5f37566a78526e424456587046314f306343551a286234306665326636363838326234393264643463343031336166333932633264373565626239623420f2f7012a20393365643461306234383164623936343335323034363339626366393133313830800438c002726b0a674568512d63526273544d5338304c79484637745658626c38536c5a4e63426938392d4d44494c56304b497154305a6d476c5a55444d675277636d396b5549447153566f5156637648434d53585865556b54726c384e555f4a41586f444c6b625f676745435a336f18027a2466613038663938332d323337662d303833632d656536332d613964616433616161656535900103a2012833653731313665633463633462636430626338373137626235353564623937633461353634643730a801bcf7e303b2010308d547ca0120346365613333363331386338303864646431646630613333633938316339316122327b226f6666736574223a31382c22637572736f725f74696d65223a22303030312d30312d30315430303a30303a30305a227d28012a005a1d0a0f636c69656e745f636f6e6e5f736571120a313738313932393033395a200a1a747270632d6f632d7072696f726974792d706173732d6261636b12022d315a1c0a0e73736f5f647965696e675f6b6579120a323535303431393036385a160a0c73736f5f636c69656e74696412063133333034375a9c040a08747270632d73736f128f04000000147061d586907300000ba05fe3000207b7000001fb0073c9510000000e3235353034313930363820071b1b000008040000000000000000000003000000004c668066ca67e24ac9a81bd08aa343840338fa2f632ec020158218d5d2a35f1a2ab856dcbdcc486af66c8ba961db5532e2a065d882604a01539050c7ad17748f95521b4dac5e1834160000001b4f696462537663547270635463702e3078393364345f31000000188e0800005f3a366a000000008d0b00000000000000000000000000002462376234353837623661333666373535346564353235613563396230303166660000000000000000000000040000011d1a007a91020a047061d58610081a06392e322e333420c19e0c4220633165633037346532323533303539633230303530333039653965643932666552005a10b7b4587b6a36f7554ed525a5c9b001ff62206237623435383762366133366637353534656435323561356339623030316666688008720757696e646f7773820118755f6c5253732d3243757359575a6a455851707045694d518a01009001019a015208081248668066ca67e24ac9a81bd08aa343840338fa2f632ec020158218d5d2a35f1a2ab856dcbdcc486af66c8ba961db5532e2a065d882604a01539050c7ad17748f95521b4dac5e18341618c4acf8fa05a00100b80165c00100d201174f696462537663547270635463702e3078393364345f3190010d';
describe('GetDownloadUrl byte-oracle (0x93d4 deserialize)', () => {
it('extracts main file fileId from f1.f3.f14.f1', () => {
const bytes = Uint8Array.from(Buffer.from(RESP_HEX, 'hex'));
const env = protobuf_decode<OidbBase<FlashGetDownloadUrlResp>>(bytes);
const result = GetDownloadUrl.deserialize(null as never, env.body!);
// 0x93d4 f1.f3 是 repeated fileInfo,单文件场景返回一个元素的数组。
expect(result).toHaveLength(1);
const meta = result[0];
// 主文件 fileId(0x93d4 f14.f1),用于 0x12a9 sub=200 拿主文件下载直链。
expect(meta.fileId).toBe('EhQ-cRbsTMS80LyHF7tVXbl8SlZNcBi89-MDILV0KIqT0ZmGlZUDMgRwcm9kUIDqSVoQVcvHCMSXXeUkTrl8NU_JAXoDLkb_ggECZ3o');
expect(meta.filesetUuid).toBe('e7453377-c8ea-404e-9285-53aa5fad1982');
expect(meta.fileName).toContain('mp4');
expect(meta.fileSize).toBe(7928764);
expect(meta.fileIndex).toBe(1);
});
});
@@ -0,0 +1,69 @@
import { describe, expect, it } from 'vitest';
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
import type { FlashPrepareUploadReq } from '@snowluma/proto-defs/oidb-actions/flash-transfer';
// 真实 sub=100 (mp4) frida 抓包(QQ 9.9.26-44343, 2026-06-19)。payload @ f2(不是 f12!)。
// byte-oracle:用抓包值构造 req,encode 必须 byte-for-byte 匹配。
const SUB100_MP4_HEX = '0a180a0408081064120ca80602b00604b80616c00c051a0208011298020a6b0a6708a0d2e40212001a28643138333762626336666131653031396136326330343734616332386563363131343565656138612222e5b18fe5b995e5bd95e588b620323032352d31322d3232203135313432392e6d70342a08080010001800200030003800400048011000100118002000280032120a040800120012021a001a045a0062005000380040004a88010a2432383564346530622d363465342d343961642d396430632d666234383938393930626162122432383564346530622d363465342d343961642d396430632d6662343839383939306261621a2432343166356438382d333637352d623030612d303261302d30633035306138343032656520012800300038024200480150005800600068007000';
const SUB100_MP4_REQ: FlashPrepareUploadReq = {
head: {
sub: { seq: 8, sub: 100 },
config: { field101: 2, field102: 4, field103: 22, field200: 5 },
field3: { field1: 1 },
},
payload: {
wrapper: {
fileInfo: {
fileSize: 5843232,
md5: '',
sha1: 'd1837bbc6fa1e019a62c0474ac28ec61145eea8a',
fileName: '屏幕录制 2025-12-22 151429.mp4',
field5: { field1: 0, field2: 0, field3: 0, field4: 0 },
field6: 0, field7: 0, field8: 0, field9: 1,
},
field2: 0,
},
field2: 1, field3: 0, field4: 0, field5: 0,
field6: {
field1: { field1: 0, field2: {} },
field2: { field3: {} },
field3: { field11: {}, field12: {} },
field10: 0,
},
field7: 0, field8: 0,
filesetWrap: {
filesetUuid: '285d4e0b-64e4-49ad-9d0c-fb4898990bab',
uploadKey: '285d4e0b-64e4-49ad-9d0c-fb4898990bab',
fileUuid: '241f5d88-3675-b00a-02a0-0c050a8402ee',
field4: 1, field5: 0, field6: 0, field7: 2, field8: {},
field9: 1, field10: 0, field11: 0, field12: 0, field13: 0, field14: 0,
},
},
};
describe('PrepareUpload byte-oracle (0x12a9_100 encode == frida 抓包)', () => {
it('encodes the sub=100 mp4 capture to the exact wire bytes', () => {
const out = Buffer.from(protobuf_encode<FlashPrepareUploadReq>(SUB100_MP4_REQ)).toString('hex');
if (out !== SUB100_MP4_HEX) {
const n = Math.min(out.length, SUB100_MP4_HEX.length);
let i = 0;
while (i < n && out[i] === SUB100_MP4_HEX[i]) i++;
throw new Error(
`hex mismatch at char ${i} (byte ${i >> 1}):\n` +
` bot: ...${out.slice(Math.max(0, i - 24), i + 24)}\n` +
` frida: ...${SUB100_MP4_HEX.slice(Math.max(0, i - 24), i + 24)}\n` +
` bot len=${out.length / 2}B, frida len=${SUB100_MP4_HEX.length / 2}B`,
);
}
expect(out).toBe(SUB100_MP4_HEX);
});
it('round-trips: encode → decode preserves key fields', () => {
const bytes = protobuf_encode<FlashPrepareUploadReq>(SUB100_MP4_REQ);
const back = protobuf_decode<FlashPrepareUploadReq>(bytes);
expect(back.head?.sub?.sub).toBe(100);
expect(back.payload?.wrapper?.fileInfo?.fileSize).toBe(5843232);
expect(back.payload?.filesetWrap?.fileUuid).toBe('241f5d88-3675-b00a-02a0-0c050a8402ee');
});
});
@@ -0,0 +1,60 @@
import { describe, expect, it } from 'vitest';
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
import type { FlashSendReq } from '@snowluma/proto-defs/oidb-actions/flash-transfer';
// 0x93d7 send_flash_msg 真实客户端请求 body(frida 抓包,QQ 9.9.26-44343, 2026-06-20)。
// fileset e7453377-c8ea-404e-9285-53aa5fad1982 发送给 uid u_0aHrwL1tyskEWkhChJoeJg。
// byte-oracle:用抓包值构造 req,encode 必须 byte-for-byte 匹配。
const SEND_HEX = '0a1e0801121a0a18755f30614872774c317479736b45576b6843684a6f654a67122465373435333337372d633865612d343034652d393238352d353361613566616431393832';
const SEND_REQ: FlashSendReq = {
target: { field1: 1, targetUid: { targetUid: 'u_0aHrwL1tyskEWkhChJoeJg' } },
filesetUuid: 'e7453377-c8ea-404e-9285-53aa5fad1982',
};
describe('SendFlashMsg byte-oracle (0x93d7 encode == frida 抓包)', () => {
it('encodes the send capture to the exact wire bytes', () => {
const out = Buffer.from(protobuf_encode<FlashSendReq>(SEND_REQ)).toString('hex');
if (out !== SEND_HEX) {
const n = Math.min(out.length, SEND_HEX.length);
let i = 0;
while (i < n && out[i] === SEND_HEX[i]) i++;
throw new Error(
`hex mismatch at char ${i} (byte ${i >> 1}):\n` +
` bot: ...${out.slice(Math.max(0, i - 20), i + 20)}\n` +
` frida: ...${SEND_HEX.slice(Math.max(0, i - 20), i + 20)}\n` +
` bot len=${out.length / 2}B, frida len=${SEND_HEX.length / 2}B`,
);
}
expect(out).toBe(SEND_HEX);
});
it('round-trips: encode → decode preserves target + filesetUuid', () => {
const bytes = protobuf_encode<FlashSendReq>(SEND_REQ);
const back = protobuf_decode<FlashSendReq>(bytes);
expect(back.target?.field1).toBe(1);
expect(back.target?.targetUid?.targetUid).toBe('u_0aHrwL1tyskEWkhChJoeJg');
expect(back.filesetUuid).toBe('e7453377-c8ea-404e-9285-53aa5fad1982');
});
});
// 群聊 0x93d7:f1={f1:2, f3:{f1:groupId}}, f2=filesetUuid(groupId 直接用群号,无需转 uid)。
// 真实客户端 frida 抓包(2026-06-20),fileset e7453377 发送给群 1017438661。
const SEND_GROUP_HEX = '0a0a08021a0608c5c393e503122465373435333337372d633865612d343034652d393238352d353361613566616431393832';
const SEND_GROUP_REQ: FlashSendReq = {
target: { field1: 2, targetGroup: { groupId: 1017438661 } },
filesetUuid: 'e7453377-c8ea-404e-9285-53aa5fad1982',
};
describe('SendFlashMsg byte-oracle (0x93d7 群聊 encode == frida 抓包)', () => {
it('encodes the group send capture to the exact wire bytes', () => {
const out = Buffer.from(protobuf_encode<FlashSendReq>(SEND_GROUP_REQ)).toString('hex');
expect(out).toBe(SEND_GROUP_HEX);
});
it('round-trips: encode → decode preserves groupId', () => {
const back = protobuf_decode<FlashSendReq>(protobuf_encode<FlashSendReq>(SEND_GROUP_REQ));
expect(back.target?.field1).toBe(2);
expect(back.target?.targetGroup?.groupId).toBe(1017438661);
});
});