Re fp runtime

From dslsdzc/rev-skills · View interactive version

Re fp runtime is an AI agent skill from the GitHub repository dslsdzc/rev-skills. 函数式语言运行时逆向(Haskell/OCaml):闭包/堆对象模型、调用约定、数据流优先策略。 触发词:Haskell逆向、OCaml逆向、GHC RTS、thunk、STG、OCaml runtime、闭包、函数式产物。

How to use this skill

Skill file

函数式运行时逆向(Haskell / OCaml)

何时使用 / 何时不用

工具准备

readelf / llvm-nm(符号分析)

ghc 工具链(Haskell 侧,可选)

ocamlobjinfo / ocamlopt(OCaml 侧,可选)

Ghidra / IDA(反编译底座)

file / xxd / Python struct(字节级核对)

操作步骤

按顺序执行;逆向着重数据流而非控制流(函数式产物控制流被打散,见坑 4)。每步产物存档(路径 + sha256,见 [[re-triage]])。

  1. 运行时识别:

```sh

readelf -s sample | grep -iE 'ghc|stg_|RTS|HsMain|_closure|_info' | head # GHC 特征

readelf -s sample | grep -iE 'caml_' | head # OCaml 特征

file sample # 字节码产物判别(脚本头)

```

  1. 闭包与堆对象:
  1. 调用约定:
  1. 分析策略(数据流优先):

```

构造器 C1 (tag 0, 2 字段) ← 分配点 A (caml_alloc2 / info 表)

字段0 ← 函数参数/常量(数据来源)

字段1 ← 字符串池引用

使用点: tag 比较 → 分支 B(业务逻辑)

```

  1. 字节码产物(OCaml 特有):

```sh

head -c 64 sample | xxd # #!...ocamlrun 脚本头 + 魔数 T/C + 长度

ocamlobjinfo sample # 直接解析字节码可执行文件(导入单位/CRC)

```

跨域联合

常见坑与陷阱

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.