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.
This commit is contained in:
21 files changed
+931
No files matched your search
@@ -0,0 +1,54 @@
|
||||
// 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');
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbBuddyRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetBuddyRecommendArk } from '../../../src/oidb-services/contacts/get-buddy-recommend-ark';
|
||||
import { env, v, s } from '../_pb-oracle';
|
||||
|
||||
function makeSender(arkJson = '{"app":"com.tencent.contact.lua"}') {
|
||||
const respEnv: OidbBase<OidbBuddyRecommendArkResp> = { command: 0x9130, subCommand: 0, body: { arkJson } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbBuddyRecommendArkResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetBuddyRecommendArk namespace', () => {
|
||||
it('declares command 0x9130 sub 0, uin form', () => {
|
||||
expect(GetBuddyRecommendArk.command).toBe(0x9130);
|
||||
expect(GetBuddyRecommendArk.subCommand).toBe(0);
|
||||
expect(GetBuddyRecommendArk.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes uin + the hard-coded jump_url template (phone defaults to empty)', () => {
|
||||
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 5 });
|
||||
expect(out).toMatchObject({ uin: 5, phoneNum: '' });
|
||||
expect(out.jumpUrl).toBe('mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=5');
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0x9130_0 and locks req tags {1:uin, 2:phone, 3:jumpUrl}', async () => {
|
||||
const sender = makeSender();
|
||||
const ark = await GetBuddyRecommendArk.invoke(sender, { userId: 10000 });
|
||||
expect(ark).toBe('{"app":"com.tencent.contact.lua"}');
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x9130_0');
|
||||
const jumpUrl = 'mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=10000';
|
||||
// phoneNum '' is a proto3 default → omitted; only tags 1 + 3 present.
|
||||
const body = [...v(1, 10000), ...s(3, jumpUrl)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x9130, 0, body, true));
|
||||
});
|
||||
|
||||
it('includes phone tag 2 when a phone number is provided', () => {
|
||||
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 7, phoneNumber: '123' });
|
||||
expect(out.phoneNum).toBe('123');
|
||||
});
|
||||
|
||||
it('deserialize returns the ark json string ("" when absent)', () => {
|
||||
expect(GetBuddyRecommendArk.deserialize({} as any, { arkJson: 'x' })).toBe('x');
|
||||
expect(GetBuddyRecommendArk.deserialize({} as any, {})).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetGroupRecommendArk } from '../../../src/oidb-services/contacts/get-group-recommend-ark';
|
||||
import { env, v } from '../_pb-oracle';
|
||||
|
||||
function makeSender(arkJson = '{"app":"com.tencent.structmsg"}') {
|
||||
const respEnv: OidbBase<OidbGroupRecommendArkResp> = { command: 0x8B7, subCommand: 5, body: { errCode: 0, arkJson } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbGroupRecommendArkResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupRecommendArk namespace', () => {
|
||||
it('declares command 0x8B7 sub 5, uin form', () => {
|
||||
expect(GetGroupRecommendArk.command).toBe(0x8B7);
|
||||
expect(GetGroupRecommendArk.subCommand).toBe(5);
|
||||
expect(GetGroupRecommendArk.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes the constant reqType=1 / flag=1 + group code', () => {
|
||||
expect(GetGroupRecommendArk.serialize({} as any, { groupId: 999 })).toEqual({ reqType: 1, groupCode: 999, flag: 1 });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0x8b7_5 and locks req tags {1:reqType, 2:groupCode, 5:flag}', async () => {
|
||||
const sender = makeSender();
|
||||
const ark = await GetGroupRecommendArk.invoke(sender, { groupId: 12345 });
|
||||
expect(ark).toBe('{"app":"com.tencent.structmsg"}');
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x8b7_5');
|
||||
const body = [...v(1, 1), ...v(2, 12345), ...v(5, 1)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x8B7, 5, body, true));
|
||||
});
|
||||
|
||||
it('deserialize returns the ark json from response field 5', () => {
|
||||
expect(GetGroupRecommendArk.deserialize({} as any, { errCode: 0, arkJson: 'g' })).toBe('g');
|
||||
expect(GetGroupRecommendArk.deserialize({} as any, {})).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { ApproveDoubtBuddyReq } from '../../../src/oidb-services/friend/approve-doubt-buddy-req';
|
||||
import { env, s } from '../_pb-oracle';
|
||||
|
||||
function makeSender() {
|
||||
const respEnv: OidbBase<OidbEmpty> = { command: 0xD69, subCommand: 0, body: {} };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbEmpty>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('ApproveDoubtBuddyReq namespace', () => {
|
||||
it('declares command 0xD69 sub 0, uin form', () => {
|
||||
expect(ApproveDoubtBuddyReq.command).toBe(0xD69);
|
||||
expect(ApproveDoubtBuddyReq.subCommand).toBe(0);
|
||||
expect(ApproveDoubtBuddyReq.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes the uid into both tag 1 and tag 2 (str1/str2 omitted, matching NapCat approve flow)', () => {
|
||||
expect(ApproveDoubtBuddyReq.serialize({} as any, { uid: 'u_x' })).toEqual({ uid: 'u_x', targetUid: 'u_x' });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xd69_0 and locks req tags {1:uid, 2:uid}', async () => {
|
||||
const sender = makeSender();
|
||||
await ApproveDoubtBuddyReq.invoke(sender, { uid: 'u_abc' });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
|
||||
const body = [...s(1, 'u_abc'), ...s(2, 'u_abc')];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbDoubtGetResp } from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetDoubtBuddyReq } from '../../../src/oidb-services/friend/get-doubt-buddy-req';
|
||||
import { env, v, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender(): { sendRawPacket: ReturnType<typeof vi.fn> } {
|
||||
const respEnv: OidbBase<OidbDoubtGetResp> = {
|
||||
command: 0xD69, subCommand: 0,
|
||||
body: { status: 1, body: { list: [
|
||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000n },
|
||||
], reason: '' } },
|
||||
};
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbDoubtGetResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetDoubtBuddyReq namespace', () => {
|
||||
it('declares command 0xD69 sub 0, uin form', () => {
|
||||
expect(GetDoubtBuddyReq.command).toBe(0xD69);
|
||||
expect(GetDoubtBuddyReq.subCommand).toBe(0);
|
||||
expect(GetDoubtBuddyReq.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes {1:1, 2:{1:count, 2:uk}} (reqId is not on the wire)', () => {
|
||||
expect(GetDoubtBuddyReq.serialize({} as any, { count: 50 })).toEqual({ field1: 1, inner: { num: 50, uk: '' } });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xd69_0 and locks nested req tags {1:const1, 2:{1:num, 2:uk}}', async () => {
|
||||
const sender = makeSender();
|
||||
await GetDoubtBuddyReq.invoke(sender, { count: 50 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
|
||||
// uk '' omitted (proto3 default); inner carries only num.
|
||||
const inner = [...v(1, 50)];
|
||||
const body = [...v(1, 1), ...m(2, inner)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
|
||||
});
|
||||
|
||||
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
|
||||
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
|
||||
expect(list).toEqual([
|
||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000 },
|
||||
]);
|
||||
});
|
||||
|
||||
it('deserialize returns [] when the body has no list', () => {
|
||||
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbModifyGroupExtResp } from '@snowluma/proto-defs/oidb-actions/group-ext';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { ModifyGroupExtInfo } from '../../../src/oidb-services/group-admin/modify-group-ext-info';
|
||||
import { env, v, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender(result = 0) {
|
||||
const respEnv: OidbBase<OidbModifyGroupExtResp> = { command: 0xF00, subCommand: 3, body: { groupCode: 12345, result } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbModifyGroupExtResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('ModifyGroupExtInfo namespace', () => {
|
||||
it('declares command 0xF00 sub 3, uin form', () => {
|
||||
expect(ModifyGroupExtInfo.command).toBe(0xF00);
|
||||
expect(ModifyGroupExtInfo.subCommand).toBe(3);
|
||||
expect(ModifyGroupExtInfo.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('only includes the fields the caller provides', () => {
|
||||
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1, robotMemberSwitch: 1 }))
|
||||
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: { inviteRobotMemberSwitch: 1 } } });
|
||||
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1 }))
|
||||
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: {} } });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xf00_3 and locks nested tags {1:gc,2:{1:gc,2:{30:switch,31:examine}}}', async () => {
|
||||
const sender = makeSender();
|
||||
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 1, robotMemberExamine: 2 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xf00_3');
|
||||
const ext = [...v(30, 1), ...v(31, 2)];
|
||||
const info = [...v(1, 12345), ...m(2, ext)];
|
||||
const body = [...v(1, 12345), ...m(2, info)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
|
||||
});
|
||||
|
||||
it('CAVEAT: a value of 0 is omitted on the wire (proto3 default) — documents the disable edge', async () => {
|
||||
const sender = makeSender();
|
||||
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0 });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
// tag 30 varint = 0xF0 0x01; with value 0 it must NOT appear on the wire.
|
||||
expect(Buffer.from(bytes).toString('hex')).not.toContain('f001');
|
||||
});
|
||||
|
||||
it('deserialize throws on a non-zero body result', () => {
|
||||
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 5 })).toThrow(/result=5/);
|
||||
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 0 })).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user