I have Erlang application's beam files which I want to decompile.

Application is Compiled and build with 'debug_info' options. here is snippet of emake file to which is used to build application :

{"apps/my_app/src/*",   [debug_info, nowarn_export_all, {outdir, "apps/my_app/ebin"},{pa, "deps"},{parse_transform, lager_transform}, {parse_transform, events_transform}]}.

I have tried function from beam_lib module but getting following Error :

1>{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(abc,[abstract_code]).
** exception error: no match of right hand side value {error,beam_lib,{not_a_beam_file,'abc.beam'}}

I have also tried solution mentioned in following post Decompile erlang .beam files compiled without debug_info but Its not working for me. I'm getting following error :

1> file:write_file("/tmp/my_module_disasm", io_lib:fwrite("~p.\n", [beam_disasm:file(abc)])).

/tmp/my_module_disasm file contains :


Anyone have Idea ?

1 Answer 1


Have you tried using recon:source/1? I think it does exactly what you need. If you don't want to use it, at least you can get inspiration from its source code:

-spec source(module()) -> iolist().
source(Module) ->
    Path = code:which(Module),
    {ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Path, [abstract_code]),
  • I had already tried it, you can see it in code snippets in post. Commented Oct 31, 2017 at 3:11
  • Looks like your module (abc) is not compiled. What does code:which(abc). return? Commented Nov 1, 2017 at 21:10
  • I have taken backup from live node. So I don’t think so it is not compiled. And code:which(abc) is returning absolute path of beam file. Commented Nov 2, 2017 at 6:02
  • Actually, on closer look, the error you're seeing comes from here, which means your file doesn't start with something like FOR1____BEAM (i.e. something that matches <<"FOR1", _Size:32, "BEAM">>. Out of curiosity, can you show me the first 12 bytes of your abc.beam file? Commented Nov 2, 2017 at 12:48
  • here it is : <<69,82,76,50,62,12,178,214,62,207,41,11>> Or in printable format <<"ERL2>\f\262\326>\317)\v">>. Commented Nov 2, 2017 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.