@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,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
WechatAdapter,
|
|
7
|
+
WeChatFridaKeyProvider,
|
|
8
|
+
} = require("../../lib/adapters/wechat");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Phase 12.6.5 — integration: WechatAdapter.authenticate flow against
|
|
12
|
+
* a mock FridaKeyProvider. We don't open a real SQLCipher DB here —
|
|
13
|
+
* that requires a fixture + better-sqlite3-multiple-ciphers compiled
|
|
14
|
+
* against the host's Node ABI, and is covered separately in the v0.5
|
|
15
|
+
* suite. Goal of this slice: prove the adapter's KeyProvider DI seam
|
|
16
|
+
* works identically for the Frida path.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function mockFrida({ keyHex, throwOnAttach, delayMs = 0 } = {}) {
|
|
20
|
+
const script = {
|
|
21
|
+
message: { connect: (h) => { script._handler = h; } },
|
|
22
|
+
load: async () => {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
if (!script._handler) return;
|
|
25
|
+
script._handler({ type: "send", payload: {
|
|
26
|
+
kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so",
|
|
27
|
+
} });
|
|
28
|
+
script._handler({ type: "send", payload: {
|
|
29
|
+
kind: "key", hex: keyHex, source: "sqlite3_key",
|
|
30
|
+
} });
|
|
31
|
+
}, delayMs);
|
|
32
|
+
},
|
|
33
|
+
unload: async () => {},
|
|
34
|
+
};
|
|
35
|
+
const session = {
|
|
36
|
+
createScript: async () => script,
|
|
37
|
+
detach: async () => {},
|
|
38
|
+
};
|
|
39
|
+
const device = {
|
|
40
|
+
attach: async () => {
|
|
41
|
+
if (throwOnAttach) throw new Error(throwOnAttach);
|
|
42
|
+
return session;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
getDevice: async () => device,
|
|
47
|
+
getUsbDevice: async () => device,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("WechatAdapter + FridaKeyProvider — DI integration", () => {
|
|
52
|
+
it("authenticate succeeds when frida provides a key", async () => {
|
|
53
|
+
// dbPath needs to point to a real file for the existsSync gate
|
|
54
|
+
const fs = require("node:fs");
|
|
55
|
+
const path = require("node:path");
|
|
56
|
+
const os = require("node:os");
|
|
57
|
+
const tmpDb = path.join(os.tmpdir(), `wechat-mock-${Date.now()}.db`);
|
|
58
|
+
fs.writeFileSync(tmpDb, "fake sqlite header");
|
|
59
|
+
|
|
60
|
+
const frida = mockFrida({ keyHex: "ab".repeat(32) /* 64 hex */ });
|
|
61
|
+
const keyProvider = new WeChatFridaKeyProvider({
|
|
62
|
+
frida,
|
|
63
|
+
deviceId: "TEST",
|
|
64
|
+
agentLoader: () => "/* test agent */",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const adapter = new WechatAdapter({
|
|
68
|
+
account: { uin: "1234567890" },
|
|
69
|
+
dbPath: tmpDb,
|
|
70
|
+
keyProvider,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const r = await adapter.authenticate();
|
|
74
|
+
expect(r.ok).toBe(true);
|
|
75
|
+
expect(r.account).toBe("1234567890");
|
|
76
|
+
|
|
77
|
+
try { fs.unlinkSync(tmpDb); } catch (_e) { /* test cleanup */ }
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("authenticate reports NO_KEY_PROVIDER when keyProvider absent", async () => {
|
|
81
|
+
const fs = require("node:fs");
|
|
82
|
+
const path = require("node:path");
|
|
83
|
+
const os = require("node:os");
|
|
84
|
+
const tmpDb = path.join(os.tmpdir(), `wechat-mock-${Date.now()}.db`);
|
|
85
|
+
fs.writeFileSync(tmpDb, "fake");
|
|
86
|
+
|
|
87
|
+
const adapter = new WechatAdapter({
|
|
88
|
+
account: { uin: "1234567890" },
|
|
89
|
+
dbPath: tmpDb,
|
|
90
|
+
// keyProvider omitted on purpose
|
|
91
|
+
});
|
|
92
|
+
const r = await adapter.authenticate();
|
|
93
|
+
expect(r.ok).toBe(false);
|
|
94
|
+
expect(r.reason).toBe("NO_KEY_PROVIDER");
|
|
95
|
+
|
|
96
|
+
try { fs.unlinkSync(tmpDb); } catch (_e) { /* test cleanup */ }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("authenticate reports KEY_PROVIDER_THREW when Frida times out", async () => {
|
|
100
|
+
const fs = require("node:fs");
|
|
101
|
+
const path = require("node:path");
|
|
102
|
+
const os = require("node:os");
|
|
103
|
+
const tmpDb = path.join(os.tmpdir(), `wechat-mock-${Date.now()}.db`);
|
|
104
|
+
fs.writeFileSync(tmpDb, "fake");
|
|
105
|
+
|
|
106
|
+
// Mock with no messages → will timeout
|
|
107
|
+
const session = {
|
|
108
|
+
createScript: async () => ({
|
|
109
|
+
message: { connect: () => {} },
|
|
110
|
+
load: async () => {},
|
|
111
|
+
unload: async () => {},
|
|
112
|
+
}),
|
|
113
|
+
detach: async () => {},
|
|
114
|
+
};
|
|
115
|
+
const frida = {
|
|
116
|
+
getDevice: async () => ({ attach: async () => session }),
|
|
117
|
+
getUsbDevice: async () => ({ attach: async () => session }),
|
|
118
|
+
};
|
|
119
|
+
const keyProvider = new WeChatFridaKeyProvider({
|
|
120
|
+
frida,
|
|
121
|
+
deviceId: "TEST",
|
|
122
|
+
agentLoader: () => "",
|
|
123
|
+
timeoutMs: 30,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const adapter = new WechatAdapter({
|
|
127
|
+
account: { uin: "1234567890" },
|
|
128
|
+
dbPath: tmpDb,
|
|
129
|
+
keyProvider,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const r = await adapter.authenticate();
|
|
133
|
+
expect(r.ok).toBe(false);
|
|
134
|
+
expect(r.reason).toBe("KEY_PROVIDER_THREW");
|
|
135
|
+
expect(r.error).toMatch(/30ms/);
|
|
136
|
+
|
|
137
|
+
try { fs.unlinkSync(tmpDb); } catch (_e) { /* test cleanup */ }
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("DB_NOT_PULLED takes precedence over keyProvider absence", async () => {
|
|
141
|
+
const adapter = new WechatAdapter({
|
|
142
|
+
account: { uin: "1234567890" },
|
|
143
|
+
dbPath: "/definitely/not/a/real/path/wechat.db",
|
|
144
|
+
});
|
|
145
|
+
const r = await adapter.authenticate();
|
|
146
|
+
expect(r.ok).toBe(false);
|
|
147
|
+
expect(r.reason).toBe("DB_NOT_PULLED");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const { FridaKeyProvider } = require("../../lib/adapters/wechat/key-providers/frida-key-provider");
|
|
6
|
+
|
|
7
|
+
/** Helper that builds a mock frida binding with a scripted message timeline. */
|
|
8
|
+
function makeMockFrida({ onAttachThrow, onCreateScriptThrow, onLoadThrow, messages = [], deviceId = "device" }) {
|
|
9
|
+
const ops = {
|
|
10
|
+
unloadCalled: 0,
|
|
11
|
+
detachCalled: 0,
|
|
12
|
+
loadCalled: 0,
|
|
13
|
+
messageHandler: null,
|
|
14
|
+
};
|
|
15
|
+
const script = {
|
|
16
|
+
message: {
|
|
17
|
+
connect: (handler) => { ops.messageHandler = handler; },
|
|
18
|
+
},
|
|
19
|
+
load: vi.fn(async () => {
|
|
20
|
+
ops.loadCalled++;
|
|
21
|
+
if (onLoadThrow) throw onLoadThrow;
|
|
22
|
+
// Replay the scripted messages on next tick so .connect handler is
|
|
23
|
+
// wired before the first send fires.
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
for (const m of messages) {
|
|
26
|
+
if (ops.messageHandler) ops.messageHandler({ type: "send", payload: m });
|
|
27
|
+
}
|
|
28
|
+
}, 0);
|
|
29
|
+
}),
|
|
30
|
+
unload: vi.fn(async () => { ops.unloadCalled++; }),
|
|
31
|
+
};
|
|
32
|
+
const session = {
|
|
33
|
+
createScript: vi.fn(async () => {
|
|
34
|
+
if (onCreateScriptThrow) throw onCreateScriptThrow;
|
|
35
|
+
return script;
|
|
36
|
+
}),
|
|
37
|
+
detach: vi.fn(async () => { ops.detachCalled++; }),
|
|
38
|
+
};
|
|
39
|
+
const device = {
|
|
40
|
+
attach: vi.fn(async (pkg) => {
|
|
41
|
+
if (onAttachThrow) throw onAttachThrow;
|
|
42
|
+
device._attachedTo = pkg;
|
|
43
|
+
return session;
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
const frida = {
|
|
47
|
+
getDevice: vi.fn(async (id) => {
|
|
48
|
+
device._id = id;
|
|
49
|
+
return device;
|
|
50
|
+
}),
|
|
51
|
+
getUsbDevice: vi.fn(async () => device),
|
|
52
|
+
};
|
|
53
|
+
return { frida, device, session, script, ops };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("FridaKeyProvider — construction", () => {
|
|
57
|
+
it("defaults packageName to com.tencent.mm", () => {
|
|
58
|
+
const p = new FridaKeyProvider({});
|
|
59
|
+
expect(p._packageName).toBe("com.tencent.mm");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("name is frida", () => {
|
|
63
|
+
const p = new FridaKeyProvider({});
|
|
64
|
+
expect(p.name).toBe("frida");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("getKey throws FRIDA_BINDING_MISSING when frida not available", async () => {
|
|
68
|
+
const p = new FridaKeyProvider({});
|
|
69
|
+
try {
|
|
70
|
+
await p.getKey();
|
|
71
|
+
throw new Error("should have thrown");
|
|
72
|
+
} catch (err) {
|
|
73
|
+
expect(err.code).toBe("FRIDA_BINDING_MISSING");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("FridaKeyProvider — happy path", () => {
|
|
79
|
+
it("captures key hex and detaches", async () => {
|
|
80
|
+
const keyHex = "00112233445566778899aabbccddeeff" +
|
|
81
|
+
"ffeeddccbbaa99887766554433221100";
|
|
82
|
+
const { frida, ops } = makeMockFrida({
|
|
83
|
+
messages: [
|
|
84
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
85
|
+
{ kind: "key", hex: keyHex.toUpperCase(), source: "sqlite3_key" },
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "/* mock agent */" });
|
|
89
|
+
const k = await p.getKey();
|
|
90
|
+
expect(k).toBe(keyHex); // lowercased
|
|
91
|
+
expect(ops.unloadCalled).toBe(1);
|
|
92
|
+
expect(ops.detachCalled).toBe(1);
|
|
93
|
+
const tel = p.getLastTelemetry();
|
|
94
|
+
expect(tel.keySource).toBe("sqlite3_key");
|
|
95
|
+
expect(tel.hooked).toHaveLength(1);
|
|
96
|
+
expect(tel.durationMs).toBeGreaterThanOrEqual(0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("uses USB device when no deviceId provided", async () => {
|
|
100
|
+
const { frida } = makeMockFrida({
|
|
101
|
+
messages: [{ kind: "key", hex: "aa" + "00".repeat(31), source: "sqlite3_key" }],
|
|
102
|
+
});
|
|
103
|
+
const p = new FridaKeyProvider({ frida, agentLoader: () => "/* mock */" });
|
|
104
|
+
await p.getKey();
|
|
105
|
+
expect(frida.getUsbDevice).toHaveBeenCalled();
|
|
106
|
+
expect(frida.getDevice).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("FridaKeyProvider — error paths", () => {
|
|
111
|
+
it("WECHAT_NOT_RUNNING when attach reports process not found", async () => {
|
|
112
|
+
const { frida } = makeMockFrida({
|
|
113
|
+
onAttachThrow: new Error("unable to find process with name 'com.tencent.mm'"),
|
|
114
|
+
});
|
|
115
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
116
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "WECHAT_NOT_RUNNING" });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("FRIDA_ATTACH_FAILED on generic attach error", async () => {
|
|
120
|
+
const { frida } = makeMockFrida({
|
|
121
|
+
onAttachThrow: new Error("permission denied"),
|
|
122
|
+
});
|
|
123
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
124
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "FRIDA_ATTACH_FAILED" });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("FRIDA_ATTACH_FAILED + session cleanup when createScript throws", async () => {
|
|
128
|
+
const { frida, ops } = makeMockFrida({
|
|
129
|
+
onCreateScriptThrow: new Error("syntax error in agent"),
|
|
130
|
+
});
|
|
131
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "BAD" });
|
|
132
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "FRIDA_ATTACH_FAILED" });
|
|
133
|
+
// Even though createScript threw, the session was already attached;
|
|
134
|
+
// implementation cleans it up in the catch path.
|
|
135
|
+
expect(ops.detachCalled).toBe(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("WCDB_KEY_TIMEOUT when no key event in time", async () => {
|
|
139
|
+
const { frida, ops } = makeMockFrida({
|
|
140
|
+
messages: [{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" }],
|
|
141
|
+
});
|
|
142
|
+
const p = new FridaKeyProvider({
|
|
143
|
+
frida,
|
|
144
|
+
deviceId: "Z1",
|
|
145
|
+
timeoutMs: 50,
|
|
146
|
+
agentLoader: () => "",
|
|
147
|
+
});
|
|
148
|
+
await expect(p.getKey()).rejects.toMatchObject({ code: "WCDB_KEY_TIMEOUT" });
|
|
149
|
+
expect(ops.unloadCalled).toBe(1);
|
|
150
|
+
expect(ops.detachCalled).toBe(1);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("non-fatal hook errors are recorded but don't reject", async () => {
|
|
154
|
+
const keyHex = "ee" + "00".repeat(31);
|
|
155
|
+
const { frida } = makeMockFrida({
|
|
156
|
+
messages: [
|
|
157
|
+
{ kind: "error", message: "Interceptor.attach failed for WCDBKeyDerive: not found" },
|
|
158
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
159
|
+
{ kind: "key", hex: keyHex, source: "sqlite3_key" },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
const p = new FridaKeyProvider({ frida, deviceId: "Z1", agentLoader: () => "" });
|
|
163
|
+
const k = await p.getKey();
|
|
164
|
+
expect(k).toBe(keyHex);
|
|
165
|
+
expect(p.getLastTelemetry().errors).toContain("Interceptor.attach failed for WCDBKeyDerive: not found");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("FridaKeyProvider — logger DI", () => {
|
|
170
|
+
it("logger receives frida-message events", async () => {
|
|
171
|
+
const events = [];
|
|
172
|
+
const { frida } = makeMockFrida({
|
|
173
|
+
messages: [
|
|
174
|
+
{ kind: "hooked", symbol: "sqlite3_key", module: "libwcdb.so" },
|
|
175
|
+
{ kind: "key", hex: "ff" + "00".repeat(31), source: "sqlite3_key" },
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
const p = new FridaKeyProvider({
|
|
179
|
+
frida,
|
|
180
|
+
deviceId: "Z1",
|
|
181
|
+
agentLoader: () => "",
|
|
182
|
+
logger: (e) => events.push(e),
|
|
183
|
+
});
|
|
184
|
+
await p.getKey();
|
|
185
|
+
expect(events.some((e) => e.kind === "frida-message" && e.evt.kind === "hooked")).toBe(true);
|
|
186
|
+
expect(events.some((e) => e.kind === "frida-message" && e.evt.kind === "key")).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
WeChatKeyProvider,
|
|
7
|
+
WeChatMD5KeyProvider,
|
|
8
|
+
} = require("../../lib/adapters/wechat");
|
|
9
|
+
|
|
10
|
+
describe("WeChatKeyProvider — base contract", () => {
|
|
11
|
+
it("getKey throws on bare base instance (subclass must override)", async () => {
|
|
12
|
+
const base = new WeChatKeyProvider();
|
|
13
|
+
await expect(base.getKey()).rejects.toThrow(/must be overridden/);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("name defaults to key-provider-base", () => {
|
|
17
|
+
const base = new WeChatKeyProvider();
|
|
18
|
+
expect(base.name).toBe("key-provider-base");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("WeChatMD5KeyProvider — construction validation", () => {
|
|
23
|
+
it("throws if opts missing", () => {
|
|
24
|
+
expect(() => new WeChatMD5KeyProvider()).toThrow(/wechatDataPath/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("throws if wechatDataPath missing", () => {
|
|
28
|
+
expect(() => new WeChatMD5KeyProvider({ uin: "1" })).toThrow(/wechatDataPath/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("name returns md5", () => {
|
|
32
|
+
const p = new WeChatMD5KeyProvider({ wechatDataPath: "/tmp/wx" });
|
|
33
|
+
expect(p.name).toBe("md5");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("WeChatMD5KeyProvider — extractor DI happy path", () => {
|
|
38
|
+
it("getKey returns hex when extractor yields key", async () => {
|
|
39
|
+
const extractor = (opts) => {
|
|
40
|
+
expect(opts.wechatDataPath).toBe("/tmp/wx");
|
|
41
|
+
return {
|
|
42
|
+
uin: "100200300",
|
|
43
|
+
imei: "350123456789012",
|
|
44
|
+
key: "abcdef1",
|
|
45
|
+
source: "test",
|
|
46
|
+
warnings: [],
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const p = new WeChatMD5KeyProvider({
|
|
50
|
+
wechatDataPath: "/tmp/wx",
|
|
51
|
+
extractor,
|
|
52
|
+
});
|
|
53
|
+
const key = await p.getKey();
|
|
54
|
+
expect(key).toBe("abcdef1");
|
|
55
|
+
expect(p.getLastResult().uin).toBe("100200300");
|
|
56
|
+
expect(p.getLastResult().imei).toBe("350123456789012");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("getKey passes uin/imei overrides through to extractor", async () => {
|
|
60
|
+
let passedOpts = null;
|
|
61
|
+
const extractor = (opts) => {
|
|
62
|
+
passedOpts = opts;
|
|
63
|
+
return { key: "0000000", uin: opts.uin, imei: opts.imei, warnings: [] };
|
|
64
|
+
};
|
|
65
|
+
const p = new WeChatMD5KeyProvider({
|
|
66
|
+
wechatDataPath: "/tmp/wx",
|
|
67
|
+
uin: "999",
|
|
68
|
+
imei: "deadbeef",
|
|
69
|
+
extractor,
|
|
70
|
+
});
|
|
71
|
+
await p.getKey();
|
|
72
|
+
expect(passedOpts.uin).toBe("999");
|
|
73
|
+
expect(passedOpts.imei).toBe("deadbeef");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("WeChatMD5KeyProvider — extractor failure surfaces as throw", () => {
|
|
78
|
+
it("throws with warnings when extractor returns no key", async () => {
|
|
79
|
+
const extractor = () => ({
|
|
80
|
+
uin: null,
|
|
81
|
+
imei: null,
|
|
82
|
+
key: null,
|
|
83
|
+
source: "missing",
|
|
84
|
+
warnings: ["UIN not found in shared_prefs", "IMEI not found in CompatibleInfo.cfg"],
|
|
85
|
+
});
|
|
86
|
+
const p = new WeChatMD5KeyProvider({
|
|
87
|
+
wechatDataPath: "/tmp/empty",
|
|
88
|
+
extractor,
|
|
89
|
+
});
|
|
90
|
+
await expect(p.getKey()).rejects.toThrow(/UIN not found/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("throws with generic reason when warnings empty", async () => {
|
|
94
|
+
const extractor = () => ({ key: null, warnings: [] });
|
|
95
|
+
const p = new WeChatMD5KeyProvider({
|
|
96
|
+
wechatDataPath: "/tmp/empty",
|
|
97
|
+
extractor,
|
|
98
|
+
});
|
|
99
|
+
await expect(p.getKey()).rejects.toThrow(/extraction returned empty/);
|
|
100
|
+
});
|
|
101
|
+
});
|