附录 A: 逆向工程方法论与工具命令参考
本文档记录了对
atomcode.bin.bak(v4.25.3) 进行逆向分析时使用的所有工具与命令。 日期: 2026-06-25
1. 静态分析工具链
1.1 strings — 提取可打印字符串
bash
# 基础用法:提取所有可打印字符串
strings atomcode.bin.bak > strings_output.txt
# 按长度过滤(跳过短噪声串)
strings -n 8 atomcode.bin.bak > strings_filtered.txt
# 提取特定模式的字符串(联合多个模式)
strings atomcode.bin.bak | grep -E "struct|impl|fn |trait|enum" | sort -u > rust_symbols.txt
# 提取 API 端点
strings atomcode.bin.bak | grep -E "^/" | sort -u > api_endpoints.txt
# 提取 URL
strings atomcode.bin.bak | grep -E "https?://" | sort -u > urls.txt
# 提取结构体定义(逆向 Rust)
strings atomcode.bin.bak | grep -i "struct.*with.*element" > structs.txt
# 提取环境变量
strings atomcode.bin.bak | grep -E "ATOMCODE_" | sort -u > env_vars.txt
# 提取错误消息
strings atomcode.bin.bak | grep -iE "failed|error|denied|timeout" > errors.txt
# 提取 crate 路径
strings atomcode.bin.bak | grep -E "crates/atomcode" | sort -u > crate_paths.txt1.2 objdump — 反汇编与分析
bash
# 查看 ELF 头部信息
objdump -f atomcode.bin.bak
# 查看所有段(Section Headers)
objdump -h atomcode.bin.bak
# 查看动态符号表
objdump -T atomcode.bin.bak 2>/dev/null | head -50
# 查看重定位条目
objdump -r atomcode.bin.bak 2>/dev/null | head -100
# 反汇编 .text 段(指定函数)
objdump -d --disassemble=<symbol> atomcode.bin.bak
# 反汇编指定段(由于 stripped,用地址范围)
objdump -d --start-address=0x10000 --stop-address=0x11000 atomcode.bin.bak
# 查看 rustc 生成的 demangled 符号
objdump -d atomcode.bin.bak | rustfilt | head -2001.3 readelf — ELF 结构分析
bash
# 查看 ELF 头
readelf -h atomcode.bin.bak
# 查看程序头(加载段)
readelf -l atomcode.bin.bak
# 查看所有段详情
readelf -S atomcode.bin.bak
# 查看动态段
readelf -d atomcode.bin.bak
# 查看符号表(如果有的话)
readelf -s atomcode.bin.bak 2>/dev/null | head -100
# 查看重定位
readelf -r atomcode.bin.bak
# 查看 NOTE 段
readelf -n atomcode.bin.bak
# 查看 GNU 版本信息
readelf -V atomcode.bin.bak1.4 nm — 符号表
bash
# 列出动态符号(即使 stripped 也有 .dynsym)
nm -D atomcode.bin.bak 2>/dev/null | head -100
# 统计符号类型分布
nm -D atomcode.bin.bak 2>/dev/null | awk '{print $2}' | sort | uniq -c | sort -rn1.5 file — 二进制类型识别
bash
file atomcode.bin.bak
# 输出: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
# dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
# for GNU/Linux 2.0.0, stripped1.6 xxd / hexdump — 十六进制分析
bash
# 查看文件头(ELF magic)
xxd -l 64 atomcode.bin.bak
# 查看特定偏移处的字节
xxd -s 0x1000 -l 256 atomcode.bin.bak
# 查看 Go/Rust 的特定二进制模式
xxd atomcode.bin.bak | grep -i "deadbeef"
# 查看字符串附近的原始字节
strings -t x atomcode.bin.bak | grep "coding_plan" | head -51.7 size — 段大小统计
bash
# 查看各段大小
size atomcode.bin.bak
# 更详细的段大小报告
size -A atomcode.bin.bak1.8 strip 信息
bash
# 检查是否 stripped
file atomcode.bin.bak
# "stripped" 表示所有 .symtab 已移除
# 但 .dynsym 仍然保留(用于动态链接)
# 查看保留的动态符号
nm -D atomcode.bin.bak | wc -l
# 通常 stripped 的 Rust 二进制仍有 2000+ 个动态符号2. 逆向分析方法论
2.1 静态字符串挖掘流程
Phase 1: 粗收
strings -n 8 bin > all_strings.txt
→ 获取所有可打印字符串的完整清单
Phase 2: 分类
grep -E "^/" → API 端点
grep -E "https?://" → 远程 URL
grep -E "ATOMCODE_" → 环境变量
grep -E "struct.*with"→ Rust 结构体
grep -iE "error|fail" → 错误消息
Phase 3: 交叉引用
strings -t x bin | grep "需要搜索的字符串"
→ 找到字符串在文件中的偏移
→ 用 xxd 查看周围上下文
Phase 4: 关联分析
已知字符串 → 推断 crate 路径
已知结构体 → 推断 enum 变体
已知 URL → 推断 API 用途2.2 结构体推断技术
bash
# 搜索 "struct X with N element" 模式
# Rust 编译时保留的调试字符串格式:
# "/crates/atomcode-daemon/src/api_codingplan.rs"
# "struct CodingPlanSetupRequest with 1 element"
strings atomcode.bin.bak | grep "struct.*with.*element" | \
sed 's/.*struct \([^ ]*\) with \([0-9]*\) element.*/\1 (\2 fields)/' | \
sort > identified_structs.txt
# 统计结构体字段数分布
strings atomcode.bin.bak | grep "struct.*with.*element" | \
grep -oP 'with \K[0-9]+' | sort -n | uniq -c | sort -rn2.3 代码路径推断
bash
# 从错误消息反推源文件路径
strings atomcode.bin.bak | grep "crates/atomcode" | sort -u
# 推断函数名(格式: "crate_name::module_name::fn_name")
strings atomcode.bin.bak | grep "::" | grep -v "https\?://" | sort -u3. 运行时分析工具
3.1 Daemon HTTP API 探测
bash
# 健康检查
curl -s http://localhost:13456/health | jq .
# 认证状态
curl -s http://localhost:13456/auth/status | jq .
# 获取模型列表(需要 Bearer token)
curl -s -H "Authorization: Bearer $(cat ~/.atomcode/auth.toml | grep access_token | cut -d'"' -f2)" \
http://localhost:13456/models | jq .
# SSE 流式聊天
curl -N -X POST http://localhost:13456/chat \
-H "Authorization: Bearer $(cat ~/.atomcode/auth.toml | grep access_token | cut -d'"' -f2)" \
-H "Content-Type: application/json" \
-d '{"session_id":"test-001","message":"你好"}' 2>&1 | head -100
# 非流式聊天
curl -s -X POST http://localhost:13456/chat \
-H "Authorization: Bearer $(cat ~/.atomcode/auth.toml | grep access_token | cut -d'"' -f2)" \
-H "Content-Type: application/json" \
-d '{"session_id":"test-002","message":"回复一句话:ok"}' | jq .
# 获取提供商列表
curl -s -H "Authorization: Bearer $TOKEN" \
http://localhost:13456/providers | jq .
# 获取技能列表
curl -s -H "Authorization: Bearer $TOKEN" \
http://localhost:13456/skills | jq .3.2 WebUI SPA 分析
bash
# 从 WebUI 提取嵌入式 JS
curl -s http://localhost:13457/assets/index-*.js > spa.js
# 解析 JS 中引用的 API 端点
grep -oP '"/[a-z]+/[a-z_-]+"' spa.js | sort -u
# 查找认证函数
grep -oP 'function \w+' spa.js | sort -u
# 查找 React/Preact 组件
grep -oP '(function|const) \w+\(.*\{' spa.js | head -1003.3 SSE 事件抓取
bash
# 使用 curl 捕获完整 SSE 流
curl -N -X POST http://localhost:13456/chat \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"session_id":"capture-001","message":"写一个hello world"}' \
> sse_capture.txt 2>&1
# 使用 tee 同时查看和保存
curl -N ... | tee sse_live.txt
# 使用 python httpx 更精细的控制
python3 -c "
import httpx, json
r = httpx.post('http://localhost:13456/chat',
headers={'Authorization': 'Bearer $TOKEN'},
json={'session_id':'py-001','message':'hi'},
timeout=30)
for line in r.text.split('\n'):
if line.startswith('data: '):
print(json.dumps(json.loads(line[6:]), indent=2, ensure_ascii=False))
"4. 辅助工具
4.1 JSON 处理
bash
# 从 auth.toml 提取 token
TOKEN=$(python3 -c "
import tomllib
with open('$HOME/.atomcode/auth.toml','rb') as f:
print(tomllib.load(f)['access_token'])
")
# 格式化 SSE 输出
curl -s -N ... | while read line; do
if [[ "$line" == data:* ]]; then
echo "$line" | sed 's/^data: //' | jq . 2>/dev/null || echo "$line"
fi
done4.2 二进制比较
bash
# 比较两个版本的字符串差异
diff <(strings v4.25.2.bin | sort) <(strings v4.25.3.bin | sort) > version_diff.txt
# 统计新增/删除的字符串
grep "^>" version_diff.txt | wc -l # 新增
grep "^<" version_diff.txt | wc -l # 删除4.3 目录监控
bash
# 监控 daemon 运行时文件变更
inotifywait -m -r ~/.atomcode/ --format '%e %f' 2>/dev/null
# 监控会话文件创建
inotifywait -m ~/.atomcode/sessions/ --format '%T %f' --timefmt '%H:%M:%S'5. 完整分析工作流
[Static Analysis Phase]
│
▼
1. file → 确认二进制类型 (ELF 64-bit, stripped)
2. strings → 提取所有可读信息 (API, URL, 结构体, 错误)
3. grep/sort/uniq → 分类整理
4. readelf → 获取 ELF 结构信息 (段、符号、重定位)
│
▼
[Dynamic Analysis Phase]
│
▼
5. 启动 daemon → 观察文件创建 (sessions, datalog)
6. curl /chat → 捕获 SSE 协议格式
7. curl /health → 确认运行状态
8. datalog 分析 → 了解 LLM 调用详情
│
▼
[Documentation Phase]
│
▼
9. 编写 Markdown 报告 (每轮 3 分钟)
10. 更新进度追踪
11. git add + commit📅 最后更新: 2026-06-25