weflow-cli 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +149 -0
- package/bin/weflow-cli-electron.cjs +59 -0
- package/bin/weflow-cli.ts +2311 -0
- package/cli.cjs +3 -0
- package/dist/bin/weflow-cli.d.ts +3 -0
- package/dist/bin/weflow-cli.d.ts.map +1 -0
- package/dist/bin/weflow-cli.js +2270 -0
- package/dist/bin/weflow-cli.js.map +1 -0
- package/dist/mcp-server/index.d.ts +3 -0
- package/dist/mcp-server/index.d.ts.map +1 -0
- package/dist/mcp-server/index.js +690 -0
- package/dist/mcp-server/index.js.map +1 -0
- package/dist/src/core/dbPathService.d.ts +40 -0
- package/dist/src/core/dbPathService.d.ts.map +1 -0
- package/dist/src/core/dbPathService.js +324 -0
- package/dist/src/core/dbPathService.js.map +1 -0
- package/dist/src/core/keyService.d.ts +59 -0
- package/dist/src/core/keyService.d.ts.map +1 -0
- package/dist/src/core/keyService.js +368 -0
- package/dist/src/core/keyService.js.map +1 -0
- package/dist/src/core/ntCore.d.ts +62 -0
- package/dist/src/core/ntCore.d.ts.map +1 -0
- package/dist/src/core/ntCore.js +191 -0
- package/dist/src/core/ntCore.js.map +1 -0
- package/dist/src/core/sqlcipherCore.d.ts +119 -0
- package/dist/src/core/sqlcipherCore.d.ts.map +1 -0
- package/dist/src/core/sqlcipherCore.js +693 -0
- package/dist/src/core/sqlcipherCore.js.map +1 -0
- package/dist/src/core/wcdbCore.d.ts +738 -0
- package/dist/src/core/wcdbCore.d.ts.map +1 -0
- package/dist/src/core/wcdbCore.js +4545 -0
- package/dist/src/core/wcdbCore.js.map +1 -0
- package/dist/src/core/wechatClient.d.ts +23 -0
- package/dist/src/core/wechatClient.d.ts.map +1 -0
- package/dist/src/core/wechatClient.js +166 -0
- package/dist/src/core/wechatClient.js.map +1 -0
- package/dist/src/services/chatService.d.ts +25 -0
- package/dist/src/services/chatService.d.ts.map +1 -0
- package/dist/src/services/chatService.js +291 -0
- package/dist/src/services/chatService.js.map +1 -0
- package/dist/src/services/configService.d.ts +43 -0
- package/dist/src/services/configService.d.ts.map +1 -0
- package/dist/src/services/configService.js +156 -0
- package/dist/src/services/configService.js.map +1 -0
- package/dist/src/services/exportService.d.ts +30 -0
- package/dist/src/services/exportService.d.ts.map +1 -0
- package/dist/src/services/exportService.js +273 -0
- package/dist/src/services/exportService.js.map +1 -0
- package/dist/src/services/wechat-formatter.d.ts +69 -0
- package/dist/src/services/wechat-formatter.d.ts.map +1 -0
- package/dist/src/services/wechat-formatter.js +248 -0
- package/dist/src/services/wechat-formatter.js.map +1 -0
- package/dist/src/services/wechatMessageService.d.ts +28 -0
- package/dist/src/services/wechatMessageService.d.ts.map +1 -0
- package/dist/src/services/wechatMessageService.js +341 -0
- package/dist/src/services/wechatMessageService.js.map +1 -0
- package/dist/src/services/wereadService.d.ts +206 -0
- package/dist/src/services/wereadService.d.ts.map +1 -0
- package/dist/src/services/wereadService.js +145 -0
- package/dist/src/services/wereadService.js.map +1 -0
- package/dist/src/services/whitelistService.d.ts +20 -0
- package/dist/src/services/whitelistService.d.ts.map +1 -0
- package/dist/src/services/whitelistService.js +60 -0
- package/dist/src/services/whitelistService.js.map +1 -0
- package/dist/src/types.d.ts +140 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/errors.d.ts +25 -0
- package/dist/src/utils/errors.d.ts.map +1 -0
- package/dist/src/utils/errors.js +43 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/pathUtils.d.ts +5 -0
- package/dist/src/utils/pathUtils.d.ts.map +1 -0
- package/dist/src/utils/pathUtils.js +16 -0
- package/dist/src/utils/pathUtils.js.map +1 -0
- package/dist/src/utils/pythonRunner.d.ts +27 -0
- package/dist/src/utils/pythonRunner.d.ts.map +1 -0
- package/dist/src/utils/pythonRunner.js +62 -0
- package/dist/src/utils/pythonRunner.js.map +1 -0
- package/dist/src/utils/talkerUtils.d.ts +14 -0
- package/dist/src/utils/talkerUtils.d.ts.map +1 -0
- package/dist/src/utils/talkerUtils.js +73 -0
- package/dist/src/utils/talkerUtils.js.map +1 -0
- package/mcp-server/index.ts +757 -0
- package/package.json +72 -0
- package/resources/key/win32/x64/wx_key.dll +0 -0
- package/resources/wcdb/win32/x64/SDL2.dll +0 -0
- package/resources/wcdb/win32/x64/WCDB.dll +0 -0
- package/resources/wcdb/win32/x64/msvcp140.dll +0 -0
- package/resources/wcdb/win32/x64/msvcp140_1.dll +0 -0
- package/resources/wcdb/win32/x64/vcruntime140.dll +0 -0
- package/resources/wcdb/win32/x64/vcruntime140_1.dll +0 -0
- package/resources/wcdb/win32/x64/wcdb_api.dll +0 -0
- package/scripts/_batch_link_sources.py +73 -0
- package/scripts/_utils.py +531 -0
- package/scripts/annual_report.py +796 -0
- package/scripts/auto_tag.py +128 -0
- package/scripts/biz_daily.py +896 -0
- package/scripts/chat_report.py +397 -0
- package/scripts/chat_stats.py +702 -0
- package/scripts/classify_daily.py +411 -0
- package/scripts/compile_wiki.py +258 -0
- package/scripts/create_reading_notes.py +370 -0
- package/scripts/enrich_backlinks.py +163 -0
- package/scripts/export_chat_html.py +766 -0
- package/scripts/extract_3x_key.py +86 -0
- package/scripts/extract_todos.py +404 -0
- package/scripts/fav_server.py +392 -0
- package/scripts/fix_topics.py +111 -0
- package/scripts/generate_ai_report.py +367 -0
- package/scripts/generate_html.py +1372 -0
- package/scripts/generate_review.py +170 -0
- package/scripts/mcp_bridge.py +398 -0
- package/scripts/nt_decrypt.py +562 -0
- package/scripts/pipeline.py +145 -0
- package/scripts/promote_all.py +310 -0
- package/scripts/promote_ideas.py +297 -0
- package/scripts/rag_chat.py +191 -0
- package/scripts/scan_decrypt_4x.py +329 -0
- package/scripts/semantic_search.py +431 -0
- package/scripts/sync_fav.py +146 -0
- package/scripts/sync_weread.py +192 -0
- package/scripts/vault_rag.py +139 -0
- package/scripts/vault_search.py +141 -0
- package/src/core/dbPathService.ts +348 -0
- package/src/core/keyService.ts +409 -0
- package/src/core/ntCore.ts +224 -0
- package/src/core/sqlcipherCore.ts +764 -0
- package/src/core/wcdbCore.ts +4568 -0
- package/src/core/wechatClient.ts +204 -0
- package/src/lz4.d.ts +10 -0
- package/src/services/chatService.ts +296 -0
- package/src/services/configService.ts +197 -0
- package/src/services/exportService.ts +305 -0
- package/src/services/wechat-formatter.ts +348 -0
- package/src/services/wechatMessageService.ts +383 -0
- package/src/services/wereadService.ts +308 -0
- package/src/services/whitelistService.ts +72 -0
- package/src/types.ts +141 -0
- package/src/utils/errors.ts +42 -0
- package/src/utils/pathUtils.ts +16 -0
- package/src/utils/pythonRunner.ts +81 -0
- package/src/utils/talkerUtils.ts +84 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { existsSync, copyFileSync, mkdirSync } from 'fs';
|
|
3
|
+
import { execFile } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
import os from 'os';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
export class KeyService {
|
|
10
|
+
koffi = null;
|
|
11
|
+
lib = null;
|
|
12
|
+
initialized = false;
|
|
13
|
+
initHook = null;
|
|
14
|
+
pollKeyData = null;
|
|
15
|
+
getStatusMessage = null;
|
|
16
|
+
cleanupHook = null;
|
|
17
|
+
getLastErrorMsg = null;
|
|
18
|
+
// Win32 APIs
|
|
19
|
+
kernel32 = null;
|
|
20
|
+
OpenProcess = null;
|
|
21
|
+
CloseHandle = null;
|
|
22
|
+
QueryFullProcessImageNameW = null;
|
|
23
|
+
PROCESS_ALL_ACCESS = 0x1F0FFF;
|
|
24
|
+
getDllPath() {
|
|
25
|
+
const archDir = process.arch === 'arm64' ? 'arm64' : 'x64';
|
|
26
|
+
const candidates = [];
|
|
27
|
+
if (process.env.WX_KEY_DLL_PATH) {
|
|
28
|
+
candidates.push(process.env.WX_KEY_DLL_PATH);
|
|
29
|
+
}
|
|
30
|
+
const cwd = process.cwd();
|
|
31
|
+
candidates.push(join(cwd, 'resources', 'key', 'win32', archDir, 'wx_key.dll'));
|
|
32
|
+
candidates.push(join(cwd, 'resources', 'key', 'win32', 'x64', 'wx_key.dll'));
|
|
33
|
+
candidates.push(join(cwd, 'resources', 'key', 'win32', 'wx_key.dll'));
|
|
34
|
+
candidates.push(join(cwd, 'resources', 'wx_key.dll'));
|
|
35
|
+
for (const path of candidates) {
|
|
36
|
+
if (existsSync(path))
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
return candidates[0];
|
|
40
|
+
}
|
|
41
|
+
isNetworkPath(path) {
|
|
42
|
+
return path.startsWith('\\\\');
|
|
43
|
+
}
|
|
44
|
+
localizeNetworkDll(originalPath) {
|
|
45
|
+
try {
|
|
46
|
+
const tempDir = join(os.tmpdir(), 'weflow_dll_cache');
|
|
47
|
+
if (!existsSync(tempDir)) {
|
|
48
|
+
mkdirSync(tempDir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
const localPath = join(tempDir, 'wx_key.dll');
|
|
51
|
+
if (existsSync(localPath))
|
|
52
|
+
return localPath;
|
|
53
|
+
copyFileSync(originalPath, localPath);
|
|
54
|
+
return localPath;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error('DLL 本地化失败:', e);
|
|
58
|
+
return originalPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
ensureLoaded() {
|
|
62
|
+
if (this.initialized)
|
|
63
|
+
return true;
|
|
64
|
+
let dllPath = '';
|
|
65
|
+
try {
|
|
66
|
+
this.koffi = require('koffi');
|
|
67
|
+
dllPath = this.getDllPath();
|
|
68
|
+
if (!existsSync(dllPath)) {
|
|
69
|
+
console.error(`wx_key.dll 不存在: ${dllPath}`);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (this.isNetworkPath(dllPath)) {
|
|
73
|
+
dllPath = this.localizeNetworkDll(dllPath);
|
|
74
|
+
}
|
|
75
|
+
this.lib = this.koffi.load(dllPath);
|
|
76
|
+
this.initHook = this.lib.func('bool InitializeHook(uint32 targetPid)');
|
|
77
|
+
this.pollKeyData = this.lib.func('bool PollKeyData(_Out_ char *keyBuffer, int bufferSize)');
|
|
78
|
+
this.getStatusMessage = this.lib.func('bool GetStatusMessage(_Out_ char *msgBuffer, int bufferSize, _Out_ int *outLevel)');
|
|
79
|
+
this.cleanupHook = this.lib.func('bool CleanupHook()');
|
|
80
|
+
this.getLastErrorMsg = this.lib.func('const char* GetLastErrorMsg()');
|
|
81
|
+
this.initialized = true;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
86
|
+
console.error(`加载 wx_key.dll 失败: ${dllPath} - ${errorMsg}`);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
ensureKernel32() {
|
|
91
|
+
if (this.kernel32)
|
|
92
|
+
return true;
|
|
93
|
+
try {
|
|
94
|
+
this.koffi = require('koffi');
|
|
95
|
+
this.kernel32 = this.koffi.load('kernel32.dll');
|
|
96
|
+
this.OpenProcess = this.kernel32.func('OpenProcess', 'void*', ['uint32', 'bool', 'uint32']);
|
|
97
|
+
this.CloseHandle = this.kernel32.func('CloseHandle', 'bool', ['void*']);
|
|
98
|
+
this.QueryFullProcessImageNameW = this.kernel32.func('QueryFullProcessImageNameW', 'bool', ['void*', 'uint32', this.koffi.out('uint16*'), this.koffi.out('uint32*')]);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.error('初始化 kernel32 失败:', e);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
decodeUtf8(buf) {
|
|
107
|
+
const nullIdx = buf.indexOf(0);
|
|
108
|
+
return buf.toString('utf8', 0, nullIdx > -1 ? nullIdx : undefined).trim();
|
|
109
|
+
}
|
|
110
|
+
decodeCString(ptr) {
|
|
111
|
+
try {
|
|
112
|
+
if (typeof ptr === 'string')
|
|
113
|
+
return ptr;
|
|
114
|
+
return this.koffi.decode(ptr, 'char', -1);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async findPidByImageName(imageName) {
|
|
121
|
+
try {
|
|
122
|
+
const { stdout } = await execFileAsync('tasklist', ['/FI', `IMAGENAME eq ${imageName}`, '/FO', 'CSV', '/NH']);
|
|
123
|
+
const lines = stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
124
|
+
for (const line of lines) {
|
|
125
|
+
if (line.startsWith('INFO:'))
|
|
126
|
+
continue;
|
|
127
|
+
const parts = line.split('","').map((p) => p.replace(/^"|"$/g, ''));
|
|
128
|
+
if (parts[0]?.toLowerCase() === imageName.toLowerCase()) {
|
|
129
|
+
const pid = Number(parts[1]);
|
|
130
|
+
if (!Number.isNaN(pid))
|
|
131
|
+
return pid;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async findWeChatPid() {
|
|
141
|
+
const names = ['Weixin.exe', 'WeChat.exe'];
|
|
142
|
+
for (const name of names) {
|
|
143
|
+
const pid = await this.findPidByImageName(name);
|
|
144
|
+
if (pid)
|
|
145
|
+
return pid;
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
async getProcessExecutablePath(pid) {
|
|
150
|
+
if (!this.ensureKernel32())
|
|
151
|
+
return null;
|
|
152
|
+
const hProcess = this.OpenProcess(0x1000, false, pid);
|
|
153
|
+
if (!hProcess)
|
|
154
|
+
return null;
|
|
155
|
+
try {
|
|
156
|
+
const sizeBuf = Buffer.alloc(4);
|
|
157
|
+
sizeBuf.writeUInt32LE(1024, 0);
|
|
158
|
+
const pathBuf = Buffer.alloc(1024 * 2);
|
|
159
|
+
const ret = this.QueryFullProcessImageNameW(hProcess, 0, pathBuf, sizeBuf);
|
|
160
|
+
if (ret) {
|
|
161
|
+
const len = sizeBuf.readUInt32LE(0);
|
|
162
|
+
return pathBuf.toString('ucs2', 0, len * 2);
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
this.CloseHandle(hProcess);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 等待微信进程出现,立即 hook 并提取密钥
|
|
175
|
+
* 用户应在调用此方法后启动微信
|
|
176
|
+
*/
|
|
177
|
+
async waitForKey(timeoutMs = 120_000, onStatus) {
|
|
178
|
+
if (process.platform !== 'win32') {
|
|
179
|
+
return { success: false, error: '自动提取 key 仅支持 Windows' };
|
|
180
|
+
}
|
|
181
|
+
if (!this.ensureLoaded()) {
|
|
182
|
+
return { success: false, error: 'wx_key.dll 未加载,请确保 resources/key/ 目录存在' };
|
|
183
|
+
}
|
|
184
|
+
if (!this.ensureKernel32()) {
|
|
185
|
+
return { success: false, error: 'Kernel32 初始化失败' };
|
|
186
|
+
}
|
|
187
|
+
const logs = [];
|
|
188
|
+
// 等待微信进程出现
|
|
189
|
+
onStatus?.('等待微信进程出现...');
|
|
190
|
+
let pid = null;
|
|
191
|
+
const waitStart = Date.now();
|
|
192
|
+
while (Date.now() - waitStart < timeoutMs) {
|
|
193
|
+
pid = await this.findWeChatPid();
|
|
194
|
+
if (pid)
|
|
195
|
+
break;
|
|
196
|
+
await new Promise(r => setTimeout(r, 500));
|
|
197
|
+
process.stdout.write('.');
|
|
198
|
+
}
|
|
199
|
+
console.log('');
|
|
200
|
+
if (!pid) {
|
|
201
|
+
return { success: false, error: '等待超时,未检测到微信进程' };
|
|
202
|
+
}
|
|
203
|
+
onStatus?.(`检测到微信进程 (PID: ${pid}),立即 hook...`);
|
|
204
|
+
return this.extractKeyFromPid(pid, logs, onStatus);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 自动从运行中的微信进程提取数据库解密 key
|
|
208
|
+
*/
|
|
209
|
+
async autoGetDbKey(timeoutMs = 60_000, onStatus) {
|
|
210
|
+
if (process.platform !== 'win32') {
|
|
211
|
+
return { success: false, error: '自动提取 key 仅支持 Windows' };
|
|
212
|
+
}
|
|
213
|
+
if (!this.ensureLoaded()) {
|
|
214
|
+
return { success: false, error: 'wx_key.dll 未加载,请确保 resources/key/ 目录存在' };
|
|
215
|
+
}
|
|
216
|
+
if (!this.ensureKernel32()) {
|
|
217
|
+
return { success: false, error: 'Kernel32 初始化失败' };
|
|
218
|
+
}
|
|
219
|
+
const logs = [];
|
|
220
|
+
onStatus?.('正在查找微信进程...');
|
|
221
|
+
const pid = await this.findWeChatPid();
|
|
222
|
+
if (!pid) {
|
|
223
|
+
return { success: false, error: '未找到微信进程,请先启动微信并登录' };
|
|
224
|
+
}
|
|
225
|
+
onStatus?.(`检测到微信进程 (PID: ${pid}),正在提取 key...`);
|
|
226
|
+
return this.extractKeyFromPid(pid, logs, onStatus);
|
|
227
|
+
}
|
|
228
|
+
async extractKeyFromPid(pid, logs, onStatus, timeoutMs = 90_000) {
|
|
229
|
+
const ok = this.initHook(pid);
|
|
230
|
+
if (!ok) {
|
|
231
|
+
const error = this.getLastErrorMsg ? this.decodeCString(this.getLastErrorMsg()) : '';
|
|
232
|
+
if (error) {
|
|
233
|
+
if (error.includes('0xC0000022') || error.includes('ACCESS_DENIED')) {
|
|
234
|
+
return { success: false, error: '权限不足,请以管理员身份运行 CLI' };
|
|
235
|
+
}
|
|
236
|
+
return { success: false, error };
|
|
237
|
+
}
|
|
238
|
+
return { success: false, error: '初始化 Hook 失败' };
|
|
239
|
+
}
|
|
240
|
+
const keyBuffer = Buffer.alloc(128);
|
|
241
|
+
const start = Date.now();
|
|
242
|
+
let pollCount = 0;
|
|
243
|
+
try {
|
|
244
|
+
while (Date.now() - start < timeoutMs) {
|
|
245
|
+
pollCount++;
|
|
246
|
+
const pollResult = this.pollKeyData(keyBuffer, keyBuffer.length);
|
|
247
|
+
if (pollResult) {
|
|
248
|
+
const key = this.decodeUtf8(keyBuffer);
|
|
249
|
+
onStatus?.(`[调试] pollKeyData=true, key长度=${key.length}, 内容=${key.slice(0, 20)}...`);
|
|
250
|
+
if (key.length === 64) {
|
|
251
|
+
onStatus?.('密钥获取成功!');
|
|
252
|
+
return { success: true, key, logs };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (pollCount <= 5 || pollCount % 20 === 0) {
|
|
256
|
+
// 前5次和每20次输出一次调试信息
|
|
257
|
+
const hexSample = keyBuffer.slice(0, 16).toString('hex');
|
|
258
|
+
onStatus?.(`[调试] poll #${pollCount}: pollResult=${pollResult}, buffer=${hexSample}`);
|
|
259
|
+
}
|
|
260
|
+
// 读取状态消息
|
|
261
|
+
for (let i = 0; i < 5; i++) {
|
|
262
|
+
const statusBuffer = Buffer.alloc(256);
|
|
263
|
+
const levelOut = [0];
|
|
264
|
+
if (!this.getStatusMessage(statusBuffer, statusBuffer.length, levelOut))
|
|
265
|
+
break;
|
|
266
|
+
const msg = this.decodeUtf8(statusBuffer);
|
|
267
|
+
if (msg) {
|
|
268
|
+
logs.push(msg);
|
|
269
|
+
onStatus?.(msg);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
await new Promise(resolve => setTimeout(resolve, 120));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
try {
|
|
277
|
+
this.cleanupHook();
|
|
278
|
+
}
|
|
279
|
+
catch { }
|
|
280
|
+
}
|
|
281
|
+
return { success: false, error: '获取密钥超时,请确保微信已登录', logs };
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* 检测当前运行的微信版本
|
|
285
|
+
*/
|
|
286
|
+
async detectWeChatVersion() {
|
|
287
|
+
const pid3x = await this.findPidByImageName('WeChat.exe');
|
|
288
|
+
if (pid3x)
|
|
289
|
+
return '3.x';
|
|
290
|
+
const pid4x = await this.findPidByImageName('Weixin.exe');
|
|
291
|
+
if (pid4x)
|
|
292
|
+
return '4.x';
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 提取 3.x 数据库密钥 (通过 Python/pywxdump 内存搜索)
|
|
297
|
+
*/
|
|
298
|
+
async extract3xKey(onStatus) {
|
|
299
|
+
if (process.platform !== 'win32') {
|
|
300
|
+
return { success: false, error: '3.x 密钥提取仅支持 Windows' };
|
|
301
|
+
}
|
|
302
|
+
onStatus?.('正在查找 3.x 微信进程...');
|
|
303
|
+
const pid = await this.findPidByImageName('WeChat.exe');
|
|
304
|
+
if (!pid) {
|
|
305
|
+
return { success: false, error: '未找到 WeChat 3.x (WeChat.exe) 进程,请先启动 3.x 微信并登录' };
|
|
306
|
+
}
|
|
307
|
+
onStatus?.(`找到 3.x 进程 (PID: ${pid}),正在通过内存搜索提取密钥...`);
|
|
308
|
+
try {
|
|
309
|
+
const scriptPath = join(process.cwd(), 'scripts', 'extract_3x_key.py');
|
|
310
|
+
if (!existsSync(scriptPath)) {
|
|
311
|
+
return { success: false, error: `Python 脚本不存在: ${scriptPath}` };
|
|
312
|
+
}
|
|
313
|
+
const { stdout } = await execFileAsync('python', [scriptPath], {
|
|
314
|
+
timeout: 120_000,
|
|
315
|
+
maxBuffer: 1024 * 1024
|
|
316
|
+
});
|
|
317
|
+
// 过滤掉可能的警告信息,只取最后一行 JSON
|
|
318
|
+
const lines = stdout.split('\n').filter((l) => l.trim().startsWith('{'));
|
|
319
|
+
if (lines.length === 0) {
|
|
320
|
+
return { success: false, error: `Python 脚本无有效输出: ${stdout.slice(0, 200)}` };
|
|
321
|
+
}
|
|
322
|
+
const result = JSON.parse(lines[lines.length - 1]);
|
|
323
|
+
if (result.success) {
|
|
324
|
+
onStatus?.(`3.x 密钥提取成功! wxid=${result.wxid}`);
|
|
325
|
+
return {
|
|
326
|
+
success: true,
|
|
327
|
+
key: result.key,
|
|
328
|
+
wxid: result.wxid,
|
|
329
|
+
msgDir: result.msg_dir,
|
|
330
|
+
wxDir: result.wx_dir
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
return { success: false, error: result.error || '3.x 密钥提取失败' };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
const msg = e?.message || String(e);
|
|
339
|
+
if (msg.includes('ETIMEDOUT') || msg.includes('killed')) {
|
|
340
|
+
return { success: false, error: '3.x 密钥提取超时' };
|
|
341
|
+
}
|
|
342
|
+
if (msg.includes('ENOENT') || msg.includes('python')) {
|
|
343
|
+
return { success: false, error: '未找到 Python,请确保 Python 已安装并在 PATH 中' };
|
|
344
|
+
}
|
|
345
|
+
return { success: false, error: `3.x 密钥提取失败: ${msg}` };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 自动检测并提取密钥 (支持 3.x 和 4.x)
|
|
350
|
+
*/
|
|
351
|
+
async autoExtractKey(onStatus) {
|
|
352
|
+
const version = await this.detectWeChatVersion();
|
|
353
|
+
if (version === '3.x') {
|
|
354
|
+
onStatus?.('检测到 WeChat 3.x 版本,使用内存搜索方式提取密钥...');
|
|
355
|
+
return this.extract3xKey(onStatus);
|
|
356
|
+
}
|
|
357
|
+
else if (version === '4.x') {
|
|
358
|
+
onStatus?.('检测到 WeChat 4.x 版本,使用 Hook 方式提取密钥...');
|
|
359
|
+
const result = await this.autoGetDbKey(60000, onStatus);
|
|
360
|
+
return { ...result, version: '4.x' };
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
return { success: false, error: '未检测到微信进程 (WeChat.exe 或 Weixin.exe)' };
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
export const keyService = new KeyService();
|
|
368
|
+
//# sourceMappingURL=keyService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyService.js","sourceRoot":"","sources":["../../../src/core/keyService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,MAAM,IAAI,CAAA;AAGnB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAEzC,MAAM,OAAO,UAAU;IACb,KAAK,GAAQ,IAAI,CAAA;IACjB,GAAG,GAAQ,IAAI,CAAA;IACf,WAAW,GAAG,KAAK,CAAA;IACnB,QAAQ,GAAQ,IAAI,CAAA;IACpB,WAAW,GAAQ,IAAI,CAAA;IACvB,gBAAgB,GAAQ,IAAI,CAAA;IAC5B,WAAW,GAAQ,IAAI,CAAA;IACvB,eAAe,GAAQ,IAAI,CAAA;IAEnC,aAAa;IACL,QAAQ,GAAQ,IAAI,CAAA;IACpB,WAAW,GAAQ,IAAI,CAAA;IACvB,WAAW,GAAQ,IAAI,CAAA;IACvB,0BAA0B,GAAQ,IAAI,CAAA;IAE7B,kBAAkB,GAAG,QAAQ,CAAA;IAEtC,UAAU;QAChB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;QAC1D,MAAM,UAAU,GAAa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AAC,qCAAqC,CAAC,CAAA;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;YACvD,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;QACtC,CAAC;aAAM,CAAC;YACN,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,oCAAoC,EAAE,CAAA;QACxE,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ChatSession, Message, Contact } from '../types.js';
|
|
2
|
+
export interface NtResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NtSessionsResult extends NtResult {
|
|
7
|
+
sessions?: ChatSession[];
|
|
8
|
+
}
|
|
9
|
+
export interface NtMessagesResult extends NtResult {
|
|
10
|
+
messages?: Message[];
|
|
11
|
+
}
|
|
12
|
+
export interface NtContactsResult extends NtResult {
|
|
13
|
+
contacts?: Contact[];
|
|
14
|
+
}
|
|
15
|
+
export interface NtScanResult {
|
|
16
|
+
success: boolean;
|
|
17
|
+
error?: string;
|
|
18
|
+
keys?: Array<{
|
|
19
|
+
key: string;
|
|
20
|
+
salt: string;
|
|
21
|
+
}>;
|
|
22
|
+
databases?: Array<{
|
|
23
|
+
path: string;
|
|
24
|
+
name: string;
|
|
25
|
+
salt: string;
|
|
26
|
+
size: number;
|
|
27
|
+
wxid: string;
|
|
28
|
+
}>;
|
|
29
|
+
matched?: Array<{
|
|
30
|
+
path: string;
|
|
31
|
+
name: string;
|
|
32
|
+
salt: string;
|
|
33
|
+
size: number;
|
|
34
|
+
wxid: string;
|
|
35
|
+
key: string;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export declare class NtCore {
|
|
39
|
+
private dbPath;
|
|
40
|
+
private keyHex;
|
|
41
|
+
private saltHex;
|
|
42
|
+
/** contact.db 路径 (用于显示备注名/昵称) */
|
|
43
|
+
contactDbPath: string | null;
|
|
44
|
+
/** contact.db 解密密钥 */
|
|
45
|
+
contactKey: string | null;
|
|
46
|
+
/** contact.db 盐值 */
|
|
47
|
+
contactSalt: string | null;
|
|
48
|
+
constructor(dbPath: string, keyHex: string, saltHex: string);
|
|
49
|
+
/** 尝试自动发现并连接 contact.db */
|
|
50
|
+
autoDetectContactDb(): boolean;
|
|
51
|
+
private get scriptPath();
|
|
52
|
+
private callPython;
|
|
53
|
+
/**
|
|
54
|
+
* Scan memory for NT keys and match to databases.
|
|
55
|
+
* Requires WeChat to be running.
|
|
56
|
+
*/
|
|
57
|
+
static scan(): Promise<NtScanResult>;
|
|
58
|
+
getSessions(keyword?: string): Promise<NtSessionsResult>;
|
|
59
|
+
getMessages(talker: string, limit?: number, offset?: number): Promise<NtMessagesResult>;
|
|
60
|
+
getContacts(keyword?: string, limit?: number): Promise<NtContactsResult>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ntCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ntCore.d.ts","sourceRoot":"","sources":["../../../src/core/ntCore.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMhE,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;CACzB;AAED,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;CACrB;AAED,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;C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C;IAoBxD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAM,EAAE,MAAM,SAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyB/E,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoB5E"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NT Core - 4.x NT database access layer
|
|
3
|
+
*
|
|
4
|
+
* NT databases (xwechat_files/* /db_storage/message/message_0.db) use
|
|
5
|
+
* SQLCipher 4 with plaintext_header_size=0. Decryption requires the
|
|
6
|
+
* sqlcipher3 Python package. This module wraps scripts/nt_decrypt.py.
|
|
7
|
+
*/
|
|
8
|
+
import { execFile } from 'child_process';
|
|
9
|
+
import { promisify } from 'util';
|
|
10
|
+
import { existsSync } from 'fs';
|
|
11
|
+
import { join, dirname } from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
import { configService } from '../services/configService.js';
|
|
14
|
+
const execFileAsync = promisify(execFile);
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
export class NtCore {
|
|
18
|
+
dbPath;
|
|
19
|
+
keyHex;
|
|
20
|
+
saltHex;
|
|
21
|
+
/** contact.db 路径 (用于显示备注名/昵称) */
|
|
22
|
+
contactDbPath = null;
|
|
23
|
+
/** contact.db 解密密钥 */
|
|
24
|
+
contactKey = null;
|
|
25
|
+
/** contact.db 盐值 */
|
|
26
|
+
contactSalt = null;
|
|
27
|
+
constructor(dbPath, keyHex, saltHex) {
|
|
28
|
+
this.dbPath = dbPath;
|
|
29
|
+
this.keyHex = keyHex;
|
|
30
|
+
this.saltHex = saltHex;
|
|
31
|
+
}
|
|
32
|
+
/** 尝试自动发现并连接 contact.db */
|
|
33
|
+
autoDetectContactDb() {
|
|
34
|
+
// 从 message_0.db 路径推导 contact.db
|
|
35
|
+
// message_0.db: <xwechat>/<wxid>/db_storage/message/message_0.db
|
|
36
|
+
// contact.db: <xwechat>/<wxid>/db_storage/contact/contact.db
|
|
37
|
+
const msgDir = this.dbPath.replace(/\\/g, '/');
|
|
38
|
+
const parts = msgDir.split('/');
|
|
39
|
+
// 找到 db_storage 位置
|
|
40
|
+
const dbStorageIdx = parts.lastIndexOf('db_storage');
|
|
41
|
+
if (dbStorageIdx < 0)
|
|
42
|
+
return false;
|
|
43
|
+
const wxidDir = parts.slice(0, dbStorageIdx).join('/');
|
|
44
|
+
const contactDbPath = `${wxidDir}/db_storage/contact/contact.db`;
|
|
45
|
+
if (existsSync(contactDbPath)) {
|
|
46
|
+
this.contactDbPath = contactDbPath;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
get scriptPath() {
|
|
52
|
+
// __dirname = dist/src/core, so ../../.. = package root
|
|
53
|
+
const pkgRoot = join(__dirname, '..', '..', '..');
|
|
54
|
+
return join(pkgRoot, 'scripts', 'nt_decrypt.py');
|
|
55
|
+
}
|
|
56
|
+
async callPython(args) {
|
|
57
|
+
try {
|
|
58
|
+
const { stdout } = await execFileAsync('python', [this.scriptPath, ...args], {
|
|
59
|
+
timeout: 120_000,
|
|
60
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
61
|
+
env: { ...process.env, PYTHONIOENCODING: 'utf-8' },
|
|
62
|
+
encoding: 'utf-8',
|
|
63
|
+
});
|
|
64
|
+
const lines = stdout.split('\n').filter((l) => l.trim());
|
|
65
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
66
|
+
const trimmed = lines[i].trim();
|
|
67
|
+
if (trimmed.startsWith('{')) {
|
|
68
|
+
return JSON.parse(trimmed);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { error: 'No valid JSON output from Python script' };
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const msg = e?.message || String(e);
|
|
75
|
+
if (msg.includes('ENOENT') || msg.includes('python')) {
|
|
76
|
+
return { error: 'Python not found. Install Python and sqlcipher3: pip install sqlcipher3' };
|
|
77
|
+
}
|
|
78
|
+
if (msg.includes('ETIMEDOUT') || msg.includes('killed')) {
|
|
79
|
+
return { error: 'NT database query timed out' };
|
|
80
|
+
}
|
|
81
|
+
return { error: `NT database query failed: ${msg}` };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Scan memory for NT keys and match to databases.
|
|
86
|
+
* Requires WeChat to be running.
|
|
87
|
+
*/
|
|
88
|
+
static async scan() {
|
|
89
|
+
try {
|
|
90
|
+
const pkgRoot = join(__dirname, '..', '..', '..');
|
|
91
|
+
const scriptPath = join(pkgRoot, 'scripts', 'nt_decrypt.py');
|
|
92
|
+
const { stdout } = await execFileAsync('python', [scriptPath, 'scan', '--json'], {
|
|
93
|
+
timeout: 300_000,
|
|
94
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
95
|
+
env: { ...process.env, PYTHONIOENCODING: 'utf-8' },
|
|
96
|
+
encoding: 'utf-8',
|
|
97
|
+
});
|
|
98
|
+
const lines = stdout.split('\n').filter((l) => l.trim());
|
|
99
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
100
|
+
const trimmed = lines[i].trim();
|
|
101
|
+
if (trimmed.startsWith('{')) {
|
|
102
|
+
const result = JSON.parse(trimmed);
|
|
103
|
+
if (result.error) {
|
|
104
|
+
return { success: false, error: result.error };
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
success: true,
|
|
108
|
+
keys: result.keys || [],
|
|
109
|
+
databases: result.databases || [],
|
|
110
|
+
matched: result.matched || [],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { success: false, error: 'Scan produced no valid output' };
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
const msg = e?.message || String(e);
|
|
118
|
+
if (msg.includes('ENOENT') || msg.includes('python')) {
|
|
119
|
+
return { success: false, error: 'Python not found. Install Python and add to PATH.' };
|
|
120
|
+
}
|
|
121
|
+
return { success: false, error: `NT scan failed: ${msg}` };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async getSessions(keyword) {
|
|
125
|
+
const args = [
|
|
126
|
+
'sessions',
|
|
127
|
+
'--db', this.dbPath,
|
|
128
|
+
'--key', this.keyHex,
|
|
129
|
+
'--salt', this.saltHex,
|
|
130
|
+
];
|
|
131
|
+
if (keyword)
|
|
132
|
+
args.push('--keyword', keyword);
|
|
133
|
+
if (this.contactDbPath && this.contactKey && this.contactSalt) {
|
|
134
|
+
args.push('--contact-db', this.contactDbPath);
|
|
135
|
+
args.push('--contact-key', this.contactKey);
|
|
136
|
+
args.push('--contact-salt', this.contactSalt);
|
|
137
|
+
}
|
|
138
|
+
const result = await this.callPython(args);
|
|
139
|
+
if (result.error) {
|
|
140
|
+
return { success: false, error: result.error };
|
|
141
|
+
}
|
|
142
|
+
return { success: true, sessions: result.sessions || [] };
|
|
143
|
+
}
|
|
144
|
+
async getMessages(talker, limit = 100, offset = 0) {
|
|
145
|
+
const args = [
|
|
146
|
+
'messages',
|
|
147
|
+
'--db', this.dbPath,
|
|
148
|
+
'--key', this.keyHex,
|
|
149
|
+
'--salt', this.saltHex,
|
|
150
|
+
'--talker', talker,
|
|
151
|
+
'--limit', String(limit),
|
|
152
|
+
'--offset', String(offset),
|
|
153
|
+
];
|
|
154
|
+
if (this.contactDbPath && this.contactKey && this.contactSalt) {
|
|
155
|
+
args.push('--contact-db', this.contactDbPath);
|
|
156
|
+
args.push('--contact-key', this.contactKey);
|
|
157
|
+
args.push('--contact-salt', this.contactSalt);
|
|
158
|
+
}
|
|
159
|
+
// Pass own wxid from config for self-message detection
|
|
160
|
+
const ownWxid = configService.get('wxid');
|
|
161
|
+
if (ownWxid)
|
|
162
|
+
args.push('--own-wxid', ownWxid);
|
|
163
|
+
const result = await this.callPython(args);
|
|
164
|
+
if (result.error) {
|
|
165
|
+
return { success: false, error: result.error };
|
|
166
|
+
}
|
|
167
|
+
return { success: true, messages: result.messages || [] };
|
|
168
|
+
}
|
|
169
|
+
async getContacts(keyword, limit = 200) {
|
|
170
|
+
const args = [
|
|
171
|
+
'contacts',
|
|
172
|
+
'--db', this.dbPath,
|
|
173
|
+
'--key', this.keyHex,
|
|
174
|
+
'--salt', this.saltHex,
|
|
175
|
+
'--limit', String(limit),
|
|
176
|
+
];
|
|
177
|
+
if (keyword)
|
|
178
|
+
args.push('--keyword', keyword);
|
|
179
|
+
if (this.contactDbPath && this.contactKey && this.contactSalt) {
|
|
180
|
+
args.push('--contact-db', this.contactDbPath);
|
|
181
|
+
args.push('--contact-key', this.contactKey);
|
|
182
|
+
args.push('--contact-salt', this.contactSalt);
|
|
183
|
+
}
|
|
184
|
+
const result = await this.callPython(args);
|
|
185
|
+
if (result.error) {
|
|
186
|
+
return { success: false, error: result.error };
|
|
187
|
+
}
|
|
188
|
+
return { success: true, contacts: result.contacts || [] };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=ntCore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ntCore.js","sourceRoot":"","sources":["../../../src/core/ntCore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAG5D,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AACzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GA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