@chainlesschain/personal-data-hub 0.4.28 → 0.4.30

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.
Files changed (204) hide show
  1. package/README.md +13 -5
  2. package/lib/adapters/social-douyin-adb/usage-profile-reader.js +253 -0
  3. package/lib/adapters/social-douyin-adb/watch-history-reader.js +104 -31
  4. package/lib/adapters/social-toutiao-adb/article-reader.js +202 -0
  5. package/lib/analysis-skills/overview.js +24 -4
  6. package/lib/analysis-skills/spending.js +63 -2
  7. package/lib/analysis-skills/timeline.js +11 -6
  8. package/lib/prompt-builder.js +15 -1
  9. package/lib/query-parser.js +38 -8
  10. package/package.json +4 -1
  11. package/__tests__/adapter-guide.test.js +0 -47
  12. package/__tests__/adapter-spec.test.js +0 -78
  13. package/__tests__/adapters/ai-chat-cookie-capture-spec.test.js +0 -211
  14. package/__tests__/adapters/ai-chat-health-checker.test.js +0 -262
  15. package/__tests__/adapters/ai-chat-history.test.js +0 -396
  16. package/__tests__/adapters/ai-chat-http-client.test.js +0 -242
  17. package/__tests__/adapters/ai-chat-vendors.test.js +0 -874
  18. package/__tests__/adapters/alipay-bill-adapter.test.js +0 -538
  19. package/__tests__/adapters/apple-health.test.js +0 -95
  20. package/__tests__/adapters/bank-family.test.js +0 -125
  21. package/__tests__/adapters/biz-tianyancha.test.js +0 -159
  22. package/__tests__/adapters/browser-history-chrome.test.js +0 -377
  23. package/__tests__/adapters/browser-history-edge.test.js +0 -159
  24. package/__tests__/adapters/car-mercedesme.test.js +0 -74
  25. package/__tests__/adapters/doc-baidu-netdisk.test.js +0 -102
  26. package/__tests__/adapters/doc-camscanner.test.js +0 -147
  27. package/__tests__/adapters/doc-platforms.test.js +0 -177
  28. package/__tests__/adapters/edu-huawei-learning-live.test.js +0 -198
  29. package/__tests__/adapters/edu-zuoyebang-live.test.js +0 -226
  30. package/__tests__/adapters/email-adapter-snapshot.test.js +0 -237
  31. package/__tests__/adapters/email-adapter.test.js +0 -742
  32. package/__tests__/adapters/email-classifier.test.js +0 -347
  33. package/__tests__/adapters/email-imap-session.test.js +0 -334
  34. package/__tests__/adapters/email-parser.test.js +0 -244
  35. package/__tests__/adapters/email-pdf-extractor.test.js +0 -529
  36. package/__tests__/adapters/email-providers.test.js +0 -84
  37. package/__tests__/adapters/email-retry-progress.test.js +0 -294
  38. package/__tests__/adapters/email-templates.test.js +0 -822
  39. package/__tests__/adapters/family-23-collectors-scaffold.test.js +0 -182
  40. package/__tests__/adapters/finance-alipay-live.test.js +0 -258
  41. package/__tests__/adapters/finance-dcep.test.js +0 -74
  42. package/__tests__/adapters/fitness-joyrun.test.js +0 -82
  43. package/__tests__/adapters/game-genshin-live.test.js +0 -238
  44. package/__tests__/adapters/game-genshin-scaffold.test.js +0 -108
  45. package/__tests__/adapters/game-honor-of-kings-live.test.js +0 -230
  46. package/__tests__/adapters/git-activity.test.js +0 -222
  47. package/__tests__/adapters/gov-12123.test.js +0 -103
  48. package/__tests__/adapters/gov-ixiamen.test.js +0 -150
  49. package/__tests__/adapters/gov-tax.test.js +0 -135
  50. package/__tests__/adapters/health-meiyou.test.js +0 -125
  51. package/__tests__/adapters/local-files.test.js +0 -264
  52. package/__tests__/adapters/local-im-pc.test.js +0 -154
  53. package/__tests__/adapters/messaging-whatsapp.test.js +0 -289
  54. package/__tests__/adapters/music-kugou.test.js +0 -187
  55. package/__tests__/adapters/music-qq.test.js +0 -112
  56. package/__tests__/adapters/netease-music-live.test.js +0 -244
  57. package/__tests__/adapters/netease-music.test.js +0 -74
  58. package/__tests__/adapters/pc-local-discovery.test.js +0 -141
  59. package/__tests__/adapters/qq-pc-direct-read.test.js +0 -227
  60. package/__tests__/adapters/reading-family.test.js +0 -108
  61. package/__tests__/adapters/recruit-boss.test.js +0 -180
  62. package/__tests__/adapters/shell-history.test.js +0 -180
  63. package/__tests__/adapters/shopping-base.test.js +0 -179
  64. package/__tests__/adapters/shopping-dianping.test.js +0 -239
  65. package/__tests__/adapters/social-bilibili-adb-api-client.test.js +0 -721
  66. package/__tests__/adapters/social-bilibili-adb-chromium-cookies-reader.test.js +0 -346
  67. package/__tests__/adapters/social-bilibili-adb-collector.test.js +0 -284
  68. package/__tests__/adapters/social-bilibili-adb-cookies-extension.test.js +0 -343
  69. package/__tests__/adapters/social-bilibili-adb-snapshot-builder.test.js +0 -296
  70. package/__tests__/adapters/social-csdn.test.js +0 -175
  71. package/__tests__/adapters/social-dongchedi.test.js +0 -165
  72. package/__tests__/adapters/social-douyin-adb-aweme-detail.test.js +0 -165
  73. package/__tests__/adapters/social-douyin-adb-collector.test.js +0 -254
  74. package/__tests__/adapters/social-douyin-adb-db-extension.test.js +0 -114
  75. package/__tests__/adapters/social-douyin-adb-im-db-parser.test.js +0 -304
  76. package/__tests__/adapters/social-douyin-adb-snapshot-builder.test.js +0 -216
  77. package/__tests__/adapters/social-douyin-adb-watch-history.test.js +0 -192
  78. package/__tests__/adapters/social-kuaishou-adb-api-client.test.js +0 -496
  79. package/__tests__/adapters/social-kuaishou-adb-collector.test.js +0 -276
  80. package/__tests__/adapters/social-kuaishou-adb-cookies-extension.test.js +0 -152
  81. package/__tests__/adapters/social-kuaishou-adb-snapshot-builder.test.js +0 -178
  82. package/__tests__/adapters/social-toutiao-adb-account-reader.test.js +0 -135
  83. package/__tests__/adapters/social-toutiao-adb-api-client.test.js +0 -626
  84. package/__tests__/adapters/social-toutiao-adb-collector.test.js +0 -378
  85. package/__tests__/adapters/social-toutiao-adb-cookies-extension.test.js +0 -193
  86. package/__tests__/adapters/social-toutiao-adb-snapshot-builder.test.js +0 -196
  87. package/__tests__/adapters/social-toutiao-kuaishou-scaffold.test.js +0 -311
  88. package/__tests__/adapters/social-weibo-adb-api-client.test.js +0 -362
  89. package/__tests__/adapters/social-weibo-adb-collector.test.js +0 -201
  90. package/__tests__/adapters/social-weibo-adb-cookies-extension.test.js +0 -167
  91. package/__tests__/adapters/social-weibo-adb-snapshot-builder.test.js +0 -189
  92. package/__tests__/adapters/social-xiaohongshu-adb-api-client.test.js +0 -431
  93. package/__tests__/adapters/social-xiaohongshu-adb-collector.test.js +0 -207
  94. package/__tests__/adapters/social-xiaohongshu-adb-cookies-extension.test.js +0 -0
  95. package/__tests__/adapters/social-xiaohongshu-adb-sign-provider-injection.test.js +0 -351
  96. package/__tests__/adapters/social-xiaohongshu-adb-sign.test.js +0 -130
  97. package/__tests__/adapters/social-xiaohongshu-adb-snapshot-builder.test.js +0 -200
  98. package/__tests__/adapters/social-zhihu.test.js +0 -246
  99. package/__tests__/adapters/system-data-adapter.test.js +0 -443
  100. package/__tests__/adapters/system-data-android-ingest.test.js +0 -144
  101. package/__tests__/adapters/system-data-android.test.js +0 -519
  102. package/__tests__/adapters/system-data-disclosure.test.js +0 -153
  103. package/__tests__/adapters/travel-12306.test.js +0 -512
  104. package/__tests__/adapters/travel-amap.test.js +0 -219
  105. package/__tests__/adapters/travel-baidu-map.test.js +0 -305
  106. package/__tests__/adapters/travel-base.test.js +0 -205
  107. package/__tests__/adapters/travel-ctrip.test.js +0 -377
  108. package/__tests__/adapters/travel-didi-consumer.test.js +0 -66
  109. package/__tests__/adapters/travel-didi.test.js +0 -204
  110. package/__tests__/adapters/travel-tencent-map.test.js +0 -207
  111. package/__tests__/adapters/travel-tongcheng.test.js +0 -289
  112. package/__tests__/adapters/video-platforms.test.js +0 -152
  113. package/__tests__/adapters/video-xigua.test.js +0 -106
  114. package/__tests__/adapters/vscode.test.js +0 -299
  115. package/__tests__/adapters/wechat-bootstrap.test.js +0 -240
  116. package/__tests__/adapters/wechat-env-probe.test.js +0 -162
  117. package/__tests__/adapters/wechat-frida-agent.test.js +0 -322
  118. package/__tests__/adapters/wechat-frida-integration.test.js +0 -149
  119. package/__tests__/adapters/wechat-frida-key-provider.test.js +0 -188
  120. package/__tests__/adapters/wechat-md5-key-provider.test.js +0 -101
  121. package/__tests__/adapters/wechat-pc-direct-read.test.js +0 -365
  122. package/__tests__/adapters/wechat-pc-group-topic.test.js +0 -63
  123. package/__tests__/adapters/wechat-pc-v4-sidecar.test.js +0 -72
  124. package/__tests__/adapters/weread.test.js +0 -123
  125. package/__tests__/adapters/wework-pc.test.js +0 -124
  126. package/__tests__/adapters/win-recent.test.js +0 -192
  127. package/__tests__/analysis-skills.test.js +0 -679
  128. package/__tests__/analysis.test.js +0 -1845
  129. package/__tests__/audio-ximalaya-snapshot.test.js +0 -279
  130. package/__tests__/batch.test.js +0 -133
  131. package/__tests__/bridges-cc-kg.test.js +0 -231
  132. package/__tests__/bridges-cc-llm.test.js +0 -191
  133. package/__tests__/bridges-cc-rag.test.js +0 -162
  134. package/__tests__/categories.test.js +0 -92
  135. package/__tests__/e2e/ai-chat-cross-source-journey.test.js +0 -213
  136. package/__tests__/e2e/full-user-journey.test.js +0 -188
  137. package/__tests__/e2e/local-data-adapters-cli.e2e.test.js +0 -146
  138. package/__tests__/entity-resolver-ingest-hook.test.js +0 -177
  139. package/__tests__/entity-resolver-stages.test.js +0 -411
  140. package/__tests__/entity-resolver-vault.test.js +0 -249
  141. package/__tests__/entity-resolver.test.js +0 -526
  142. package/__tests__/fitness-keep-snapshot.test.js +0 -224
  143. package/__tests__/fixtures/entity-resolver-200-mock.json +0 -96
  144. package/__tests__/ids.test.js +0 -45
  145. package/__tests__/integration/ai-chat-history-registry.test.js +0 -228
  146. package/__tests__/integration/aichat-wizard-end-to-end.test.js +0 -282
  147. package/__tests__/integration/cross-adapter-pipelines.test.js +0 -396
  148. package/__tests__/integration/local-data-adapters-pipeline.test.js +0 -373
  149. package/__tests__/integration/social-bilibili-pipeline.test.js +0 -261
  150. package/__tests__/integration/wechat-bootstrap-end-to-end.test.js +0 -390
  151. package/__tests__/key-providers.test.js +0 -126
  152. package/__tests__/kg-derive.test.js +0 -219
  153. package/__tests__/llm-client.test.js +0 -122
  154. package/__tests__/longtail-adapters.test.js +0 -281
  155. package/__tests__/messaging-qq-snapshot.test.js +0 -294
  156. package/__tests__/mobile-extractor-encrypted.test.js +0 -460
  157. package/__tests__/mobile-extractor.test.js +0 -288
  158. package/__tests__/mock-adapter.test.js +0 -93
  159. package/__tests__/prompt-builder.test.js +0 -249
  160. package/__tests__/query-parser.test.js +0 -302
  161. package/__tests__/rag-derive.test.js +0 -169
  162. package/__tests__/registry-readiness.test.js +0 -292
  163. package/__tests__/registry.test.js +0 -420
  164. package/__tests__/salvage-ingest.test.js +0 -97
  165. package/__tests__/schemas.test.js +0 -331
  166. package/__tests__/shopping-adapters.test.js +0 -392
  167. package/__tests__/shopping-eleme-snapshot.test.js +0 -454
  168. package/__tests__/shopping-pinduoduo-snapshot.test.js +0 -484
  169. package/__tests__/shopping-snapshot.test.js +0 -438
  170. package/__tests__/shopping-vipshop-snapshot.test.js +0 -425
  171. package/__tests__/shopping-xianyu-snapshot.test.js +0 -451
  172. package/__tests__/sidecar-contacts-cross-validate.test.js +0 -186
  173. package/__tests__/sidecar-supervisor.test.js +0 -128
  174. package/__tests__/sign-providers.test.js +0 -62
  175. package/__tests__/social-adapters.test.js +0 -280
  176. package/__tests__/social-bilibili-snapshot.test.js +0 -278
  177. package/__tests__/social-douban-snapshot.test.js +0 -351
  178. package/__tests__/social-douyin-im-direct-read.test.js +0 -377
  179. package/__tests__/social-douyin-salvage-collector.test.js +0 -98
  180. package/__tests__/social-douyin-salvage-mapper.test.js +0 -90
  181. package/__tests__/social-douyin-snapshot.test.js +0 -256
  182. package/__tests__/social-kuaishou-snapshot.test.js +0 -362
  183. package/__tests__/social-toutiao-snapshot.test.js +0 -366
  184. package/__tests__/social-weibo-snapshot.test.js +0 -234
  185. package/__tests__/social-weibo-sqlite-device.test.js +0 -174
  186. package/__tests__/social-xiaohongshu-snapshot.test.js +0 -232
  187. package/__tests__/sqlite-leaf-salvage.test.js +0 -97
  188. package/__tests__/travel-adapters.test.js +0 -483
  189. package/__tests__/travel-maps-snapshot.test.js +0 -426
  190. package/__tests__/vault-driver-error.test.js +0 -74
  191. package/__tests__/vault-search-helpers.test.js +0 -104
  192. package/__tests__/vault-search.test.js +0 -423
  193. package/__tests__/vault.test.js +0 -767
  194. package/__tests__/wechat-adapter.test.js +0 -594
  195. package/__tests__/whatsapp-adapter.test.js +0 -138
  196. package/scripts/_make-fixture-all.js +0 -126
  197. package/scripts/_make-fixture-contacts.js +0 -84
  198. package/scripts/evaluate-entity-resolver.js +0 -213
  199. package/scripts/run-native-tests-sandbox.sh +0 -55
  200. package/scripts/smoke-phase-5-5.js +0 -196
  201. package/scripts/smoke-phase-5-7.js +0 -181
  202. package/scripts/smoke-system-data-contacts.js +0 -309
  203. package/scripts/smoke-system-data.js +0 -312
  204. package/vitest.config.js +0 -88
@@ -1,322 +0,0 @@
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 — sjqz-audit fixes (sig + format + module case)", () => {
175
- // Helper extending fakePtr with readCString for ascii-hex tests.
176
- function fakeAsciiHexPtr(asciiHex) {
177
- return {
178
- _v: asciiHex,
179
- toInt32() { return 0; },
180
- readByteArray(_len) { return new Uint8Array(0).buffer; },
181
- };
182
- }
183
- function memoryReadCString(ptr, _maxLen) {
184
- return ptr && typeof ptr._v === "string" ? ptr._v : null;
185
- }
186
-
187
- it("attaches when only uppercase libWCDB.so resolves (sjqz canonical name)", () => {
188
- const send = vi.fn();
189
- const Interceptor = { attach: vi.fn() };
190
- const Module = {
191
- findExportByName(mod, sym) {
192
- return mod === "libWCDB.so" && sym === "sqlite3_key"
193
- ? { symbol: sym }
194
- : null;
195
- },
196
- };
197
- const Process = {
198
- findModuleByName(mod) {
199
- return mod === "libWCDB.so" ? { name: mod } : null;
200
- },
201
- };
202
-
203
- runAgentUnderMock({ Module, Process, Interceptor, send });
204
-
205
- const hooked = send.mock.calls.find((c) => c[0].kind === "hooked");
206
- expect(hooked).toBeDefined();
207
- expect(hooked[0].module).toBe("libWCDB.so");
208
- });
209
-
210
- it("v2 hook reads key from args[2] and length from args[3] (not args[1]/[2])", () => {
211
- const send = vi.fn();
212
- const attached = {};
213
- const Interceptor = {
214
- attach(addr, handlers) { attached[addr.symbol] = handlers; },
215
- };
216
- const Module = {
217
- findExportByName(mod, sym) {
218
- return sym === "sqlite3_key_v2" ? { symbol: sym } : null;
219
- },
220
- };
221
- const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
222
-
223
- runAgentUnderMock({ Module, Process, Interceptor, send });
224
-
225
- // sqlite3_key_v2(sqlite3 *db, const char *zDbName, const void *pKey, int nKey)
226
- // args[0]=db, args[1]=name, args[2]=keyBytes, args[3]=len
227
- const dbNamePtr = fakePtr("ffeeffeeffeeffeeffeeffeeffeeffee"); // would be wrong if read as key
228
- const keyHex = "12345678" + "00".repeat(28); // 32 bytes
229
- const args = [
230
- fakePtr(0), // db
231
- dbNamePtr, // name (NOT the key)
232
- fakePtr(keyHex), // pKey — correct args[2]
233
- fakePtr(32), // nKey — correct args[3]
234
- ];
235
- attached.sqlite3_key_v2.onEnter(args);
236
-
237
- const keyEvt = send.mock.calls.find((c) => c[0].kind === "key");
238
- expect(keyEvt).toBeDefined();
239
- expect(keyEvt[0].hex).toBe(keyHex); // proves args[2] was read, not args[1]
240
- expect(keyEvt[0].sig).toBe("v2");
241
- expect(keyEvt[0].format).toBe("raw-bytes");
242
- expect(keyEvt[0].length).toBe(32);
243
- });
244
-
245
- it("reads ascii-hex key via readCString when length === 64", () => {
246
- const send = vi.fn();
247
- const attached = {};
248
- const Interceptor = {
249
- attach(addr, handlers) { attached[addr.symbol] = handlers; },
250
- };
251
- const Module = {
252
- findExportByName(mod, sym) {
253
- return sym === "sqlite3_key" ? { symbol: sym } : null;
254
- },
255
- };
256
- const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
257
- const Memory = { readCString: memoryReadCString };
258
-
259
- runAgentUnderMock({ Module, Process, Interceptor, send, Memory });
260
-
261
- // 64-char ASCII hex string + len=64 → readCString path (sjqz scenario)
262
- const asciiHex = "ABCDEF0123456789".repeat(4).toLowerCase();
263
- const args = [fakePtr(0), fakeAsciiHexPtr(asciiHex), fakePtr(64)];
264
- attached.sqlite3_key.onEnter(args);
265
-
266
- const keyEvt = send.mock.calls.find((c) => c[0].kind === "key");
267
- expect(keyEvt).toBeDefined();
268
- expect(keyEvt[0].hex).toBe(asciiHex);
269
- expect(keyEvt[0].format).toBe("ascii-hex");
270
- expect(keyEvt[0].length).toBe(64);
271
- });
272
-
273
- it("emits unsupported-signature error for mangled C++ symbol (no host attempt)", () => {
274
- const send = vi.fn();
275
- const attached = {};
276
- const Interceptor = {
277
- attach(addr, handlers) { attached[addr.symbol] = handlers; },
278
- };
279
- const mangledSymbol =
280
- "_ZN4WCDB8Database13setCipherKeyERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE";
281
- const Module = {
282
- findExportByName(mod, sym) {
283
- return sym === mangledSymbol ? { symbol: sym } : null;
284
- },
285
- };
286
- const Process = { findModuleByName() { return { name: "libwcdb.so" }; } };
287
-
288
- runAgentUnderMock({ Module, Process, Interceptor, send });
289
-
290
- attached[mangledSymbol].onEnter([fakePtr(0), fakePtr("aabb"), fakePtr(32)]);
291
-
292
- const errEvt = send.mock.calls.find(
293
- (c) => c[0].kind === "error" && /unsupported symbol signature/.test(c[0].message),
294
- );
295
- expect(errEvt).toBeDefined();
296
- // And NO key event emitted (host must fall back to MD5 path).
297
- const keyEvt = send.mock.calls.find((c) => c[0].kind === "key");
298
- expect(keyEvt).toBeUndefined();
299
- });
300
- });
301
-
302
- describe("frida-agent — module not yet loaded path", () => {
303
- it("emits module-waiting and schedules retry", () => {
304
- const send = vi.fn();
305
- const Interceptor = { attach: vi.fn() };
306
- const Module = { findExportByName: vi.fn().mockReturnValue(null) };
307
- const Process = { findModuleByName: vi.fn().mockReturnValue(null) };
308
- const setTimeoutMock = vi.fn();
309
-
310
- runAgentUnderMock({ Module, Process, Interceptor, send, setTimeout: setTimeoutMock });
311
-
312
- const waiting = send.mock.calls.find((c) => c[0].kind === "module-waiting");
313
- expect(waiting).toBeDefined();
314
- // Post-sjqz audit: agent now tries both libWCDB.so (uppercase, sjqz-verified)
315
- // and libwcdb.so. The module-waiting event surfaces the join so the
316
- // host telemetry shows both attempted names.
317
- expect(waiting[0].module).toBe("libWCDB.so|libwcdb.so");
318
- expect(setTimeoutMock).toHaveBeenCalled();
319
- // First retry delay 500ms
320
- expect(setTimeoutMock.mock.calls[0][1]).toBe(500);
321
- });
322
- });
@@ -1,149 +0,0 @@
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
- });
@@ -1,188 +0,0 @@
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
- });