erlic122

erlic122

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

Marked As Solved

lud

lud

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 · GitHub because it can generate elixir source instead of erlang. But I don’t know it as much as decompilerl.

Also Liked

al2o3cr

al2o3cr

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.

Cleidiano

Cleidiano

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 · GitHub

lud

lud

It should output an .erl file in the current working directory.

:\testproject\myproject>mix run tt.exs > holiday_role_data.erl
warning: function deps/0 is unused
  mix.exs:23

** (CompileError) mix.exs:10: undefined function deps/1 

How is your mix.exs file like? The deps({:decompilerl, github: "niahoo/decompilerl"}) is strange.

Generally you will have a deps: deps(), call in the project/0 function of the mix.exs file and dependencies defined like this:

  defp deps do
    [
      # ...
      {:decompilerl, github: "niahoo/decompilerl"}
    ]
  end

But you do not need the dependency in your project, you can just install the tool:

mix archive.install github niahoo/decompilerl
# or
mix archive.install github michalmuskala/decompile

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement