@chainlesschain/personal-data-hub 0.1.0 → 0.2.1
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/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +211 -0
- package/__tests__/adapters/ai-chat-health-checker.test.js +262 -0
- package/__tests__/adapters/ai-chat-history.test.js +396 -0
- package/__tests__/adapters/ai-chat-http-client.test.js +242 -0
- package/__tests__/adapters/ai-chat-vendors.test.js +874 -0
- package/__tests__/adapters/alipay-bill-adapter.test.js +538 -0
- package/__tests__/adapters/email-adapter.test.js +138 -1
- package/__tests__/adapters/email-classifier.test.js +347 -0
- package/__tests__/adapters/email-pdf-extractor.test.js +529 -0
- package/__tests__/adapters/email-retry-progress.test.js +294 -0
- package/__tests__/adapters/email-templates.test.js +699 -0
- package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +269 -0
- package/__tests__/adapters/system-data-adapter.test.js +440 -0
- package/__tests__/adapters/system-data-android-ingest.test.js +144 -0
- package/__tests__/adapters/system-data-android.test.js +387 -0
- package/__tests__/adapters/system-data-disclosure.test.js +153 -0
- package/__tests__/adapters/wechat-bootstrap.test.js +240 -0
- package/__tests__/adapters/wechat-env-probe.test.js +162 -0
- package/__tests__/adapters/wechat-frida-agent.test.js +191 -0
- package/__tests__/adapters/wechat-frida-integration.test.js +149 -0
- package/__tests__/adapters/wechat-frida-key-provider.test.js +188 -0
- package/__tests__/adapters/wechat-md5-key-provider.test.js +101 -0
- package/__tests__/analysis-skills.test.js +556 -0
- package/__tests__/analysis.test.js +329 -1
- package/__tests__/e2e/ai-chat-cross-source-journey.test.js +213 -0
- package/__tests__/e2e/full-user-journey.test.js +188 -0
- package/__tests__/entity-resolver-ingest-hook.test.js +177 -0
- package/__tests__/entity-resolver-stages.test.js +411 -0
- package/__tests__/entity-resolver-vault.test.js +246 -0
- package/__tests__/entity-resolver.test.js +526 -0
- package/__tests__/fixtures/entity-resolver-200-mock.json +96 -0
- package/__tests__/integration/ai-chat-history-registry.test.js +228 -0
- package/__tests__/integration/aichat-wizard-end-to-end.test.js +282 -0
- package/__tests__/integration/cross-adapter-pipelines.test.js +396 -0
- package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +390 -0
- package/__tests__/longtail-adapters.test.js +217 -0
- package/__tests__/mobile-extractor.test.js +288 -0
- package/__tests__/registry.test.js +4 -2
- package/__tests__/shopping-adapters.test.js +296 -0
- package/__tests__/sidecar-contacts-cross-validate.test.js +163 -0
- package/__tests__/sidecar-supervisor.test.js +120 -0
- package/__tests__/social-adapters.test.js +206 -0
- package/__tests__/travel-adapters.test.js +325 -0
- package/__tests__/vault.test.js +3 -3
- package/__tests__/wechat-adapter.test.js +476 -0
- package/__tests__/whatsapp-adapter.test.js +135 -0
- package/lib/adapter-spec.js +12 -0
- package/lib/adapters/_python-sidecar-base.js +207 -0
- package/lib/adapters/ai-chat-history/ai-chat-adapter.js +374 -0
- package/lib/adapters/ai-chat-history/cookie-auth.js +109 -0
- package/lib/adapters/ai-chat-history/cookie-capture-spec.js +331 -0
- package/lib/adapters/ai-chat-history/health-checker.js +210 -0
- package/lib/adapters/ai-chat-history/http-client.js +211 -0
- package/lib/adapters/ai-chat-history/index.js +28 -0
- package/lib/adapters/ai-chat-history/schema-map.js +258 -0
- package/lib/adapters/ai-chat-history/vendor-spec.js +86 -0
- package/lib/adapters/ai-chat-history/vendors/coze.js +179 -0
- package/lib/adapters/ai-chat-history/vendors/deepseek.js +199 -0
- package/lib/adapters/ai-chat-history/vendors/doubao.js +255 -0
- package/lib/adapters/ai-chat-history/vendors/dreamina.js +174 -0
- package/lib/adapters/ai-chat-history/vendors/hunyuan.js +176 -0
- package/lib/adapters/ai-chat-history/vendors/kimi.js +182 -0
- package/lib/adapters/ai-chat-history/vendors/qianfan.js +160 -0
- package/lib/adapters/ai-chat-history/vendors/tongyi.js +193 -0
- package/lib/adapters/ai-chat-history/vendors/zhipu.js +202 -0
- package/lib/adapters/ai-chat-history/wizard-controller.js +473 -0
- package/lib/adapters/alipay-bill/alipay-bill-adapter.js +311 -0
- package/lib/adapters/alipay-bill/counterparty.js +129 -0
- package/lib/adapters/alipay-bill/csv-parser.js +217 -0
- package/lib/adapters/alipay-bill/index.js +41 -0
- package/lib/adapters/alipay-bill/zip-decryptor.js +111 -0
- package/lib/adapters/email-imap/classifier.js +495 -0
- package/lib/adapters/email-imap/email-adapter.js +419 -8
- package/lib/adapters/email-imap/index.js +42 -0
- package/lib/adapters/email-imap/pdf-extractor.js +192 -0
- package/lib/adapters/email-imap/templates/bill.js +232 -0
- package/lib/adapters/email-imap/templates/government.js +120 -0
- package/lib/adapters/email-imap/templates/index.js +78 -0
- package/lib/adapters/email-imap/templates/order.js +186 -0
- package/lib/adapters/email-imap/templates/other.js +114 -0
- package/lib/adapters/email-imap/templates/register.js +113 -0
- package/lib/adapters/email-imap/templates/travel.js +157 -0
- package/lib/adapters/email-imap/templates/utils.js +275 -0
- package/lib/adapters/email-imap/transactions.js +234 -0
- package/lib/adapters/messaging-qq/index.js +158 -0
- package/lib/adapters/messaging-telegram/index.js +142 -0
- package/lib/adapters/messaging-whatsapp/index.js +189 -0
- package/lib/adapters/shopping-base/index.js +208 -0
- package/lib/adapters/shopping-jd/index.js +150 -0
- package/lib/adapters/shopping-meituan/index.js +154 -0
- package/lib/adapters/shopping-taobao/index.js +176 -0
- package/lib/adapters/social-bilibili/index.js +171 -0
- package/lib/adapters/social-douyin/index.js +116 -0
- package/lib/adapters/social-kuaishou/index.js +237 -0
- package/lib/adapters/social-toutiao/index.js +236 -0
- package/lib/adapters/social-weibo/index.js +164 -0
- package/lib/adapters/social-xiaohongshu/index.js +96 -0
- package/lib/adapters/system-data/disclosure.js +166 -0
- package/lib/adapters/system-data/index.js +34 -0
- package/lib/adapters/system-data/system-data-adapter.js +344 -0
- package/lib/adapters/system-data-android/adapter.js +348 -0
- package/lib/adapters/system-data-android/index.js +76 -0
- package/lib/adapters/travel-12306/index.js +151 -0
- package/lib/adapters/travel-amap/index.js +164 -0
- package/lib/adapters/travel-baidu-map/index.js +162 -0
- package/lib/adapters/travel-base/index.js +240 -0
- package/lib/adapters/travel-ctrip/index.js +151 -0
- package/lib/adapters/wechat/bootstrap.js +146 -0
- package/lib/adapters/wechat/content-parser.js +326 -0
- package/lib/adapters/wechat/db-reader.js +209 -0
- package/lib/adapters/wechat/env-probe.js +218 -0
- package/lib/adapters/wechat/frida-agent/loader.js +67 -0
- package/lib/adapters/wechat/frida-agent/wechat-key-hook.js +126 -0
- package/lib/adapters/wechat/index.js +37 -0
- package/lib/adapters/wechat/key-extractor.js +158 -0
- package/lib/adapters/wechat/key-providers/frida-key-provider.js +244 -0
- package/lib/adapters/wechat/key-providers/index.js +22 -0
- package/lib/adapters/wechat/key-providers/key-provider-base.js +44 -0
- package/lib/adapters/wechat/key-providers/md5-key-provider.js +81 -0
- package/lib/adapters/wechat/normalize.js +220 -0
- package/lib/adapters/wechat/wechat-adapter.js +205 -0
- package/lib/analysis-skills/base.js +113 -0
- package/lib/analysis-skills/footprint.js +167 -0
- package/lib/analysis-skills/index.js +58 -0
- package/lib/analysis-skills/interests.js +161 -0
- package/lib/analysis-skills/relations.js +226 -0
- package/lib/analysis-skills/spending.js +219 -0
- package/lib/analysis-skills/timeline.js +167 -0
- package/lib/analysis.js +191 -2
- package/lib/entity-resolver/embedding-stage.js +198 -0
- package/lib/entity-resolver/entity-resolver.js +384 -0
- package/lib/entity-resolver/index.js +42 -0
- package/lib/entity-resolver/llm-stage.js +191 -0
- package/lib/entity-resolver/rule-stage.js +208 -0
- package/lib/entity-resolver/worker.js +149 -0
- package/lib/index.js +131 -0
- package/lib/migrations.js +73 -0
- package/lib/mobile-extractor/android.js +193 -0
- package/lib/mobile-extractor/index.js +9 -0
- package/lib/mobile-extractor/ios.js +223 -0
- package/lib/prompt-builder.js +11 -1
- package/lib/query-parser.js +7 -1
- package/lib/registry.js +42 -0
- package/lib/sidecar/index.js +15 -0
- package/lib/sidecar/supervisor.js +359 -0
- package/lib/vault.js +343 -0
- package/package.json +36 -3
- package/scripts/_make-fixture-all.js +126 -0
- package/scripts/_make-fixture-contacts.js +84 -0
- package/scripts/evaluate-entity-resolver.js +213 -0
- package/scripts/smoke-phase-5-5.js +196 -0
- package/scripts/smoke-phase-5-7.js +181 -0
- package/scripts/smoke-system-data-contacts.js +309 -0
- package/scripts/smoke-system-data.js +312 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 12.6.7 — bootstrapWechatAdapter unit tests.
|
|
3
|
+
*
|
|
4
|
+
* Validates the decision matrix that ties env-probe → KeyProvider →
|
|
5
|
+
* WechatAdapter. All exec calls are stubbed via `_probe` injection so
|
|
6
|
+
* tests stay fully hermetic (no adb, no Frida binding, no real device).
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect } from "vitest";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import os from "node:os";
|
|
14
|
+
import wechatModule from "../../lib/adapters/wechat/bootstrap.js";
|
|
15
|
+
const { bootstrapWechatAdapter } = wechatModule;
|
|
16
|
+
|
|
17
|
+
function mkProbe(overrides = {}) {
|
|
18
|
+
const base = {
|
|
19
|
+
ok: true,
|
|
20
|
+
suggestedKeyProvider: "md5",
|
|
21
|
+
reasons: ["WeChat 7.0.22 (< 8.0) — legacy MD5(IMEI+UIN) path supported"],
|
|
22
|
+
device: { reachable: true, serial: "SERIAL123", abi: "arm64-v8a" },
|
|
23
|
+
root: { detected: false, magiskInstalled: false },
|
|
24
|
+
frida: { serverRunning: false, port: null },
|
|
25
|
+
wechat: { installed: true, versionName: "7.0.22", majorVersion: 7 },
|
|
26
|
+
warnings: [],
|
|
27
|
+
};
|
|
28
|
+
return { ...base, ...overrides };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function mkWechatDataPath() {
|
|
32
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pdh-wechat-bootstrap-"));
|
|
33
|
+
return dir;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("bootstrapWechatAdapter — input validation", () => {
|
|
37
|
+
it("throws when account.uin missing (including bare opts)", async () => {
|
|
38
|
+
await expect(bootstrapWechatAdapter()).rejects.toThrow(/account\.uin/);
|
|
39
|
+
await expect(bootstrapWechatAdapter({})).rejects.toThrow(/account\.uin/);
|
|
40
|
+
await expect(
|
|
41
|
+
bootstrapWechatAdapter({ account: {} }),
|
|
42
|
+
).rejects.toThrow(/account\.uin/);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("bootstrapWechatAdapter — md5 path", () => {
|
|
47
|
+
it("returns ok with MD5KeyProvider when probe suggests md5 + wechatDataPath provided", async () => {
|
|
48
|
+
const wechatDataPath = mkWechatDataPath();
|
|
49
|
+
const r = await bootstrapWechatAdapter({
|
|
50
|
+
account: { uin: "1234567890" },
|
|
51
|
+
wechatDataPath,
|
|
52
|
+
_probe: mkProbe(),
|
|
53
|
+
});
|
|
54
|
+
expect(r.ok).toBe(true);
|
|
55
|
+
expect(r.adapter).toBeDefined();
|
|
56
|
+
expect(r.adapter.account.uin).toBe("1234567890");
|
|
57
|
+
expect(r.keyProvider).toBeDefined();
|
|
58
|
+
expect(r.keyProvider.name).toBe("md5");
|
|
59
|
+
expect(r.probe.suggestedKeyProvider).toBe("md5");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns MD5_NEEDS_WECHAT_DATA_PATH when md5 chosen but wechatDataPath missing", async () => {
|
|
63
|
+
const r = await bootstrapWechatAdapter({
|
|
64
|
+
account: { uin: "1234567890" },
|
|
65
|
+
_probe: mkProbe(),
|
|
66
|
+
});
|
|
67
|
+
expect(r.ok).toBe(false);
|
|
68
|
+
expect(r.reason).toBe("MD5_NEEDS_WECHAT_DATA_PATH");
|
|
69
|
+
expect(r.probe).toBeDefined();
|
|
70
|
+
expect(r.message).toMatch(/wechatDataPath/);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("propagates dbPath to the adapter constructor", async () => {
|
|
74
|
+
const wechatDataPath = mkWechatDataPath();
|
|
75
|
+
const dbPath = path.join(wechatDataPath, "MicroMsg.db");
|
|
76
|
+
fs.writeFileSync(dbPath, "stub", "utf-8");
|
|
77
|
+
const r = await bootstrapWechatAdapter({
|
|
78
|
+
account: { uin: "1234567890" },
|
|
79
|
+
dbPath,
|
|
80
|
+
wechatDataPath,
|
|
81
|
+
_probe: mkProbe(),
|
|
82
|
+
});
|
|
83
|
+
expect(r.ok).toBe(true);
|
|
84
|
+
expect(r.adapter._dbPath).toBe(dbPath);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("bootstrapWechatAdapter — frida path", () => {
|
|
89
|
+
it("returns ok with FridaKeyProvider when probe suggests frida", async () => {
|
|
90
|
+
const r = await bootstrapWechatAdapter({
|
|
91
|
+
account: { uin: "wxid_abcdef" },
|
|
92
|
+
_probe: mkProbe({
|
|
93
|
+
suggestedKeyProvider: "frida",
|
|
94
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
95
|
+
root: { detected: true, magiskInstalled: true },
|
|
96
|
+
frida: { serverRunning: true, port: 27042 },
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
expect(r.ok).toBe(true);
|
|
100
|
+
expect(r.keyProvider).toBeDefined();
|
|
101
|
+
expect(r.keyProvider.name).toBe("frida");
|
|
102
|
+
expect(r.adapter).toBeDefined();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("forwards fridaOpts.deviceId / packageName / timeoutMs", async () => {
|
|
106
|
+
const r = await bootstrapWechatAdapter({
|
|
107
|
+
account: { uin: "wxid_abcdef" },
|
|
108
|
+
fridaOpts: {
|
|
109
|
+
deviceId: "EMULATOR_ID",
|
|
110
|
+
packageName: "com.tencent.mm.beta",
|
|
111
|
+
timeoutMs: 12_345,
|
|
112
|
+
},
|
|
113
|
+
_probe: mkProbe({
|
|
114
|
+
suggestedKeyProvider: "frida",
|
|
115
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
116
|
+
root: { detected: true, magiskInstalled: true },
|
|
117
|
+
frida: { serverRunning: true, port: 27042 },
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
expect(r.ok).toBe(true);
|
|
121
|
+
expect(r.keyProvider._deviceId).toBe("EMULATOR_ID");
|
|
122
|
+
expect(r.keyProvider._packageName).toBe("com.tencent.mm.beta");
|
|
123
|
+
expect(r.keyProvider._timeoutMs).toBe(12_345);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("falls back to probe.device.serial when fridaOpts.deviceId not provided", async () => {
|
|
127
|
+
const r = await bootstrapWechatAdapter({
|
|
128
|
+
account: { uin: "wxid_abcdef" },
|
|
129
|
+
_probe: mkProbe({
|
|
130
|
+
suggestedKeyProvider: "frida",
|
|
131
|
+
device: { reachable: true, serial: "FROM_PROBE", abi: "arm64-v8a" },
|
|
132
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
133
|
+
root: { detected: true, magiskInstalled: true },
|
|
134
|
+
frida: { serverRunning: true, port: 27042 },
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
expect(r.ok).toBe(true);
|
|
138
|
+
expect(r.keyProvider._deviceId).toBe("FROM_PROBE");
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("bootstrapWechatAdapter — unsupported / unknown", () => {
|
|
143
|
+
it("returns ENV_UNSUPPORTED with probe reasons when nothing viable", async () => {
|
|
144
|
+
const r = await bootstrapWechatAdapter({
|
|
145
|
+
account: { uin: "1234567890" },
|
|
146
|
+
_probe: mkProbe({
|
|
147
|
+
ok: false,
|
|
148
|
+
suggestedKeyProvider: "unsupported",
|
|
149
|
+
reasons: ["WeChat 8.0.50 requires root for SQLCipher key extraction"],
|
|
150
|
+
}),
|
|
151
|
+
});
|
|
152
|
+
expect(r.ok).toBe(false);
|
|
153
|
+
expect(r.reason).toBe("ENV_UNSUPPORTED");
|
|
154
|
+
expect(r.message).toMatch(/root/);
|
|
155
|
+
expect(r.probe).toBeDefined();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("returns UNKNOWN_KEY_PROVIDER when override is not md5/frida", async () => {
|
|
159
|
+
const r = await bootstrapWechatAdapter({
|
|
160
|
+
account: { uin: "1234567890" },
|
|
161
|
+
keyProviderOverride: "magic-pony",
|
|
162
|
+
_probe: mkProbe(),
|
|
163
|
+
});
|
|
164
|
+
expect(r.ok).toBe(false);
|
|
165
|
+
expect(r.reason).toBe("UNKNOWN_KEY_PROVIDER");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("bootstrapWechatAdapter — override", () => {
|
|
170
|
+
it("keyProviderOverride='frida' picks frida even when probe suggests md5", async () => {
|
|
171
|
+
const r = await bootstrapWechatAdapter({
|
|
172
|
+
account: { uin: "wxid_force" },
|
|
173
|
+
keyProviderOverride: "frida",
|
|
174
|
+
_probe: mkProbe(), // suggests "md5"
|
|
175
|
+
});
|
|
176
|
+
expect(r.ok).toBe(true);
|
|
177
|
+
expect(r.keyProvider.name).toBe("frida");
|
|
178
|
+
expect(r.probe.suggestedKeyProvider).toBe("md5"); // probe transparent
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("keyProviderOverride='md5' picks md5 even when probe suggests frida", async () => {
|
|
182
|
+
const wechatDataPath = mkWechatDataPath();
|
|
183
|
+
const r = await bootstrapWechatAdapter({
|
|
184
|
+
account: { uin: "1234567890" },
|
|
185
|
+
wechatDataPath,
|
|
186
|
+
keyProviderOverride: "md5",
|
|
187
|
+
_probe: mkProbe({
|
|
188
|
+
suggestedKeyProvider: "frida",
|
|
189
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
190
|
+
root: { detected: true, magiskInstalled: true },
|
|
191
|
+
frida: { serverRunning: true, port: 27042 },
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
expect(r.ok).toBe(true);
|
|
195
|
+
expect(r.keyProvider.name).toBe("md5");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("bootstrapWechatAdapter — adapter ctor errors", () => {
|
|
200
|
+
it("returns ADAPTER_CTOR_FAILED when WechatAdapter throws", async () => {
|
|
201
|
+
const wechatDataPath = mkWechatDataPath();
|
|
202
|
+
function Boom() {
|
|
203
|
+
throw new Error("ctor boom");
|
|
204
|
+
}
|
|
205
|
+
const r = await bootstrapWechatAdapter({
|
|
206
|
+
account: { uin: "1234567890" },
|
|
207
|
+
wechatDataPath,
|
|
208
|
+
_probe: mkProbe(),
|
|
209
|
+
_WechatAdapter: Boom,
|
|
210
|
+
});
|
|
211
|
+
expect(r.ok).toBe(false);
|
|
212
|
+
expect(r.reason).toBe("ADAPTER_CTOR_FAILED");
|
|
213
|
+
expect(r.message).toBe("ctor boom");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("bootstrapWechatAdapter — test seams", () => {
|
|
218
|
+
it("uses injected _md5Provider verbatim", async () => {
|
|
219
|
+
const stubProvider = { name: "md5", getKey: async () => "deadbeef" };
|
|
220
|
+
const r = await bootstrapWechatAdapter({
|
|
221
|
+
account: { uin: "1234567890" },
|
|
222
|
+
_probe: mkProbe(),
|
|
223
|
+
_md5Provider: stubProvider,
|
|
224
|
+
});
|
|
225
|
+
expect(r.ok).toBe(true);
|
|
226
|
+
expect(r.keyProvider).toBe(stubProvider);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("uses injected _fridaProvider verbatim", async () => {
|
|
230
|
+
const stubProvider = { name: "frida", getKey: async () => "feedface".repeat(8) };
|
|
231
|
+
const r = await bootstrapWechatAdapter({
|
|
232
|
+
account: { uin: "wxid_abc" },
|
|
233
|
+
keyProviderOverride: "frida",
|
|
234
|
+
_probe: mkProbe(),
|
|
235
|
+
_fridaProvider: stubProvider,
|
|
236
|
+
});
|
|
237
|
+
expect(r.ok).toBe(true);
|
|
238
|
+
expect(r.keyProvider).toBe(stubProvider);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
const { probe, decide } = require("../../lib/adapters/wechat/env-probe");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build a scripted exec that returns a canned response per matching
|
|
9
|
+
* substring. Falls back to `{ code: 1, stdout: "", stderr: "" }`.
|
|
10
|
+
*/
|
|
11
|
+
function makeExec(table) {
|
|
12
|
+
return async (cmd) => {
|
|
13
|
+
for (const [needle, response] of table) {
|
|
14
|
+
if (cmd.includes(needle)) return { code: 0, stdout: response, stderr: "" };
|
|
15
|
+
}
|
|
16
|
+
return { code: 1, stdout: "", stderr: "" };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ADB_DEVICES_OK = "List of devices attached\nABC123XYZ\tdevice\n\n";
|
|
21
|
+
const WECHAT_7 = " versionName=7.0.22\n";
|
|
22
|
+
const WECHAT_8 = " versionName=8.0.50\n";
|
|
23
|
+
const NETSTAT_FRIDA = "tcp 0 0 0.0.0.0:27042 0.0.0.0:* LISTEN\n";
|
|
24
|
+
|
|
25
|
+
describe("decide() — pure decision logic", () => {
|
|
26
|
+
it("device unreachable → unsupported", () => {
|
|
27
|
+
const r = decide({
|
|
28
|
+
device: { reachable: false }, root: {}, frida: {}, wechat: {},
|
|
29
|
+
});
|
|
30
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("WeChat 7.x → md5 regardless of root/frida", () => {
|
|
34
|
+
const r = decide({
|
|
35
|
+
device: { reachable: true },
|
|
36
|
+
root: { detected: false },
|
|
37
|
+
frida: { serverRunning: false },
|
|
38
|
+
wechat: { installed: true, versionName: "7.0.22", majorVersion: 7 },
|
|
39
|
+
});
|
|
40
|
+
expect(r.suggestedKeyProvider).toBe("md5");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("WeChat 8.x + root + frida → frida", () => {
|
|
44
|
+
const r = decide({
|
|
45
|
+
device: { reachable: true },
|
|
46
|
+
root: { detected: true, magiskInstalled: true },
|
|
47
|
+
frida: { serverRunning: true, port: 27042 },
|
|
48
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
49
|
+
});
|
|
50
|
+
expect(r.suggestedKeyProvider).toBe("frida");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("WeChat 8.x + no root → unsupported", () => {
|
|
54
|
+
const r = decide({
|
|
55
|
+
device: { reachable: true },
|
|
56
|
+
root: { detected: false },
|
|
57
|
+
frida: { serverRunning: true },
|
|
58
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
59
|
+
});
|
|
60
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
61
|
+
expect(r.reasons.join(" ")).toMatch(/root/);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("WeChat 8.x + root + no frida-server → unsupported", () => {
|
|
65
|
+
const r = decide({
|
|
66
|
+
device: { reachable: true },
|
|
67
|
+
root: { detected: true },
|
|
68
|
+
frida: { serverRunning: false },
|
|
69
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
70
|
+
});
|
|
71
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
72
|
+
expect(r.reasons.join(" ")).toMatch(/frida-server/i);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("WeChat not installed → unsupported", () => {
|
|
76
|
+
const r = decide({
|
|
77
|
+
device: { reachable: true },
|
|
78
|
+
root: { detected: true },
|
|
79
|
+
frida: { serverRunning: true },
|
|
80
|
+
wechat: { installed: false },
|
|
81
|
+
});
|
|
82
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
83
|
+
expect(r.reasons.join(" ")).toMatch(/not installed/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("WeChat 8.x + root + frida + no Magisk → frida (warn reason)", () => {
|
|
87
|
+
const r = decide({
|
|
88
|
+
device: { reachable: true },
|
|
89
|
+
root: { detected: true, magiskInstalled: false },
|
|
90
|
+
frida: { serverRunning: true, port: 27042 },
|
|
91
|
+
wechat: { installed: true, versionName: "8.0.50", majorVersion: 8 },
|
|
92
|
+
});
|
|
93
|
+
expect(r.suggestedKeyProvider).toBe("frida");
|
|
94
|
+
expect(r.reasons.join(" ")).toMatch(/Magisk not detected/);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("probe() — end-to-end with mock exec", () => {
|
|
99
|
+
it("returns unsupported when no device", async () => {
|
|
100
|
+
const exec = makeExec([["adb devices", "List of devices attached\n\n"]]);
|
|
101
|
+
const r = await probe({ exec });
|
|
102
|
+
expect(r.ok).toBe(false);
|
|
103
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
104
|
+
expect(r.device.reachable).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("WeChat 7.x device → md5 path", async () => {
|
|
108
|
+
const exec = makeExec([
|
|
109
|
+
["adb devices", ADB_DEVICES_OK],
|
|
110
|
+
["getprop ro.product.cpu.abi", "arm64-v8a\n"],
|
|
111
|
+
["com.tencent.mm", WECHAT_7],
|
|
112
|
+
]);
|
|
113
|
+
const r = await probe({ exec });
|
|
114
|
+
expect(r.ok).toBe(true);
|
|
115
|
+
expect(r.suggestedKeyProvider).toBe("md5");
|
|
116
|
+
expect(r.device.serial).toBe("ABC123XYZ");
|
|
117
|
+
expect(r.device.abi).toBe("arm64-v8a");
|
|
118
|
+
expect(r.wechat.majorVersion).toBe(7);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("WeChat 8.x + rooted + frida → frida path", async () => {
|
|
122
|
+
const exec = makeExec([
|
|
123
|
+
["adb devices", ADB_DEVICES_OK],
|
|
124
|
+
["getprop ro.product.cpu.abi", "arm64-v8a\n"],
|
|
125
|
+
['su -c id', "uid=0(root) gid=0(root) groups=0(root)\n"],
|
|
126
|
+
["command -v magisk", "/system/bin/magisk\n"],
|
|
127
|
+
["pgrep -f frida-server", "12345\n"],
|
|
128
|
+
["netstat -tln", NETSTAT_FRIDA],
|
|
129
|
+
["com.tencent.mm", WECHAT_8],
|
|
130
|
+
]);
|
|
131
|
+
const r = await probe({ exec });
|
|
132
|
+
expect(r.ok).toBe(true);
|
|
133
|
+
expect(r.suggestedKeyProvider).toBe("frida");
|
|
134
|
+
expect(r.root.detected).toBe(true);
|
|
135
|
+
expect(r.root.magiskInstalled).toBe(true);
|
|
136
|
+
expect(r.frida.serverRunning).toBe(true);
|
|
137
|
+
expect(r.frida.port).toBe(27042);
|
|
138
|
+
expect(r.wechat.majorVersion).toBe(8);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("WeChat 8.x but no root → unsupported with reason", async () => {
|
|
142
|
+
const exec = makeExec([
|
|
143
|
+
["adb devices", ADB_DEVICES_OK],
|
|
144
|
+
["getprop ro.product.cpu.abi", "arm64-v8a\n"],
|
|
145
|
+
["com.tencent.mm", WECHAT_8],
|
|
146
|
+
]);
|
|
147
|
+
const r = await probe({ exec });
|
|
148
|
+
expect(r.ok).toBe(false);
|
|
149
|
+
expect(r.suggestedKeyProvider).toBe("unsupported");
|
|
150
|
+
expect(r.reasons.join(" ")).toMatch(/root not detected/);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("non-ARM ABI gets warning", async () => {
|
|
154
|
+
const exec = makeExec([
|
|
155
|
+
["adb devices", ADB_DEVICES_OK],
|
|
156
|
+
["getprop ro.product.cpu.abi", "x86_64\n"],
|
|
157
|
+
["com.tencent.mm", WECHAT_7],
|
|
158
|
+
]);
|
|
159
|
+
const r = await probe({ exec });
|
|
160
|
+
expect(r.warnings.join(" ")).toMatch(/x86_64/);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const { loadAgentScript, runAgentUnderMock } = require("../../lib/adapters/wechat/frida-agent/loader");
|
|
6
|
+
|
|
7
|
+
function hexToBuffer(hex) {
|
|
8
|
+
const out = new Uint8Array(hex.length / 2);
|
|
9
|
+
for (let i = 0; i < out.length; i++) {
|
|
10
|
+
out[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
11
|
+
}
|
|
12
|
+
return out.buffer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Fake NativePointer — supports toInt32() (length) and readByteArray(len) (key bytes). */
|
|
16
|
+
function fakePtr(value) {
|
|
17
|
+
return {
|
|
18
|
+
_v: value,
|
|
19
|
+
toInt32() { return typeof value === "number" ? value : 0; },
|
|
20
|
+
readByteArray(len) {
|
|
21
|
+
// value is a hex string for key bytes; len ignored beyond bounds
|
|
22
|
+
if (typeof value !== "string") return new Uint8Array(0).buffer;
|
|
23
|
+
const buf = hexToBuffer(value);
|
|
24
|
+
// truncate to requested len if needed
|
|
25
|
+
return new Uint8Array(buf, 0, Math.min(len, buf.byteLength)).buffer;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("frida-agent loader — script loading", () => {
|
|
31
|
+
it("loadAgentScript returns non-empty JS text", () => {
|
|
32
|
+
const src = loadAgentScript();
|
|
33
|
+
expect(src.length).toBeGreaterThan(100);
|
|
34
|
+
expect(src).toContain("libwcdb.so");
|
|
35
|
+
expect(src).toContain("sqlite3_key");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("frida-agent — sqlite3_key hook on module already loaded", () => {
|
|
40
|
+
it("emits hooked + key on sqlite3_key onEnter", () => {
|
|
41
|
+
const send = vi.fn();
|
|
42
|
+
const attached = {};
|
|
43
|
+
const Interceptor = {
|
|
44
|
+
attach(addr, handlers) {
|
|
45
|
+
attached[addr.symbol] = handlers;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const Module = {
|
|
49
|
+
findExportByName(mod, sym) {
|
|
50
|
+
if (mod !== "libwcdb.so") return null;
|
|
51
|
+
if (sym === "sqlite3_key") return { symbol: sym };
|
|
52
|
+
return null; // only sqlite3_key resolves; others null
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const Process = {
|
|
56
|
+
findModuleByName(mod) { return mod === "libwcdb.so" ? { name: mod } : null; },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
runAgentUnderMock({ Module, Process, Interceptor, send });
|
|
60
|
+
|
|
61
|
+
// After load, "hooked" event already sent
|
|
62
|
+
const hooked = send.mock.calls.find((c) => c[0].kind === "hooked");
|
|
63
|
+
expect(hooked).toBeDefined();
|
|
64
|
+
expect(hooked[0].symbol).toBe("sqlite3_key");
|
|
65
|
+
expect(hooked[0].module).toBe("libwcdb.so");
|
|
66
|
+
|
|
67
|
+
// Fire the hook: args = [sqlite3*, keyBytes, len]
|
|
68
|
+
const keyHex = "11223344556677889900aabbccddeeff" +
|
|
69
|
+
"00112233445566778899aabbccddeeff"; // 64 hex = 32 bytes (SQLCipher 256-bit)
|
|
70
|
+
const args = [fakePtr(0), fakePtr(keyHex), fakePtr(32)];
|
|
71
|
+
attached.sqlite3_key.onEnter(args);
|
|
72
|
+
|
|
73
|
+
const key = send.mock.calls.find((c) => c[0].kind === "key");
|
|
74
|
+
expect(key).toBeDefined();
|
|
75
|
+
expect(key[0].hex).toBe(keyHex);
|
|
76
|
+
expect(key[0].source).toBe("sqlite3_key");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("only emits the first key event (anti-detection: hook fires once)", () => {
|
|
80
|
+
const send = vi.fn();
|
|
81
|
+
const attached = {};
|
|
82
|
+
const Interceptor = {
|
|
83
|
+
attach(addr, handlers) { attached[addr.symbol] = handlers; },
|
|
84
|
+
};
|
|
85
|
+
const Module = {
|
|
86
|
+
findExportByName(mod, sym) {
|
|
87
|
+
if (sym === "sqlite3_key") return { symbol: sym };
|
|
88
|
+
return null;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
|
|
92
|
+
|
|
93
|
+
runAgentUnderMock({ Module, Process, Interceptor, send });
|
|
94
|
+
|
|
95
|
+
const args = [fakePtr(0), fakePtr("aabb" + "00".repeat(30)), fakePtr(32)];
|
|
96
|
+
attached.sqlite3_key.onEnter(args);
|
|
97
|
+
attached.sqlite3_key.onEnter(args);
|
|
98
|
+
attached.sqlite3_key.onEnter(args);
|
|
99
|
+
|
|
100
|
+
const keyEvents = send.mock.calls.filter((c) => c[0].kind === "key");
|
|
101
|
+
expect(keyEvents).toHaveLength(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("rejects implausible key length with error event", () => {
|
|
105
|
+
const send = vi.fn();
|
|
106
|
+
const attached = {};
|
|
107
|
+
const Interceptor = {
|
|
108
|
+
attach(addr, handlers) { attached[addr.symbol] = handlers; },
|
|
109
|
+
};
|
|
110
|
+
const Module = {
|
|
111
|
+
findExportByName(mod, sym) { return sym === "sqlite3_key" ? { symbol: sym } : null; },
|
|
112
|
+
};
|
|
113
|
+
const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
|
|
114
|
+
|
|
115
|
+
runAgentUnderMock({ Module, Process, Interceptor, send });
|
|
116
|
+
|
|
117
|
+
attached.sqlite3_key.onEnter([fakePtr(0), fakePtr("aa"), fakePtr(9999)]);
|
|
118
|
+
|
|
119
|
+
const errs = send.mock.calls.filter((c) => c[0].kind === "error");
|
|
120
|
+
expect(errs.length).toBeGreaterThan(0);
|
|
121
|
+
expect(errs[0][0].message).toMatch(/implausible key length 9999/);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("frida-agent — fallback symbol resolution", () => {
|
|
126
|
+
it("attaches to wcdb_setkey when sqlite3_key absent", () => {
|
|
127
|
+
const send = vi.fn();
|
|
128
|
+
const attached = {};
|
|
129
|
+
const Interceptor = {
|
|
130
|
+
attach(addr, handlers) { attached[addr.symbol] = handlers; },
|
|
131
|
+
};
|
|
132
|
+
const Module = {
|
|
133
|
+
findExportByName(mod, sym) {
|
|
134
|
+
// WeChat 8.x renamed primary symbol
|
|
135
|
+
if (sym === "wcdb_setkey") return { symbol: sym };
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
|
|
140
|
+
|
|
141
|
+
runAgentUnderMock({ Module, Process, Interceptor, send });
|
|
142
|
+
|
|
143
|
+
const hooked = send.mock.calls.find((c) => c[0].kind === "hooked");
|
|
144
|
+
expect(hooked[0].symbol).toBe("wcdb_setkey");
|
|
145
|
+
expect(attached.wcdb_setkey).toBeDefined();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("emits source = matched symbol when fallback fires", () => {
|
|
149
|
+
const send = vi.fn();
|
|
150
|
+
const attached = {};
|
|
151
|
+
const Interceptor = {
|
|
152
|
+
attach(addr, handlers) { attached[addr.symbol] = handlers; },
|
|
153
|
+
};
|
|
154
|
+
const Module = {
|
|
155
|
+
findExportByName(mod, sym) {
|
|
156
|
+
return sym === "WCDBKeyDerive" ? { symbol: sym } : null;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
|
|
160
|
+
|
|
161
|
+
runAgentUnderMock({ Module, Process, Interceptor, send });
|
|
162
|
+
|
|
163
|
+
attached.WCDBKeyDerive.onEnter([
|
|
164
|
+
fakePtr(0),
|
|
165
|
+
fakePtr("deadbeef" + "00".repeat(28)),
|
|
166
|
+
fakePtr(32),
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
const key = send.mock.calls.find((c) => c[0].kind === "key");
|
|
170
|
+
expect(key[0].source).toBe("WCDBKeyDerive");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("frida-agent — module not yet loaded path", () => {
|
|
175
|
+
it("emits module-waiting and schedules retry", () => {
|
|
176
|
+
const send = vi.fn();
|
|
177
|
+
const Interceptor = { attach: vi.fn() };
|
|
178
|
+
const Module = { findExportByName: vi.fn().mockReturnValue(null) };
|
|
179
|
+
const Process = { findModuleByName: vi.fn().mockReturnValue(null) };
|
|
180
|
+
const setTimeoutMock = vi.fn();
|
|
181
|
+
|
|
182
|
+
runAgentUnderMock({ Module, Process, Interceptor, send, setTimeout: setTimeoutMock });
|
|
183
|
+
|
|
184
|
+
const waiting = send.mock.calls.find((c) => c[0].kind === "module-waiting");
|
|
185
|
+
expect(waiting).toBeDefined();
|
|
186
|
+
expect(waiting[0].module).toBe("libwcdb.so");
|
|
187
|
+
expect(setTimeoutMock).toHaveBeenCalled();
|
|
188
|
+
// First retry delay 500ms
|
|
189
|
+
expect(setTimeoutMock.mock.calls[0][1]).toBe(500);
|
|
190
|
+
});
|
|
191
|
+
});
|