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.
Matthias
----------------------------------------------------------------------
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:
-module(hw).
-export([go/0]).
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.
{raw_abstract_v1,[{attribute,1,file,{"./hw.erl",1}},
{attribute,1,module,hw},
{attribute,2,export,[{go,0}]},
{function,4,
go,
0,
[{clause,4,
[],
[],
[{string,5,"this is my function"}]}]},
{eof,6}]}
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