Decompile beam to erlang

Matthias Lang matthias@REDACTED
Sat Jan 28 09:02:55 CET 2006

 > Is there any way i can retrive the erlang files beam files.

This question seems to come up every so often. Figured I'd write an
answer to put into the FAQ next time I update it. Improvements welcome.



Q: Can I re-create .erl files using just the .beam files?

A: _If_ the code was compiled with the debug_info flag,
   then the .beam file contains a 'partially compiled' 
   representation of the source---basically the parse tree. 
   Here is a simple module:


     go() when true ->
       "this is my function".

   and the corresponding abstract code:

     3> {ok, {hw, [{abstract_code, Abs}]}} =  beam_lib:chunks("hw.beam", [abstract_code]), Abs.
                                     [{string,5,"this is my function"}]}]},

   Writing a decompiler which can turn the above example back to source
   is a fifteen minute job. Writing a decompiler which handles more
   complex Erlang code is more time consuming, but not much harder.

   If the abstract code is _not_ present in the beam file, the problem
   gets much harder. It is possible to study the remaining information
   and draw some conclusions about what the original .erl file might
   have looked like, for instance which functions were exported. But
   a lot of other important information, such as variable names, is
   not present. In general, recreating the source code from a beam
   file without abstract code is not practical.


More information about the erlang-questions mailing list