Files
SnowLuma/packages/protocol/tests/oidb-services/_pb-oracle.ts
T
DrSmoothl 43cd4a0b99 feat(onebot): TierB ③ — RE'd OIDB actions (ark share / doubt friends / robot-add)
All recovered from QQNT wrapper.linux.node via IDA — NapCat ships these as
kernel-only with no portable packet wire, so each cmd + protobuf was traced
from the binary (worker ctor cmd/subcmd via BaseOidbWorker::DoSendOidbReq;
field tags from the per-feature EncodeRequest). All uin-form OIDB (envelope
reserved=1, matching the NT worker flag=1). One commit for easy rollback.

New OIDB services + byte-oracle tests (fixed-wire, mutation-resistant):
- 0x9130_0 getBuddyRecommendContactArkJson → share_peer/send_ark_share (user)
- 0x8b7_5  getGroupRecommendContactArkJson → share_peer/send_ark_share (group),
           share_group_ex/send_group_ark_share (NapCat's getArkJsonGroupShare
           was NOT RE'd; routed to this confident equivalent — documented)
- 0xd69_0  getDoubtBuddyReq → get_doubt_friends_add_request
- 0xd69_0  approvalDoubtBuddyReq → set_doubt_friends_add_request (approve only)
- 0xf00_3  modifyGroupExtInfoV2 → set_group_robot_add_option (EXTInfo tags
           30/31; GroupExtFilter is client-side gating, not on the wire)

NOT shipped (kernel-.so-side, no static cmd recoverable from this binary —
honest, no guessed packets): get_robot_uin_range (trpc method-routed),
create_collection/get_collection_list (Weiyun multi-step), trans_group_file.

Doubt-list string field NAMES (nick/source/msg) are medium-confidence
(generic serializer); uid+reqTime are high. READ path, so a mislabel is
cosmetic, never a wire/ban risk. Wired through bridge friend/contacts/
groupAdmin apis; proto-defs + per-file subpath exports registered.
2026-06-18 21:12:29 +08:00

55 lines
1.8 KiB
TypeScript

// Independent protobuf byte-oracle helpers for OIDB service tests.
//
// These build expected wire bytes from FIRST PRINCIPLES (the RE'd tag
// numbers), NOT via proton — so asserting `proton.encode(...) === pb.env(...)`
// goes red if a proto-defs field tag is wrong or silently changes. A
// symmetric encode→decode round-trip can't catch a tag swap; this can.
//
// Emission rules mirror proton's observed behaviour: fields in ASCENDING
// tag order, and proto3 defaults (0 / '' / false) OMITTED.
function uvarint(n: number): number[] {
const out: number[] = [];
let x = n;
do {
let b = x % 128;
x = Math.floor(x / 128);
if (x > 0) b |= 0x80;
out.push(b);
} while (x > 0);
return out;
}
function tag(field: number, wire: number): number[] {
return uvarint(field * 8 + wire);
}
/** varint field (wire type 0). */
export function v(field: number, value: number): number[] {
return [...tag(field, 0), ...uvarint(value)];
}
/** length-delimited string field (wire type 2). */
export function s(field: number, str: string): number[] {
const b = [...Buffer.from(str, 'utf8')];
return [...tag(field, 2), ...uvarint(b.length), ...b];
}
/** length-delimited sub-message field (wire type 2). */
export function m(field: number, msg: number[]): number[] {
return [...tag(field, 2), ...uvarint(msg.length), ...msg];
}
/**
* Wrap a body in the OidbBase envelope exactly as proton emits it:
* command(1), subCommand(2) [omitted when 0], body(4), reserved(12)=1
* [only when uinForm]. errorCode(3)/errorMsg(5) are defaults → omitted.
*/
export function env(command: number, subCommand: number, body: number[], uinForm: boolean): string {
const out = [...v(1, command)];
if (subCommand !== 0) out.push(...v(2, subCommand));
out.push(...m(4, body));
if (uinForm) out.push(...v(12, 1));
return Buffer.from(out).toString('hex');
}