Need help decompiling .beam file

Hi, I’m new to this ERLANG and BEAM language, I’m looking for a person with experience in Erlang, I want to know how I can decompile and compile a Beam file from my server, I know very little about that type of file or how I can edit it, when opening the file I find this at the beginning FOR1 can be a key piece, more information to the intern, I attach the file in case you need to see it, thank you very much in advance Payment for the service

File .Beam
https://github.com/granados12/decompile/blob/main/holiday_role_data4.beam?raw=true

The BEAM includes tooling to do part of this, :beam_disasm.

{:ok, {{_, 200, _}, headers, body_charlist}} = :httpc.request('https://github.com/granados12/decompile/blob/main/holiday_role_data4.beam?raw=true')

body = :binary.list_to_bin(body_charlist)

:beam_disasm.file(body)

This produces output like (you’ll want to make sure to use IO.inspect(limit: :infinity) to prevent cutting off terms):

{:beam_file, :holiday_role_data,
 [
   {:all_son, 0, 12},
   {:all_son2, 0, 14},
   {:bid_son, 1, 21},
   {:get, 1, 853},
   {:get_const, 1, 1259},
   {:get_open, 1, 59},
   {:list_open_son, 1, 4},
   {:list_open_total, 0, 2},
   {:list_son, 1, 16},
   {:list_total, 0, 10},
   {:main_ico, 1, 1257},
   {:module_info, 0, 1265},
   {:module_info, 1, 1267},
   {:open_ico, 1, 1255}
 ],
 [
   lager_records: [
     condition: [:label, :op, :val, :msg],
     holiday: [:camp_id, :total_id, :bid, :tbid, :cli_type, :cli_type_name, :start_time, :end_time,
      :condition, :type, :title, :title2, :main_ico, :ico, :type_ico, :top_banner, :rule_str,
      :time_str, :bottom_alert, :sort_val, :reward_title, :aim_title, :reward, :item_effect,
      :mail_subject, :mail_content, :cli_reward, :panel_type, :open_day, :open_day_min,
      :open_day_max, :merge_day, :process_show_reward, :platform_id, :platform_exclude_id,
      :hide_srv_ids, :channel_ban],
     holiday_total: [:id, :name, :icon_id, :start_time, :end_time, :status, :open_day, :merge_day,
      :is_show, :type]
   ],
   vsn: [320956466309601905319104183717896391347]
 ],
 [
   options: [
     :error_summary,
     {:hipe, [:o3]},
     :debug_info,
     {:i, 'inc'},
     {:outdir, 'ebin'},
     {:parse_transform, :lager_transform},
     {:d, :disable_auth},
     {:d, :enable_gm_cmd},
     {:d, :debug},
     {:d, :data_debug}
   ],
   version: '7.0.4',
   source: '/elora/server/src/data/holiday_role_data.erl'
 ],
 [
   {:function, :list_open_total, 0, 2,
    [
      {:label, 1},
      {:line, 1},
      {:func_info, {:atom, :holiday_role_data}, {:atom, :list_open_total}, 0},
      {:label, 2},
      {:allocate_zero, 1, 0},
      {:move, {:literal, "HĐ Gộp SV"}, {:x, 0}},
      {:line, 2},
      {:call_ext, 1, {:extfunc, :lang, :get, 1}},
      {:move, {:x, 0}, {:y, 0}},
      {:move, {:literal, "HĐ Mở SV"}, {:x, 0}},
      {:line, 3},
      {:call_ext, 1, {:extfunc, :lang, :get, 1}},
      {:test_heap, 28, 1},
      {:put_tuple, 11, {:x, 1}},
      {:put, {:atom, :holiday_total}},
      {:put, {:integer, 103}},
      {:put, {:x, 0}},
      {:put, {:integer, 0}},
      {:put, {:literal, {:open_day, 1}}},
      {:put, {:literal, {:open_day, 56, 86399}}},
      {:put, {:integer, 1}},
      {:put, {:integer, 0}},
      {:put, {:integer, 0}},
      {:put, {:integer, 1}},
      {:put, {:integer, 1}},
      {:put_list, {:x, 1}, nil, {:x, 1}},
      {:put_tuple, 11, {:x, 2}},
      {:put, {:atom, :holiday_total}},
      {:put, {:integer, 104}},
      {:put, {:y, 0}},
      {:put, {:integer, 0}},
      {:put, {:literal, {:merge_day, 1}}},

As for editing this BEAM file, that’s not something that’s normally done - BEAM files are written by the compiler so if you want to change them you change the Erlang etc code and recompile. According to the metadata in that file, that’s in src/data/holiday_role_data.erl.

3 Likes

Hello, thank you very much for answering, I really didn’t know how to do it, in the same way there are several files, but with this example I will see if I can decompile them, the only thing I want with the files is to decompile them, edit the texts that are in the Vietnamese language, translate them into English and ready to compile them again, can I talk to you in private for a moment?

I know nothing about Beam file format, but maybe you can get some inspiration in how to approach the problem inspect this repo GitHub - michalmuskala/decompile

2 Likes

This solution helped me a lot, thanks man, now how do I save it in a file to be able to edit it, or convert it into a .txt or .erl, edit it and compile it again, as I say, it is to only edit the texts, translate them into English and return them to compile

Hola erlic122, bienvenido :rocket:

Have you tried asking in the Erlang forums?

1 Like

Hello, thank you very much for the welcome, if I made an account 3 days ago but it has not been validated and I cannot ask a question without being registered, then I have to use this forum since they have not verified my account registration

1 Like

I have been able to decompile it in this way but I have not been able to recompile it in .BEAM file any other advice?

Given your source file is generated from decompilation, you can open an erlang shell (erl command) and compile it by hand:

erl
Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit]

Eshell V12.2  (abort with ^G)
1> c("holiday_role_data.erl").
{ok,holiday_role_data}
1 Like

I get an error, it doesn’t seem to decompile correctly, is there any other way to decompile the .beam files or convert them from beam to .erl

PM me your email address and I will send you the .erl file. It is too large for tools like pastebin.

1 Like

Ok perfect thank you very much, could you explain or tell me what are the commands to decompress it or convert it to .erl? is that there are several files and I want to know so I can decompile them all,

Gmail

I sent the file, please hide your address from public sight :slight_smile:

1 Like

Thank you very much man, very grateful to you

To get the source I created a base mix project:

mix new myproject

In mix.exs deps() function I added this dependency:

{:decompilerl, github: "niahoo/decompilerl"}

Then I renamed your beam file to holiday_role_data.beam (removed the “4”) because the module inside is holiday_role_data and must match the file name.

The beam file is in the root of the project directory.

Then I created a tt.exs file with this content:

Code.append_path(File.cwd!())
Decompilerl.decompile(:holiday_role_data)
System.halt()

And then run this file with mix run tt.exs > holiday_role_data.erl

Note that you must then edit the file to remove the text “Retrieving code for holiday_role_data”.

It may be possible to have better results with GitHub - michalmuskala/decompile because it can generate elixir source instead of erlang. But I don’t know it as much as decompilerl.

1 Like

Thank you very much, very grateful, it works perfectly, but now with some files I get an error, I would like to know why? and how to fix it to be able to decompile

this is the error it gives me


** (MatchError) no match of right hand side value: {:error, :beam_lib, {:key_missing_or_invalid, <<70, 79, 82, 49, 0, 1, 52, 148, 66, 69, 65, 77, 65, 116, 111, 109, 0, 0, 4, 172, 0, 0, 0, 72, 11, 99, 104, 97, 114, 103, 101, 95, 100, 97, 116, 97, 4, 108, 105, 115, 116, 5, 108, 105, 115, ...>>, :abstract_code}}
     (decompilerl 0.0.1) lib/decompilerl.ex:25: Decompilerl.do_decompile/1
     (decompilerl 0.0.1) lib/decompilerl.ex:5: Decompilerl.decompile/2
     tt.exs:2: (file)
     (elixir 1.12.2) lib/code.ex:1261: Code.require_file/2

this is the file
https://github.com/granados12/decompile/blob/main/charge_data.beam?raw=true

There is a thread which is active in erlang forums. You can take a look at it.

1 Like

Ok thank you very much, I will see if there is what I need

No, it didn’t work for me, @lud solution does work, for most files, but one or another doesn’t work, it gives the error message I mentioned

1 Like

That kind of chunk is optional in a BEAM file - it’s not usually included for “production” builds.