deepspider 0.2.6 → 0.2.9
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/.trellis/spec/backend/ci-cd-guidelines.md +73 -0
- package/.trellis/spec/backend/deepagents-guide.md +43 -0
- package/.trellis/spec/backend/hook-guidelines.md +40 -0
- package/.trellis/spec/backend/index.md +1 -0
- package/.trellis/spec/backend/quality-guidelines.md +77 -0
- package/.trellis/workspace/pony/index.md +3 -2
- package/.trellis/workspace/pony/journal-1.md +64 -0
- package/CLAUDE.md +23 -0
- package/README.md +6 -0
- package/package.json +3 -2
- package/src/agent/prompts/system.js +63 -255
- package/src/agent/run.js +48 -17
- package/src/agent/skills/static-analysis/SKILL.md +120 -0
- package/src/agent/tools/browser.js +99 -0
- package/src/agent/tools/report.js +64 -14
- package/src/agent/tools/runtime.js +6 -4
- package/src/agent/tools/utils.js +0 -1
- package/src/browser/defaultHooks.js +325 -27
- package/src/browser/hooks/index.js +14 -18
- package/src/browser/ui/analysisPanel.js +461 -388
- package/src/env/HookBase.js +38 -18
- package/src/browser/hooks/crypto.js +0 -55
- package/src/browser/hooks/native.js +0 -9
- package/src/browser/hooks/network.js +0 -33
package/src/env/HookBase.js
CHANGED
|
@@ -152,15 +152,22 @@ export class HookBase {
|
|
|
152
152
|
|
|
153
153
|
// 性能优化:可配置是否记录调用栈
|
|
154
154
|
let stack = null;
|
|
155
|
+
let caller = null;
|
|
155
156
|
if (config.captureStack) {
|
|
156
157
|
const err = new Error();
|
|
157
158
|
stack = err.stack;
|
|
159
|
+
// 解析调用栈,提取文件和行号信息
|
|
160
|
+
const parsed = window.__deepspider__.parseStack(stack, config.stackDepth);
|
|
161
|
+
if (parsed.length > 0) {
|
|
162
|
+
caller = parsed[0]; // 第一个有效调用位置
|
|
163
|
+
}
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
const entry = {
|
|
161
167
|
...data,
|
|
162
168
|
timestamp: Date.now(),
|
|
163
169
|
stack: stack,
|
|
170
|
+
caller: caller, // 解析后的调用位置 { func, file, line, col }
|
|
164
171
|
requestId: requestContext?.id || null
|
|
165
172
|
};
|
|
166
173
|
|
|
@@ -181,7 +188,9 @@ export class HookBase {
|
|
|
181
188
|
fetch: 'color: #9C27B0',
|
|
182
189
|
};
|
|
183
190
|
const color = colors[data.action] || colors[type] || 'color: #666';
|
|
184
|
-
|
|
191
|
+
// 显示调用位置
|
|
192
|
+
const loc = caller ? ' @ ' + (caller.file || '').split('/').pop() + ':' + caller.line : '';
|
|
193
|
+
console.log('%c[DeepSpider:' + type + ']' + loc, color, data.action || '', data);
|
|
185
194
|
}
|
|
186
195
|
return entry;
|
|
187
196
|
},
|
|
@@ -190,30 +199,41 @@ export class HookBase {
|
|
|
190
199
|
parseStack: function(stack, depth) {
|
|
191
200
|
if (!stack) return [];
|
|
192
201
|
const maxDepth = depth || config.stackDepth || 5;
|
|
193
|
-
//
|
|
194
|
-
const
|
|
202
|
+
// 过滤 Hook 框架和常见库的调用栈
|
|
203
|
+
const skipPatterns = [
|
|
204
|
+
/__deepspider__/,
|
|
205
|
+
/deepspider\\.native/,
|
|
206
|
+
/hookFunc|hooked|origEnc|origDec|original/i,
|
|
207
|
+
/^Error$/,
|
|
208
|
+
/at Object\\.log/,
|
|
209
|
+
/at Object\\.parseStack/,
|
|
195
210
|
/react|vue|angular|jquery|lodash|axios/i,
|
|
196
211
|
/node_modules/,
|
|
197
|
-
|
|
198
|
-
|
|
212
|
+
/^webpack:/,
|
|
213
|
+
/\\(native\\)/,
|
|
214
|
+
/<anonymous>:\\d+:\\d+$/
|
|
199
215
|
];
|
|
200
216
|
|
|
201
|
-
return stack.split('\\n').slice(
|
|
202
|
-
|
|
203
|
-
|
|
217
|
+
return stack.split('\\n').slice(1).map(function(line) {
|
|
218
|
+
// Chrome/Node 格式: at funcName (file:line:col) 或 at file:line:col
|
|
219
|
+
let match = line.match(/at\\s+(.+?)\\s+\\((.+?):(\\d+):(\\d+)\\)/);
|
|
220
|
+
if (match) {
|
|
221
|
+
return { func: match[1], file: match[2], line: parseInt(match[3]), col: parseInt(match[4]) };
|
|
222
|
+
}
|
|
223
|
+
match = line.match(/at\\s+(.+?):(\\d+):(\\d+)/);
|
|
204
224
|
if (match) {
|
|
205
|
-
return {
|
|
206
|
-
func: match[1] || 'anonymous',
|
|
207
|
-
file: match[2] || match[1],
|
|
208
|
-
line: parseInt(match[3] || match[2]),
|
|
209
|
-
col: parseInt(match[4] || match[3])
|
|
210
|
-
};
|
|
225
|
+
return { func: 'anonymous', file: match[1], line: parseInt(match[2]), col: parseInt(match[3]) };
|
|
211
226
|
}
|
|
212
|
-
|
|
227
|
+
// Firefox 格式: funcName@file:line:col
|
|
228
|
+
match = line.match(/(.+?)@(.+?):(\\d+):(\\d+)/);
|
|
229
|
+
if (match) {
|
|
230
|
+
return { func: match[1] || 'anonymous', file: match[2], line: parseInt(match[3]), col: parseInt(match[4]) };
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
213
233
|
}).filter(function(f) {
|
|
214
|
-
if (!f
|
|
215
|
-
const str = f.
|
|
216
|
-
return !
|
|
234
|
+
if (!f || !f.file) return false;
|
|
235
|
+
const str = f.func + ' ' + f.file;
|
|
236
|
+
return !skipPatterns.some(function(p) { return p.test(str); });
|
|
217
237
|
}).slice(0, maxDepth);
|
|
218
238
|
},
|
|
219
239
|
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DeepSpider - 加密库 Hook
|
|
3
|
-
* 已废弃,请使用 src/env/CryptoHook.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const cryptoHook = `
|
|
7
|
-
(function() {
|
|
8
|
-
const deepspider = window.__deepspider__;
|
|
9
|
-
if (!deepspider) return;
|
|
10
|
-
|
|
11
|
-
// Hook Function.prototype.apply (CryptoJS)
|
|
12
|
-
const _apply = Function.prototype.apply;
|
|
13
|
-
const applyHook = function() {
|
|
14
|
-
const result = _apply.call(this, ...arguments);
|
|
15
|
-
try {
|
|
16
|
-
if (arguments.length === 2 && arguments[1]?.[0]) {
|
|
17
|
-
const cfg = arguments[1][0];
|
|
18
|
-
if (cfg.ciphertext && cfg.key && cfg.algorithm) {
|
|
19
|
-
deepspider.log('crypto', {
|
|
20
|
-
algo: 'CryptoJS',
|
|
21
|
-
key: cfg.key?.toString?.() || '',
|
|
22
|
-
iv: cfg.iv?.toString?.() || '',
|
|
23
|
-
mode: cfg.mode?.name || 'unknown'
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} catch (e) {}
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
Function.prototype.apply = deepspider.native(applyHook, _apply);
|
|
31
|
-
|
|
32
|
-
// Hook RSA
|
|
33
|
-
const _call = Function.prototype.call;
|
|
34
|
-
const callHook = function() {
|
|
35
|
-
const result = _call.call(this, ...arguments);
|
|
36
|
-
try {
|
|
37
|
-
const arg = arguments[0];
|
|
38
|
-
if (arg?.__proto__?.getPublicKey && arg?.__proto__?.encrypt) {
|
|
39
|
-
const proto = arg.__proto__.__proto__;
|
|
40
|
-
if (proto?.encrypt && !proto.__hooked__) {
|
|
41
|
-
proto.__hooked__ = true;
|
|
42
|
-
const _enc = proto.encrypt;
|
|
43
|
-
proto.encrypt = deepspider.native(function(data) {
|
|
44
|
-
const enc = _enc.call(this, data);
|
|
45
|
-
deepspider.log('crypto', { algo: 'RSA', data, encrypted: enc });
|
|
46
|
-
return enc;
|
|
47
|
-
}, _enc);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} catch (e) {}
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
Function.prototype.call = deepspider.native(callHook, _call);
|
|
54
|
-
})();
|
|
55
|
-
`;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DeepSpider - 网络请求 Hook
|
|
3
|
-
* 已废弃,请使用 src/env/NetworkHook.js
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const networkHook = `
|
|
7
|
-
(function() {
|
|
8
|
-
const deepspider = window.__deepspider__;
|
|
9
|
-
if (!deepspider) return;
|
|
10
|
-
|
|
11
|
-
// Hook fetch
|
|
12
|
-
const _fetch = window.fetch;
|
|
13
|
-
window.fetch = deepspider.native(async function(url, options = {}) {
|
|
14
|
-
deepspider.log('fetch', { url, body: options.body });
|
|
15
|
-
return _fetch.call(this, url, options);
|
|
16
|
-
}, _fetch);
|
|
17
|
-
|
|
18
|
-
// Hook XHR
|
|
19
|
-
const _open = XMLHttpRequest.prototype.open;
|
|
20
|
-
const _send = XMLHttpRequest.prototype.send;
|
|
21
|
-
|
|
22
|
-
XMLHttpRequest.prototype.open = deepspider.native(function(method, url) {
|
|
23
|
-
this._url = url;
|
|
24
|
-
this._method = method;
|
|
25
|
-
return _open.apply(this, arguments);
|
|
26
|
-
}, _open);
|
|
27
|
-
|
|
28
|
-
XMLHttpRequest.prototype.send = deepspider.native(function(body) {
|
|
29
|
-
deepspider.log('xhr', { method: this._method, url: this._url, body });
|
|
30
|
-
return _send.apply(this, arguments);
|
|
31
|
-
}, _send);
|
|
32
|
-
})();
|
|
33
|
-
`;
|