Files
2026-05-19 11:30:21 +08:00

42 lines
1006 B
Markdown

# Erlang .beam 反编译脚本说明
## 功能
`decompile_beam.erl` 将 Erlang 编译后的 `.beam` 文件反编译为对应的 `.erl` 源文件。
## 用法
```bash
# 反编译单个 .beam 文件(生成的 .erl 与 .beam 同目录)
escript decompile_beam.erl path/to/module.beam
# 反编译目录下所有 .beam 文件
escript decompile_beam.erl path/to/ebin
```
## 重要限制
- **只有带 `debug_info` 编译的 .beam 才能反编译出完整源码。**
- 若编译时未加 `debug_info`,脚本会跳过并提示“缺少抽象代码块”。
编译时保留 debug_info 示例:
```erlang
compile:file("src/mymod.erl", [debug_info, report_warnings]).
```
或 rebar3 在 `rebar.config` 中:
```erlang
{erl_opts, [debug_info]}.
```
## 依赖
- 仅依赖 Erlang/OTP 标准库(`beam_lib``erl_pp``file` 等),无需额外依赖。
## 输出
- 每个 `.beam` 会在**同一目录**下生成同名的 `.erl` 文件。
- 例如:`ebin/my_app.beam``ebin/my_app.erl`