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

1006 B

Erlang .beam 反编译脚本说明

功能

decompile_beam.erl 将 Erlang 编译后的 .beam 文件反编译为对应的 .erl 源文件。

用法

# 反编译单个 .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 示例:

compile:file("src/mymod.erl", [debug_info, report_warnings]).

或 rebar3 在 rebar.config 中:

{erl_opts, [debug_info]}.

依赖

  • 仅依赖 Erlang/OTP 标准库(beam_liberl_ppfile 等),无需额外依赖。

输出

  • 每个 .beam 会在同一目录下生成同名的 .erl 文件。
  • 例如:ebin/my_app.beamebin/my_app.erl