Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Ive lost/deleted/whatever the .erl files for my project, can I somehow recreate it from the .beam files?

0
10 Posted

Ive lost/deleted/whatever the .erl files for my project, can I somehow recreate it from the .beam files?

0

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. The syntax_tools package from the jungerl can be used to do most of the hard work. 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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.