# Decompile BEAM files to Elixir source code

**URL:** <https://forum.elixirforum.com/t/decompile-beam-files-to-elixir-source-code/14081>\
**Category:** Questions\
**Tags:** beam, ast\
**Created:** [May 7, 2018, 2:44pm UTC](https://forum.elixirforum.com/t/decompile-beam-files-to-elixir-source-code/14081 "2018-05-07T14:44:10Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Marcus](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/marcus/32/24640_2.png) [@Marcus](https://forum.elixirforum.com/u/Marcus)\
**Post date:** [May 28, 2020, 7:46pm UTC](https://forum.elixirforum.com/t/decompile-beam-files-to-elixir-source-code/14081/8 "2020-05-28T19:46:45Z")

</div>

I have also done some experiments with the BEAM file. See the little [beam\_file](https://github.com/hrzndhrn/beam_file) project.

With `BeamFile` you can create byte, erl, and elixir-code (with the limitation discussed here) from the beam file.

Example:

```elixir
defmodule Example.Math do
  @moduledoc "Math is Fun"

  def add(number_a, number_b), do: number_a + number_b

  def odd_or_even(a) do
    if rem(a, 2) == 0 do
      :even
    else
      :odd
    end
  end
end

```

```elixir
iex> {:ok, code} = BeamFile.elixir_code(Example.Math)
iex> IO.puts(code)
defmodule Elixir.Example.Math do
  @moduledoc """
  Math is Fun
  """

  def add(number_a, number_b) do
    :erlang.+(number_a, number_b)
  end

  def odd_or_even(a) do
    case(:erlang.==(:erlang.rem(a, 2), 0)) do
      false ->
        :odd

      true ->
        :even
    end
  end
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/decompile-beam-files-to-elixir-source-code/14081)._
