Decompile beam to erlang

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Sat Jan 28 15:03:41 CET 2006

Matthias Lang wrote:
> 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.

Here's a pretty generic way to convert abstract
forms to .erl:


transform(BeamFName, ErlFName) ->
  case beam_lib:chunks(BeamFName, [abstract_code]) of
    {ok, {_, [{abstract_code, {raw_abstract_v1,Forms}}]}} ->
      Src = 
        {ok, Fd} = file:open(ErlFName, [write]),
        io:fwrite(Fd, "~s~n", [Src]),
    Error ->

(It _did_ take exactly 15 minutes, 
- just trying to hack it from memory
- reading the docs, waiting two minutes for 
  the webserver to respond
- fetching the docs from local disk
- reading some more, giving up and then 
  searching my mail archive for an old 
  mail to Luke Gorrie, where I had included
  the above code
- Copy-paste, compiling, running and 
  verifying the results... :)


More information about the erlang-questions mailing list