dsh-reverse-plugin 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/index.js +78 -0
  2. package/package.json +45 -4
  3. package/preset/js-reverse.patch.yml +179 -0
  4. package/skills/js/iv8-env-runtime/SKILL.md +159 -0
  5. package/skills/js/iv8-env-runtime/assets/entry-report-template.txt +23 -0
  6. package/skills/js/iv8-env-runtime/assets/env_starter.py +100 -0
  7. package/skills/js/iv8-env-runtime/references/case-function-iwencai.md +96 -0
  8. package/skills/js/iv8-env-runtime/references/case-intercept-douyin.md +133 -0
  9. package/skills/js/iv8-env-runtime/references/config-defaults-cheatsheet.md +75 -0
  10. package/skills/js/iv8-env-runtime/references/cross-platform-install.md +108 -0
  11. package/skills/js/iv8-env-runtime/references/iv8-api-contract.md +97 -0
  12. package/skills/js/iv8-env-runtime/references/network-and-eventloop.md +113 -0
  13. package/skills/js/iv8-env-runtime/references/part1-entry-location.md +138 -0
  14. package/skills/js/iv8-env-runtime/references/part1-mcp-tool-map.md +77 -0
  15. package/skills/js/iv8-env-runtime/references/part2-discovery.md +80 -0
  16. package/skills/js/iv8-env-runtime/references/patching-principles.md +91 -0
  17. package/skills/js/iv8-env-runtime/references/trap-blacklist.md +60 -0
  18. package/skills/js/iv8-env-runtime/references/version-gotchas.md +128 -0
  19. package/skills/js/iv8-env-runtime/scripts/consistency_lint.py +211 -0
  20. package/skills/js/iv8-env-runtime/scripts/defaults_audit.py +143 -0
  21. package/skills/js/iv8-env-runtime/scripts/monitor_env.py +185 -0
  22. package/skills/js/iv8-env-runtime/scripts/network_bridge.py +147 -0
  23. package/skills/js/iv8-env-runtime/scripts/parity_check.py +175 -0
  24. package/skills/js/iv8-env-runtime/scripts/preflight.py +144 -0
  25. package/skills/js/iv8-env-runtime/scripts/reproduce_stub_error.py +165 -0
  26. package/skills/js/iv8-env-runtime/scripts/run_target.py +150 -0
  27. package/skills/js/iv8-jsvmp-recovery/SKILL.md +129 -0
  28. package/skills/js/iv8-jsvmp-recovery/agents/openai.yaml +4 -0
  29. package/skills/js/iv8-jsvmp-recovery/references/case-study-douyin-a-bogus.md +320 -0
  30. package/skills/js/iv8-jsvmp-recovery/references/controlled-oracle-and-equivalence.md +247 -0
  31. package/skills/js/iv8-jsvmp-recovery/references/static-trace-evidence.md +289 -0
  32. package/skills/js/iv8-jsvmp-recovery/references/vmp-domain-model.md +212 -0
  33. package/skills/js/iv8-jsvmp-recovery/scripts/verify-equivalence.py +281 -0
  34. package/skills/js/js-ast-deobfuscation/SKILL.md +140 -0
  35. package/skills/js/js-ast-deobfuscation/agents/openai.yaml +4 -0
  36. package/skills/js/js-ast-deobfuscation/references/anti-patterns.md +325 -0
  37. package/skills/js/js-ast-deobfuscation/references/first-pass.md +255 -0
  38. package/skills/js/js-ast-deobfuscation/references/interaction-and-stopping.md +758 -0
  39. package/skills/js/js-ast-deobfuscation/references/iv8-runtime-observation.md +773 -0
  40. package/skills/js/js-ast-deobfuscation/references/jsvmp-identification.md +328 -0
  41. package/skills/js/js-ast-deobfuscation/references/methods-and-evidence.md +460 -0
  42. package/skills/js/js-ast-deobfuscation/references/patterns-and-priority.md +516 -0
  43. package/skills/js/js-ast-deobfuscation/references/validation-contract.md +604 -0
  44. package/skills/js/js-ast-deobfuscation/scripts/prepare-source.mjs +921 -0
  45. package/README.md +0 -3
package/index.js ADDED
@@ -0,0 +1,78 @@
1
+ // Reverse-engineering toolkit bundle. Each mode preset mounts this module with
2
+ // its own skills directory, so a preset exposes that domain's skills alone.
3
+ import { readdirSync, readFileSync, statSync } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { parse } from 'yaml'
7
+
8
+ export const name = 'reverse-skills'
9
+
10
+ /** This bundle contributes skills, so it needs the skill registry. */
11
+ export const inject = ['skills']
12
+
13
+ const PACKAGE_ROOT = fileURLToPath(new URL('.', import.meta.url))
14
+
15
+ /** Package-relative skills directory used when a preset mounts without `dir`. */
16
+ const DEFAULT_DIR = 'skills'
17
+
18
+ /**
19
+ * Resolve one mount's skills directory.
20
+ * @param dir - package-relative directory whose child directories each hold a SKILL.md.
21
+ * @returns absolute path to that skills directory.
22
+ */
23
+ export function skillsRoot(dir = DEFAULT_DIR) {
24
+ return join(PACKAGE_ROOT, dir)
25
+ }
26
+
27
+ /**
28
+ * Split one SKILL.md into its YAML frontmatter and the markdown body.
29
+ * @param raw - the raw SKILL.md text.
30
+ * @returns parsed frontmatter (or {}) and the body after the frontmatter.
31
+ */
32
+ export function splitFrontmatter(raw) {
33
+ const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(raw)
34
+ if (match === null) return { data: {}, content: raw }
35
+ return { data: parse(match[1]) ?? {}, content: raw.slice(match[0].length) }
36
+ }
37
+
38
+ /**
39
+ * Collect the runtime skill registrations of one mode's bundled skills.
40
+ * @param dir - package-relative directory holding `<skill>/SKILL.md` entries.
41
+ * @returns one registration per `<name>/SKILL.md` directory.
42
+ */
43
+ export function collectSkills(dir = DEFAULT_DIR) {
44
+ const root = skillsRoot(dir)
45
+ const registrations = []
46
+ for (const entry of readdirSync(root, { withFileTypes: true })) {
47
+ if (!entry.isDirectory()) continue
48
+ const skillPath = join(root, entry.name, 'SKILL.md')
49
+ if (!statSync(skillPath, { throwIfNoEntry: false })?.isFile()) continue
50
+ const { data, content } = splitFrontmatter(readFileSync(skillPath, 'utf8'))
51
+ if (typeof data.name !== 'string' || typeof data.description !== 'string') continue
52
+ registrations.push({
53
+ name: data.name,
54
+ description: data.description,
55
+ whenToUse: typeof data.whenToUse === 'string' ? data.whenToUse : undefined,
56
+ content,
57
+ path: skillPath,
58
+ source: 'custom',
59
+ resourceBase: { kind: 'directory', path: join(root, entry.name) },
60
+ metadata: Object.fromEntries(
61
+ Object.entries(data).filter(([key]) => !['name', 'description', 'whenToUse'].includes(key)),
62
+ ),
63
+ })
64
+ }
65
+ return registrations
66
+ }
67
+
68
+ /**
69
+ * Register one mode's bundled skills; Cordis owns and reverses each registration.
70
+ * @param ctx - plugin context carrying the preset's standing scope.
71
+ * @param config - mount config; `dir` selects the package-relative skills directory.
72
+ */
73
+ export function apply(ctx, config = {}) {
74
+ const dir = typeof config.dir === 'string' && config.dir !== '' ? config.dir : DEFAULT_DIR
75
+ for (const skill of collectSkills(dir)) {
76
+ ctx.skills.register(skill)
77
+ }
78
+ }
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "dsh-reverse-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Reverse-engineering toolkit for DeepSeek Harness: one mode preset per reverse domain, over bundled skills, MCP servers and analysis rules. Ships the JS reverse mode; more modes follow.",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "cordis",
10
+ "reverse-engineering",
11
+ "agent-preset",
12
+ "deobfuscation",
13
+ "jsvmp",
14
+ "iv8",
15
+ "mcp"
16
+ ],
17
+ "homepage": "https://github.com/zhizhuodemao/ai-reverse-resources/tree/main/dsh/reverse-plugin#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/zhizhuodemao/ai-reverse-resources.git",
21
+ "directory": "dsh/reverse-plugin"
22
+ },
23
+ "type": "module",
24
+ "main": "index.js",
25
+ "files": [
26
+ "index.js",
27
+ "preset",
28
+ "skills"
29
+ ],
30
+ "dependencies": {
31
+ "yaml": "^2.4.0"
32
+ },
33
+ "dsh": {
34
+ "bundle": {
35
+ "patch": [
36
+ "./preset/js-reverse.patch.yml"
37
+ ]
38
+ }
39
+ },
40
+ "engines": {
41
+ "node": ">=24.9.0",
42
+ "dsh": "^0.2.1-rc.3"
43
+ },
44
+ "scripts": {
45
+ "test": "node --test tests/*.test.mjs"
46
+ }
47
+ }
@@ -0,0 +1,179 @@
1
+ # JS 逆向模式:技能与 MCP 都挂在这个预设内部,只对该模式的会话可见。
2
+ - insert:
3
+ - id: preset-js-reverse
4
+ name: '@deepseek-ai/dsh-agent-preset'
5
+ config:
6
+ id: js-reverse
7
+ name: JS 逆向模式
8
+ description: JS 逆向工程 Agent:证据驱动、逐步决策,配备 iv8 受控执行与 js-reverse 浏览器取证。
9
+ order: 2
10
+ plugins:
11
+ - id: js-reverse-skills
12
+ name: 'dsh-reverse-plugin'
13
+ config:
14
+ dir: skills/js
15
+
16
+ - id: mcp-js-reverse
17
+ name: '@deepseek-ai/dsh-mcp-client'
18
+ config:
19
+ transport: stdio
20
+ serverName: js-reverse
21
+ command: npx
22
+ args: ['-y', 'js-reverse-mcp@4.0.1']
23
+
24
+ - id: persona
25
+ name: '@deepseek-ai/dsh-persona'
26
+ config:
27
+ prefix: >-
28
+ You are a JS reverse-engineering agent powered by the {{model}} model.
29
+
30
+ 工作准则:
31
+ - 证据驱动:每个结论必须可溯源——静态证据(源码、字节码、AST)或动态证据(受控执行、浏览器观测)。区分"事实"与"推断",不无证猜测。
32
+ - 逐步决策:关键选择先说明依据与代价,等用户决定——解混淆路线、是否补环境、静态还是动态、继续还是交接。
33
+ - 保护原始输入:目标文件一律只读;分析前先做格式化派生副本,一切修改只落在副本。
34
+ - 解混淆服务于分析:产出是方便阅读、搜索、定位、动态观测的派生视图;不以"清理干净"或还原作者原名、原始工程为目标。
35
+ - 受控执行:动态证据通过 iv8(C++ V8 + 浏览器环境)或 js-reverse MCP 取得;Node.js 仅作静态工程工具。
36
+ - 等价验收:恢复的算法、签名、映射以与原始实现精确等价为验收标准;"服务器恰好接受"不是证明。
37
+ - 长线任务用 todo 和 goal 跟踪;多路独立分析(静态/动态/资料)可用 subagent 并行;关键证据和推导过程记录在案,保持可审计。
38
+
39
+ - id: agent-instructions
40
+ name: '@deepseek-ai/dsh-agent-instructions'
41
+ config:
42
+ maxBytes: 65536
43
+
44
+ - id: tool-bash
45
+ name: '@deepseek-ai/dsh-tool-bash'
46
+ disabled: !!js process.platform === 'win32'
47
+
48
+ - id: tool-pwsh
49
+ name: '@deepseek-ai/dsh-tool-pwsh'
50
+ disabled: !!js process.platform !== 'win32'
51
+
52
+ - id: tool-fs
53
+ name: '@deepseek-ai/dsh-tool-fs'
54
+
55
+ - id: tool-fs-search
56
+ name: '@deepseek-ai/dsh-tool-fs-search'
57
+ config:
58
+ sampleOverCapGlobResults: false
59
+
60
+ - id: tool-jobs
61
+ name: '@deepseek-ai/dsh-tool-jobs'
62
+
63
+ - id: skill-filesystem
64
+ name: '@deepseek-ai/dsh-skill-filesystem'
65
+
66
+ - id: tool-skill
67
+ name: '@deepseek-ai/dsh-tool-skill'
68
+
69
+ - id: tool-goal
70
+ name: '@deepseek-ai/dsh-tool-goal'
71
+
72
+ - id: planning
73
+ name: cordis:group
74
+ group: true
75
+ isolate:
76
+ planMode: true
77
+ config:
78
+ - id: plan-mode
79
+ name: '@deepseek-ai/dsh-plan-mode'
80
+ config:
81
+ section: |
82
+ You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
83
+
84
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
85
+
86
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
87
+
88
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
89
+
90
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
91
+
92
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.
93
+
94
+ - id: compaction
95
+ name: cordis:group
96
+ group: true
97
+ isolate:
98
+ compaction: true
99
+ toolResultPruner: true
100
+ config:
101
+ - id: compaction-basic
102
+ name: '@deepseek-ai/dsh-compaction-basic'
103
+
104
+ - id: command-compact
105
+ name: '@deepseek-ai/dsh-command-compact'
106
+
107
+ - id: tool-result-pruner
108
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
109
+ config:
110
+ thresholdChars: 8192
111
+ headChars: 4096
112
+ tailChars: 1024
113
+
114
+ - id: delegation
115
+ name: cordis:group
116
+ group: true
117
+ isolate:
118
+ workflowEngine: true
119
+ config:
120
+ - id: tool-subagent-control
121
+ name: '@deepseek-ai/dsh-tool-subagent-control'
122
+
123
+ - id: tool-subagent
124
+ name: '@deepseek-ai/dsh-tool-subagent'
125
+ config:
126
+ provider: spawn
127
+ toolName: subagent
128
+
129
+ - id: tool-subagent-fork
130
+ name: '@deepseek-ai/dsh-tool-subagent'
131
+ config:
132
+ provider: fork
133
+ toolName: subagent_fork
134
+
135
+ - id: tool-subagent-codex
136
+ name: '@deepseek-ai/dsh-tool-subagent'
137
+ disabled: true
138
+ config:
139
+ provider: codex
140
+ toolName: subagent_codex
141
+ enableRunInBackground: false
142
+ maxDepth: provider-managed
143
+
144
+ - id: tool-subagent-claude-code
145
+ name: '@deepseek-ai/dsh-tool-subagent'
146
+ disabled: true
147
+ config:
148
+ provider: claude-code
149
+ toolName: subagent_claude_code
150
+ enableRunInBackground: false
151
+ maxDepth: provider-managed
152
+
153
+ - id: workflow-ptc
154
+ name: '@deepseek-ai/dsh-workflow-ptc'
155
+ config:
156
+ provider: spawn
157
+
158
+ - id: tool-workflow
159
+ name: '@deepseek-ai/dsh-tool-workflow'
160
+
161
+ - id: tool-ralph
162
+ name: '@deepseek-ai/dsh-tool-ralph'
163
+ config:
164
+ subagentProvider: spawn
165
+ maxRounds: 64
166
+
167
+ - id: tool-ask-user
168
+ name: '@deepseek-ai/dsh-tool-ask-user'
169
+
170
+ - id: tool-todo
171
+ name: '@deepseek-ai/dsh-tool-todo'
172
+ config:
173
+ allowParallelInProgress: true
174
+
175
+ - id: tool-web
176
+ name: '@deepseek-ai/dsh-tool-web'
177
+ config:
178
+ fetch: false
179
+ searchTimeoutMs: 60000
@@ -0,0 +1,159 @@
1
+ ---
2
+ name: iv8-env-runtime
3
+ description: >-
4
+ 强制使用 iv8(Python 原生的 C++ V8 + 浏览器环境运行时)作为目标 JavaScript 的唯一受控执行底座,
5
+ 配置浏览器环境并在本地运行目标反爬 JS,拿到签名 / token,
6
+ 并用 js-reverse MCP 从真实出口倒推定位加密 / 签名"生成"入口。分两部分:Part1 找入口(js-reverse MCP),
7
+ Part2 补环境跑通(iv8)。当任务涉及以下时使用:iv8、补环境、脱浏览器跑 JS、js-reverse 找入口、
8
+ 本地产签名 / token、JSContext、page.load、add_resource、eventLoop.drain、指纹配置、stub 窟窿、
9
+ navigator/canvas/webgl 一致性。不得使用 Node.js vm 或外部补环境框架替代 iv8;Node.js 只可作为静态工程工具。
10
+ 本 skill 不涉及 Akamai 真实鼠标轨迹 / 行为采集式的边界或内容。
11
+ ---
12
+
13
+ > **版本基线:iv8 0.1.3 / 2026-07(社区版,已实测)。动手前先跑 `scripts/preflight.py`。**
14
+ > 所有 deploy 绑定值(bdms 版本 / aid / script id / u 数组 / golden sum)一律运行时解析,勿写死。
15
+
16
+ # iv8-env-runtime — 用 iv8 补环境脱浏览器跑反爬 JS
17
+
18
+ 用 iv8 在纯 Python 里跑目标站的反爬 / 签名 JS,本地产出签名 / token,全程无浏览器。
19
+ 两大部分:**Part1** 用 js-reverse MCP 找到真实"生成"入口;**Part2** 用 iv8 补环境把入口跑通。
20
+
21
+ ---
22
+
23
+ ## §0 能做 / 不能做红线(常驻护栏,8 条铁律)
24
+
25
+ > 违反任意一条几乎必翻车。每次动手前扫一遍。
26
+
27
+ 1. **断点用 `vdebugger;`,绝不用 `debugger;`**(原生 debugger 已被 iv8 禁用,目标常用无限 debugger 反调试)。
28
+ 2. **console 检测站:`enable_console=False` + `vconsole.log`**(`vconsole` 对目标 JS 完全不可见)。
29
+ 3. **`environment` = 画像**(JS 可观测的指纹,可含数组)/ **`config` = 引擎行为**(仅标量,**无数组**:timezone / permissions 等)。两者别混。
30
+ 4. **默认值三坑**:`location.href` 默认 `about:blank`(**几乎必配**);`canvas.fingerprint.toDataURL.png` 默认 `''`(**canvas 指纹站必配**);`navigator` 有 200+ 合理默认(**通常只配 `userAgent`**)。
31
+ 5. **社区版无真实网络栈**:真请求走 Python `requests` → `ctx.add_resource()` 注入响应 → `eventLoop.drain()` 推进,而不是指望 iv8 自己发包。
32
+ 6. **API 三态**:真实现(navigator/crypto/XHR)**别动**;stub 空壳(如 `MessageChannel` port=null)**替换**;陷阱 / 正确缺失(`process`/`_phantom`/`__webdriver_script_fn`/`StyleMedia`/`Float16Array`)**绝不补**(补了自曝)。
33
+ 7. **一致性红线**:UA ↔ userAgentData ↔ platform ↔ 时区 ↔ 语言 ↔ webgl **整套对齐**。说自己是 Mac 就别让 platform 还是 Win32。
34
+ 8. **`time_mode`**:默认 `logical`(sleep 瞬间完成);**POW / 时间差校验站用 `system`**(Date.now() 反映真实耗时)。
35
+ 9. **唯一运行底座**:目标原始 JS 只在 iv8 中执行。真实浏览器用于定位入口、采集环境事实和提供对账样本,不替代 iv8 参考运行;Node.js vm 不进入目标执行链。
36
+
37
+ ---
38
+
39
+ ## §1 前置门(P0,硬门)
40
+
41
+ **必跑 `scripts/preflight.py`。不过不得继续。**
42
+
43
+ 它做四件事:① 检测平台 / Python 版本 / 架构,装错平台或版本硬阻断并给替代路径;② 打印已安装 iv8 版本(本 skill 版本门控的**唯一真相源**,`references/version-gotchas.md` 消费它);③ 校验 `import iv8` 与 `get_defaults()` 可用;④ 打印跨平台安装结论。
44
+
45
+ 安装矩阵详见 `references/cross-platform-install.md`。速记:Windows x64 / Linux x64 → `pip install iv8`(PyPI,Py3.9–3.14);macOS 仅 Apple Silicon 实验版,**不上 PyPI**,去 GitHub Releases 下 `iv8-<ver>-cpXX-cpXX-macosx_14_0_arm64.whl` → `uv pip install ./…whl`(Py3.11–3.14 / macOS14+);Intel Mac / mac 上 Py<3.11 = 不支持。项目强制用 **uv** 管理。
46
+
47
+ > **CHECKPOINT P0**:preflight 全绿、版本已打印,才进 Part1 / Part2。**STOP** 若阻断,按它给的替代路径处理,别硬跑。
48
+
49
+ ---
50
+
51
+ ## §2 双轨全景
52
+
53
+ ```
54
+ Part1 找入口(js-reverse MCP,真浏览器) Part2 补环境跑通(iv8,纯 Python)
55
+ 真实出口 → 倒推 → 定位"生成"入口 → 分类入口类型 → 最小 environment 起跑 → 发现缺口 → 配/补 → 收割 token → 验收
56
+ ```
57
+
58
+ **运行阶段模型(P0–P4,带门):**
59
+
60
+ | 阶段 | 做什么 | 退出闸 |
61
+ |---|---|---|
62
+ | **P0** 环境就绪 | 跑 preflight | 全绿 + 版本打印 |
63
+ | **P1** 找入口 | 从真实出口倒推,定位 + 分类入口 | entry-report 填满 & 结论"已定位" |
64
+ | **P2** 起跑 + 发现缺口 | 最小 environment 零配跑,列缺口清单 | 缺口清单成形(monitor∩defaults + TypeError 栈) |
65
+ | **P3** 配 / 补 / 跑通 | 喂指纹、替 stub、网络桥接、drain、收割 | 本地算出 token |
66
+ | **P4** 验收 | parity 对账 + **服务器判决** | 服务器 200 / code=0 |
67
+
68
+ > **P1 ↔ P2 ↔ P3 可来回迭代**,不是单向瀑布。入口分类错了回 P1;缺口没配全回 P2;服务器拒了回 P3。
69
+
70
+ ---
71
+
72
+ ## §3 Part1 — 找入口(5 步骨架)
73
+
74
+ 方法论:**不是先读懂混淆代码,而是让真实代码自己跑,在出口附近观察参数从无到有的边界。**
75
+ 完整流程见 `references/part1-entry-location.md`,MCP 工具映射见 `references/part1-mcp-tool-map.md`。
76
+
77
+ 1. **明确目标字段**:字段名、所在请求 / 存储位置、真实样例(`list_network_requests` 找真实出口)。
78
+ 2. **在真实出口下断点**:XHR/fetch(`break_on_xhr`)、cookie/storage setter、或目标函数返回点(`set_breakpoint_on_text`)。
79
+ 3. **从断点向上看调用栈,只给每层定角色**:加载 / 初始化 / 触发 / **生成** / 读取 / 搬运 / 发送。别硬读混淆。
80
+ 4. **定位铁证 =「上一层没有,下一层有」**(`select_frame` + `evaluate_script(mainWorld=true)` 对比改写前输入 / 改写后输出)。**不是**"出现在调用栈里"就算。
81
+ 5. **判来源 + 最小复现**:本地生成 / 已有状态搬运 / 服务端下发 / 未确认;按入口类型(函数式 / 拦截式 / 事件式 / 状态机式 / 采集式 / 下发式)做最小复现。
82
+
83
+ **产出**:填满 `assets/entry-report-template.txt`。参考案例:拦截式见 `references/case-intercept-douyin.md`,函数式见 `references/case-function-iwencai.md`。
84
+
85
+ > **CHECKPOINT P1**:entry-report 每格有动态边界证据、结论写"已定位"。**STOP** 禁止用"可能是 / 和某 SDK 有关 / 调用栈里出现过"当结论——那些一律记"未定位"。
86
+
87
+ ---
88
+
89
+ ## §4 Part2 — 补环境 SOP(P2 → P3 → P4)
90
+
91
+ 核心认知:**补环境 = 造环境(iv8 全包)+ 配环境(你喂指纹值)+ 偶尔补漏(替 stub 窟窿)。** 手写 window/DOM 的体力活没了。
92
+
93
+ ### P2 起跑 + 发现缺口
94
+
95
+ 从 `assets/env_starter.py` 起手:最小 environment(只 `location` + `navigator.userAgent`)零配跑。
96
+
97
+ - **发现清单 = monitor ∩ defaults 交集**:`scripts/monitor_env.py`(debug 模式)列出"它读 / 调了哪些字段",`scripts/defaults_audit.py` 查这些字段的 iv8 默认是不是占位(about:blank / 空)→ **交集就是要配的**。
98
+ - **stub 窟窿 = TypeError 栈**(typeof 正常、抓不到缺失日志,一用就崩):`scripts/reproduce_stub_error.py` 复现异常栈定位。
99
+ - 判 API 三态见 `references/part2-discovery.md`;配值 / 三态原则见 `references/patching-principles.md`。
100
+
101
+ > **CHECKPOINT P2**:缺口清单成形(要配的指纹 + 要替的 stub)。**STOP** 别 grep 源码枚举字段一次补一堆——靠监控 + 报错发现,一次一处。
102
+
103
+ ### P3 配环境 + 补漏 + 跑通
104
+
105
+ 1. **喂指纹值**:`location` 全字段填真实 URL、看站配 `canvas`/`webgl`/`window.origin`、读页面 DOM 的站用 `innerHTML` 或 `page.load` 填真实 HTML。配值前先 `scripts/consistency_lint.py` 静态拒错(UA↔platform↔时区 不一致直接拦)。
106
+ 2. **替换 stub**:MessageChannel/Worker null port 等,配 `wrapNative` + `eventLoop.advance`+`drain`(core-js microtask 降级链,见 `references/version-gotchas.md` E2)。
107
+ 3. **网络桥接**:`scripts/network_bridge.py` 固化 "JS 发请求 → 暂停 → Python requests → `add_resource` 注入 → drain 推进" 握手。细节见 `references/network-and-eventloop.md`。
108
+ 4. **drain-before-read**:`scripts/run_target.py` 内联 drain 断言——**收割 token 前必须先 drain**(异步产物没排空就读会拿到 undefined/半成品)。
109
+
110
+ > **CHECKPOINT P3**:本地稳定算出 token。**STOP** 遇 iv8 专坑先版本门控查 `references/version-gotchas.md`(E1 btoa 在 0.1.3 已修**别照抄**旧版注入 / E2 MessageChannel / E4 WASM instanceof+OOM 炸弹 / E5 audio 金标准 buffer / E6 jsvmp null-safe patch / E7 字体渲染物理量→真机采集后注回 iv8)。
111
+
112
+ ### P4 验收(服务器判决是唯一真相)
113
+
114
+ - **本地 parity**:`scripts/parity_check.py` 把本地产物与真机样本**逐字符**对账(din 顺序等强校验)。
115
+ - **服务器判决**:拿本地产的 token 真发一次,**只认服务器 200 / code=0**。本地自洽不算成功。
116
+
117
+ > **CHECKPOINT P4**:服务器 200 / code=0 → 收工,别画蛇添足。
118
+ > **STOP 分流**:算出但被拒 → 回 P3 查哪个指纹没对上(parity 第一处分叉常指向自检点);403 等请求层拒 → **多半非环境**(cookie/IP/参数过期),先排除非环境因素别乱补。
119
+
120
+ ---
121
+
122
+ ## §5 references / scripts 索引表
123
+
124
+ | 文件 | 何时开 / 何时跑 |
125
+ |---|---|
126
+ | `references/iv8-api-contract.md` | 要用 iv8 任何 API 前——只准用契约里列的,别臆造 |
127
+ | `references/cross-platform-install.md` | P0,装 iv8 / 换机器 / 平台不支持时 |
128
+ | `references/version-gotchas.md` | P3 遇专坑(E1–E7);消费 preflight 打印的版本做门控 |
129
+ | `references/config-defaults-cheatsheet.md` | P2/P3 查某字段默认是否占位、environment vs config 归属 |
130
+ | `references/part1-entry-location.md` | P1 找入口的完整 8 步流程 + 来源判定 + 禁止结论 |
131
+ | `references/part1-mcp-tool-map.md` | P1 每步该调哪个 js-reverse MCP 工具 |
132
+ | `references/part2-discovery.md` | P2 判 API 三态、四手段发现要配 / 补什么 |
133
+ | `references/patching-principles.md` | P3 配值 / 替 stub 的一致性 / 最小 / 一次一处原则 |
134
+ | `references/network-and-eventloop.md` | P3 网络桥接 + eventLoop drain/advance 时序 |
135
+ | `references/trap-blacklist.md` | P2/P3 判断某缺失 API 是陷阱(别补)还是真漏补 |
136
+ | `references/case-intercept-douyin.md` | 参考拦截式入口 + 抖音 bdms 补环境实录 |
137
+ | `references/case-function-iwencai.md` | 参考函数式入口 + 爱问财补环境实录 |
138
+ | `scripts/preflight.py` | **P0 必跑**,硬门 |
139
+ | `scripts/monitor_env.py` | P2 debug 监控,列"它访问了啥"(要配的清单一半) |
140
+ | `scripts/defaults_audit.py` | P2 查字段默认占位(要配的清单另一半) |
141
+ | `scripts/consistency_lint.py` | P3 配值前静态拒错,一致性红线 |
142
+ | `scripts/run_target.py` | P2/P3 起跑目标 JS,内联 drain-before-read 断言 |
143
+ | `scripts/network_bridge.py` | P3 固化真请求 → add_resource → drain 握手 |
144
+ | `scripts/reproduce_stub_error.py` | P2 复现 stub 窟窿的 TypeError 栈 |
145
+ | `scripts/parity_check.py` | P4 本地产物 vs 真机逐字符对账 |
146
+ | `assets/env_starter.py` | P2 起跑模板(最小 environment) |
147
+ | `assets/entry-report-template.txt` | P1 产出,填满即退出 P1 |
148
+
149
+ ---
150
+
151
+ ## §6 iv8 唯一运行底座
152
+
153
+ 不要另造浏览器环境。iv8 已提供 `window`、DOM、BOM、XHR、Canvas、WebGL、Crypto、Timer 和事件循环;本 skill 只处理三类差异:
154
+
155
+ 1. **画像值不符**:通过 `JSContext(environment=..., config=...)` 配置,并用 `consistency_lint.py` 拦截自相矛盾。
156
+ 2. **已证实的 stub 空壳**:把补丁作为目标外部的 `stub_setup_js` 在原始 JS 之前注入;只实现目标实际调用的行为,函数或构造器用 `__iv8__.wrapNative` 保持原生表面,异步行为交给 `eventLoop.advance/drain`。
157
+ 3. **iv8 不具备的物理量**:在真实浏览器采集原始测量值,把它声明为环境输入后注入 iv8;最终目标 JS、生成入口和产物仍在 iv8 中运行。
158
+
159
+ 未知 API 默认保持 `undefined`。只有同时具备“真实 Chrome 确实存在、目标确实读取、iv8 当前实现不满足”三项证据时才补。不要导入通用 mock 框架,不要批量构造 window/DOM,不要把真实浏览器或其他 JavaScript 运行时当成 iv8 的替代执行链。具体判据与最小补丁结构见 `references/patching-principles.md` 和 `references/trap-blacklist.md`。
@@ -0,0 +1,23 @@
1
+ ========================================================================
2
+ P1 入口定位结论报告(模板)
3
+ 用法:逐字段填满。三条边界证据(上一层没有 / 下一层已有 / 中间结果==最终结果)
4
+ 必须同时齐备,末行才允许写「已定位」;任一字段只有猜测或调用栈痕迹 → 写「未定位」。
5
+ 说明见 references/part1-entry-location.md §7-8。
6
+ ========================================================================
7
+
8
+ 目标字段: (字段名 + 位置:URL query / header / body / cookie / storage + 真实样例值)
9
+ 真实出口: (URL / XHR.open / fetch / sendBeacon / cookie setter / storage setter / return / callback)
10
+ 直接相关 JS: (脚本 URL + 生成帧函数名;scriptId 会过期,记 URL)
11
+ 入口类型: (函数式 / 拦截式 / 事件式 / 状态机式 / 采集式 / 下发式)
12
+ 来源类型: (本地生成 / 已有状态搬运 / 服务端下发 / 未确认)
13
+ 前置状态: (触发前 JS 是否加载、init 是否完成、cookie/storage/config 是否存在)
14
+ 主动触发方式: (调函数 / 触发 XHR/fetch / 事件 / timer / 队列 / getter)
15
+ 输入参数: (this、arguments、URL、method、headers、body、config、事件对象)
16
+ 上一层没有的证据: (上一层输入里目标字段不存在的动态观察)
17
+ 下一层已有的证据: (下一层输出里目标字段已出现的动态观察)
18
+ 中间结果==最终结果证据:(哪个变量/返回值逐字符等于最终出口值)
19
+ 输出读取方式: (从 URL/header/body/cookie/storage/netLog/return/callback 的哪里读)
20
+ 对照实验: (不触发/触发/改输入/清状态/重放后的对照结果)
21
+
22
+ 结论: (已定位 / 未定位)
23
+ ========================================================================
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ env_starter.py — iv8 environment 起手模板(阶段 P2 零配起手)
5
+
6
+ 用途:
7
+ 给一个「最小可跑」的 environment 起手 dict,只填几乎必配的两项:
8
+ - location 全字段(iv8 默认 location.href 是 about:blank,几乎必须覆盖成真实页面 URL);
9
+ - navigator.userAgent(对外浏览器版本由它决定)。
10
+ canvas / webgl / DOM / screen 等一律「看站再加,别一次补全」——
11
+ P2 的做法是先零配跑、用 monitor∩defaults 交集找出真正被读到的字段,再按需补,
12
+ 过度预配反而制造不一致红线。
13
+
14
+ 用法:
15
+ from env_starter import make_environment
16
+ env = make_environment(
17
+ href="https://www.example.com/path?x=1",
18
+ user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...",
19
+ )
20
+ # 交给 scripts/consistency_lint.py 体检后再喂 iv8.JSContext(environment=env)
21
+
22
+ 本文件属于 iv8-env-runtime skill。
23
+ 交叉引用:
24
+ - 字段归属与默认值见 references/config-defaults-cheatsheet.md;
25
+ - 一致性红线(UA↔platform↔时区↔语言↔webgl)先跑 scripts/consistency_lint.py;
26
+ - canvas/webgl 等指纹值必须来自真实浏览器证据,并通过 iv8 environment/config 注入。
27
+ 说明:下方所有具体值均为「仅示例」占位,真实站点请按 P1/P2 观测到的真机值替换。
28
+ """
29
+
30
+ try: # 仅用于类型/URL 解析,缺失也不影响 make_environment 被直接改字段字典使用
31
+ from urllib.parse import urlsplit
32
+ except Exception: # noqa: BLE001
33
+ urlsplit = None
34
+
35
+
36
+ def _split_location(href):
37
+ """把一个页面 URL 拆成 iv8 location 各字段。href 是 location 里最关键的一项。"""
38
+ if urlsplit is None:
39
+ # 极简兜底:至少把 href 填上,其余留空由调用方补
40
+ return {"href": href, "origin": "", "protocol": "", "host": "",
41
+ "hostname": "", "port": "", "pathname": "", "search": "", "hash": ""}
42
+ u = urlsplit(href)
43
+ origin = "{}://{}".format(u.scheme, u.netloc) if u.scheme and u.netloc else ""
44
+ return {
45
+ "href": href,
46
+ "origin": origin,
47
+ "protocol": (u.scheme + ":") if u.scheme else "",
48
+ "host": u.netloc,
49
+ "hostname": u.hostname or "",
50
+ "port": str(u.port) if u.port else "",
51
+ "pathname": u.path or "",
52
+ "search": ("?" + u.query) if u.query else "",
53
+ "hash": ("#" + u.fragment) if u.fragment else "",
54
+ }
55
+
56
+
57
+ def make_environment(href, user_agent, language="en-US", languages=None):
58
+ """构造起手 environment。只配必需项;其余看站再加。
59
+
60
+ 参数:
61
+ href : 真实页面 URL(必配;iv8 默认 about:blank 几乎总要覆盖)。
62
+ user_agent : navigator.userAgent(必配;决定对外浏览器版本)。
63
+ language / languages : 语言,注意 language 应是 languages[0](红线,见 consistency_lint)。
64
+ """
65
+ if languages is None:
66
+ languages = [language, "en"]
67
+ return {
68
+ # ★ 必配:location 默认 about:blank,站点脚本读 location.* 时必须是真实页面
69
+ "location": _split_location(href),
70
+ # ★ 必配:navigator.userAgent 决定对外浏览器版本;其余 navigator 字段有 200+ 默认值,
71
+ # 通常只需覆盖 UA(以及和 UA 自洽的 language/languages)。
72
+ "navigator": {
73
+ "userAgent": user_agent,
74
+ "language": language,
75
+ "languages": languages,
76
+ },
77
+ # 以下为「看站再加」示例,默认注释掉——不要一次补全,过度预配会制造不一致红线:
78
+ # canvas 站点必配 canvas.fingerprint.toDataURL.png(默认 ''):
79
+ # "canvas": {"fingerprint": {"toDataURL": {"png": "<真机抓的 dataURL,仅示例,勿写死>"}}},
80
+ # webgl 指纹(须与 UA 显卡语义自洽):
81
+ # "webgl": {"vendor": "Google Inc. (NVIDIA)",
82
+ # "renderer": "ANGLE (NVIDIA, NVIDIA GeForce RTX 3060 ...)"},
83
+ # 屏幕:
84
+ # "screen": {"width": 1920, "height": 1080, "colorDepth": 24},
85
+ }
86
+
87
+
88
+ # 一个可直接参考/拷贝的示例实例(值均为占位,真实站点务必替换)。
89
+ STARTER_ENVIRONMENT_EXAMPLE = make_environment(
90
+ href="https://www.example.com/page", # 仅示例
91
+ user_agent=( # 仅示例,按真机替换
92
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
93
+ "(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
94
+ ),
95
+ )
96
+
97
+
98
+ if __name__ == "__main__":
99
+ import json
100
+ print(json.dumps(STARTER_ENVIRONMENT_EXAMPLE, ensure_ascii=False, indent=2))