From dc168bf8b94b04da084543d947c7abba91f6872c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?=
 <nanaeonn@outlook.com>
Date: Sat, 12 Oct 2024 22:25:10 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20proto=20=E6=95=B4=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/core/apis/group.ts                  | 13 ++++-------
 src/core/proto/ImageFileId.ts           | 21 -----------------
 src/core/proto/Oidb.fe1_2.ts            | 21 -----------------
 src/core/proto/OidbBase.ts              | 16 -------------
 src/core/proto/Poke.ts                  | 31 -------------------------
 src/core/proto/oidb/Oidb.ed3_1.ts       |  9 +++++++
 src/core/proto/oidb/Oidb.fe1_2.ts       |  7 ++++++
 src/core/proto/oidb/OidbBase.ts         |  9 +++++++
 src/core/proto/{ => old}/Message.ts     |  0
 src/core/proto/{ => old}/ProfileLike.ts |  0
 src/onebot/api/msg.ts                   |  2 +-
 src/onebot/api/user.ts                  |  2 +-
 src/onebot/index.ts                     |  2 +-
 13 files changed, 32 insertions(+), 101 deletions(-)
 delete mode 100644 src/core/proto/ImageFileId.ts
 delete mode 100644 src/core/proto/Oidb.fe1_2.ts
 delete mode 100644 src/core/proto/OidbBase.ts
 delete mode 100644 src/core/proto/Poke.ts
 create mode 100644 src/core/proto/oidb/Oidb.ed3_1.ts
 create mode 100644 src/core/proto/oidb/Oidb.fe1_2.ts
 create mode 100644 src/core/proto/oidb/OidbBase.ts
 rename src/core/proto/{ => old}/Message.ts (100%)
 rename src/core/proto/{ => old}/ProfileLike.ts (100%)

diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts
index 03e5e021..cee1a91a 100644
--- a/src/core/apis/group.ts
+++ b/src/core/apis/group.ts
@@ -12,10 +12,9 @@ import {
 import { isNumeric, sleep, solveAsyncProblem } from '@/common/helper';
 import { LimitedHashTable } from '@/common/message-unique';
 import { NTEventWrapper } from '@/common/event';
-import { randomUUID } from 'crypto';
-import { RequestUtil } from '@/common/request';
 import { NapProtoMsg } from '../proto/NapProto';
-import { OidbSvcTrpcTcp0XED3_1, OidbSvcTrpcTcpBaseProto } from '../proto/OidbBase';
+import {  OidbSvcTrpcTcpBase } from '../proto/oidb/OidbBase';
+import { OidbSvcTrpcTcp0XED3_1 } from '../proto/oidb/Oidb.ed3_1';
 interface recvPacket {
     type: string,//仅recv
     trace_id_md5?: string,
@@ -46,11 +45,7 @@ export class NTQQGroupApi {
             this.groupCache.set(group.groupCode, group);
         }
         this.context.logger.logDebug(`加载${this.groups.length}个群组缓存完成`);
-        //console.log('pid', process.pid);
-        // this.session = await frida.attach(process.pid);
-        // setTimeout(async () => {
-        //     this.sendPocketRkey();
-        // }, 10000);
+        // process.pid 调试点
     }
     async getCoreAndBaseInfo(uids: string[]) {
         return await this.core.eventWrapper.callNoListenerEvent(
@@ -70,7 +65,7 @@ export class NTQQGroupApi {
             groupUin: group,
             ext: 0
         });
-        let oidb_packet = new NapProtoMsg(OidbSvcTrpcTcpBaseProto).encode({
+        let oidb_packet = new NapProtoMsg(OidbSvcTrpcTcpBase).encode({
             command: 0xed3,
             subCommand: 1,
             body: oidb_0xed3
diff --git a/src/core/proto/ImageFileId.ts b/src/core/proto/ImageFileId.ts
deleted file mode 100644
index 25ad0ee7..00000000
--- a/src/core/proto/ImageFileId.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { MessageType, BinaryReader, ScalarType, BinaryWriter } from '@protobuf-ts/runtime';
-
-export const FileId = new MessageType("FileId", [
-    { no: 2, name: "sha1", kind: "scalar", T: ScalarType.BYTES },
-    { no: 4, name: "appid", kind: "scalar", T: ScalarType.UINT32 },
-]);
-
-export function encodePBFileId(message: any) {
-    return FileId.internalBinaryWrite(message, new BinaryWriter(), {
-        writerFactory: () => new BinaryWriter(),
-        writeUnknownFields: false
-    }).finish();
-}
-
-export function decodePBFileId(buffer: Uint8Array): any {
-    const reader = new BinaryReader(buffer);
-    return FileId.internalBinaryRead(reader, reader.len, {
-        readUnknownField: true,
-        readerFactory: () => new BinaryReader(buffer)
-    });
-}
\ No newline at end of file
diff --git a/src/core/proto/Oidb.fe1_2.ts b/src/core/proto/Oidb.fe1_2.ts
deleted file mode 100644
index 2af198c6..00000000
--- a/src/core/proto/Oidb.fe1_2.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { MessageType, ScalarType } from "@protobuf-ts/runtime";
-import { OidbSvcTrpcTcpBase } from "./Poke";
-
-export const OidbSvcTrpcTcp0XFE1_2 = new MessageType("oidb_svc_trpctcp_0xfe1_2", [
-    { no: 1, name: "uin", kind: "scalar", T: ScalarType.UINT32 },
-    { no: 3, name: "key", kind: "scalar", T: ScalarType.BYTES, opt: true }
-]);
-export function encode_packet_0xfe1_2(PeerUin: string) {
-    let Body = OidbSvcTrpcTcp0XFE1_2.toBinary
-        ({
-            uin: parseInt(PeerUin),
-            key: new Uint8Array([0x00, 0x00, 0x00, 0x00])
-        });
-    return OidbSvcTrpcTcpBase.toBinary
-        ({
-            command: 0xfe1,
-            subcommand: 2,
-            body: Body,
-            isreserved: 1
-        });
-}
\ No newline at end of file
diff --git a/src/core/proto/OidbBase.ts b/src/core/proto/OidbBase.ts
deleted file mode 100644
index 3f63f898..00000000
--- a/src/core/proto/OidbBase.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { ProtoField } from "./NapProto";
-import { ScalarType } from '@protobuf-ts/runtime';
-
-export const OidbSvcTrpcTcpBaseProto = {
-    command: ProtoField(1, ScalarType.UINT32),
-    subCommand: ProtoField(2, ScalarType.UINT32),
-    body: ProtoField(4, ScalarType.BYTES),
-    isReserved: ProtoField(12, ScalarType.UINT32, false, true)
-}
-
-export const OidbSvcTrpcTcp0XED3_1 = {
-    uin: ProtoField(1, ScalarType.UINT32),
-    groupUin: ProtoField(2, ScalarType.UINT32, false, true),
-    friendUin: ProtoField(5, ScalarType.BYTES, false, true),
-    ext: ProtoField(6, ScalarType.UINT32)
-}
\ No newline at end of file
diff --git a/src/core/proto/Poke.ts b/src/core/proto/Poke.ts
deleted file mode 100644
index 262f0e9b..00000000
--- a/src/core/proto/Poke.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-// import { MessageType, ScalarType, BinaryWriter } from '@protobuf-ts/runtime';
-
-// export const OidbSvcTrpcTcpBase = new MessageType("oidb_svc_trpctcp_base", [
-//     { no: 1, name: "command", kind: "scalar", T: ScalarType.UINT32 },
-//     { no: 2, name: "subcommand", kind: "scalar", T: ScalarType.UINT32, opt: true },
-//     { no: 4, name: "body", kind: "scalar", T: ScalarType.BYTES, opt: true },
-//     { no: 12, name: "isreserved", kind: "scalar", T: ScalarType.INT32, opt: true }
-// ]);
-
-// export const OidbSvcTrpcTcp0XED3_1 = new MessageType("oidb_svc_trpctcp_0xed3_1", [
-//     { no: 1, name: "uin", kind: "scalar", T: ScalarType.UINT32 },
-//     { no: 2, name: "groupuin", kind: "scalar", T: ScalarType.UINT32, opt: true },
-//     { no: 5, name: "frienduin", kind: "scalar", T: ScalarType.UINT32, opt: true },
-//     { no: 6, name: "ext", kind: "scalar", T: ScalarType.UINT32 }
-// ]);
-
-// export function encodeGroupPoke(groupUin: number, PeerUin: number) {
-//     let Body = OidbSvcTrpcTcp0XED3_1.toBinary
-//         ({
-//             uin: PeerUin,
-//             groupuin: groupUin,
-//             ext: 0
-//         });
-//     //console.log(Body)
-//     return OidbSvcTrpcTcpBase.toBinary
-//         ({
-//             command: 0xed3,
-//             subcommand: 1,
-//             body: Body
-//         });
-// }
\ No newline at end of file
diff --git a/src/core/proto/oidb/Oidb.ed3_1.ts b/src/core/proto/oidb/Oidb.ed3_1.ts
new file mode 100644
index 00000000..441b7335
--- /dev/null
+++ b/src/core/proto/oidb/Oidb.ed3_1.ts
@@ -0,0 +1,9 @@
+import { ScalarType } from "@protobuf-ts/runtime";
+import { ProtoField } from "../NapProto";
+
+export const OidbSvcTrpcTcp0XED3_1 = {
+    uin: ProtoField(1, ScalarType.UINT32),
+    groupUin: ProtoField(2, ScalarType.UINT32, false, true),
+    friendUin: ProtoField(5, ScalarType.BYTES, false, true),
+    ext: ProtoField(6, ScalarType.UINT32)
+}
\ No newline at end of file
diff --git a/src/core/proto/oidb/Oidb.fe1_2.ts b/src/core/proto/oidb/Oidb.fe1_2.ts
new file mode 100644
index 00000000..414c66a6
--- /dev/null
+++ b/src/core/proto/oidb/Oidb.fe1_2.ts
@@ -0,0 +1,7 @@
+import {  ScalarType } from "@protobuf-ts/runtime";
+import { ProtoField } from "../NapProto";
+
+export const OidbSvcTrpcTcp0XEE1_2 = {
+    uin: ProtoField(1, ScalarType.UINT32),
+    key: ProtoField(3, ScalarType.BYTES, false, true),
+}
\ No newline at end of file
diff --git a/src/core/proto/oidb/OidbBase.ts b/src/core/proto/oidb/OidbBase.ts
new file mode 100644
index 00000000..ac6538ee
--- /dev/null
+++ b/src/core/proto/oidb/OidbBase.ts
@@ -0,0 +1,9 @@
+import { ProtoField } from "../NapProto";
+import { ScalarType } from '@protobuf-ts/runtime';
+
+export const OidbSvcTrpcTcpBase = {
+    command: ProtoField(1, ScalarType.UINT32),
+    subCommand: ProtoField(2, ScalarType.UINT32),
+    body: ProtoField(4, ScalarType.BYTES),
+    isReserved: ProtoField(12, ScalarType.UINT32, false, true)
+}
\ No newline at end of file
diff --git a/src/core/proto/Message.ts b/src/core/proto/old/Message.ts
similarity index 100%
rename from src/core/proto/Message.ts
rename to src/core/proto/old/Message.ts
diff --git a/src/core/proto/ProfileLike.ts b/src/core/proto/old/ProfileLike.ts
similarity index 100%
rename from src/core/proto/ProfileLike.ts
rename to src/core/proto/old/ProfileLike.ts
diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts
index 61279f9c..2b28401c 100644
--- a/src/onebot/api/msg.ts
+++ b/src/onebot/api/msg.ts
@@ -34,7 +34,7 @@ import { RequestUtil } from '@/common/request';
 import fs from 'node:fs';
 import fsPromise from 'node:fs/promises';
 import { OB11FriendAddNoticeEvent } from '@/onebot/event/notice/OB11FriendAddNoticeEvent';
-import { decodeSysMessage } from '@/core/proto/ProfileLike';
+import { decodeSysMessage } from '@/core/proto/old/ProfileLike';
 
 type RawToOb11Converters = {
     [Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
diff --git a/src/onebot/api/user.ts b/src/onebot/api/user.ts
index 716a5803..67621a49 100644
--- a/src/onebot/api/user.ts
+++ b/src/onebot/api/user.ts
@@ -1,5 +1,5 @@
 import { NapCatCore } from '@/core';
-import { decodeProfileLikeTip } from '@/core/proto/ProfileLike';
+import { decodeProfileLikeTip } from '@/core/proto/old/ProfileLike';
 
 import { NapCatOneBot11Adapter } from '@/onebot';
 import { OB11ProfileLikeEvent } from '../event/notice/OB11ProfileLikeEvent';
diff --git a/src/onebot/index.ts b/src/onebot/index.ts
index 0882589b..a7e9fd33 100644
--- a/src/onebot/index.ts
+++ b/src/onebot/index.ts
@@ -45,7 +45,7 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecal
 import { LRUCache } from '@/common/lru-cache';
 import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
 import { Native } from '@/native';
-import { decodeMessage, decodeRecallGroup, Message, RecallGroup } from '@/core/proto/Message';
+import { decodeMessage, decodeRecallGroup, Message, RecallGroup } from '@/core/proto/old/Message';
 
 //OneBot实现类
 export class NapCatOneBot11Adapter {