Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompiling OCaml byte code files

I am working on Ocaml and I've some binaries that I need to figure out. The closest I've come to is converting OCaml byte code to C compiled code using ocamlcc.

I don't wish to reverse engineer the C-code unless and until I know for sure that I won't be able to decompile OCaml code.

Question: Are there any traditional ways to decompile ML code for OCaml specifically?

(Apologies if the question is abstract.)

like image 506
p0lAris Avatar asked Mar 03 '13 08:03

p0lAris


2 Answers

You can also use dumpobj from the tools directory of the distribution. It is installed on my Ubuntu linux under the name ocamldumpobj, and will print the instructions contained in a bytecode file, in a format like:

...
131214  APPLY1 
131215  PUSHCONST1 
131216  LTINT 
131217  BRANCHIF 131225
131219  ACC2 
131220  BRANCHIFNOT 131225
131222  ACC3 
...

You have to learn about OCaml bytecode to go further. There is no tool to go from bytecode to source files, as the bytecode does not contain enough information for that.

like image 74
Fabrice Le Fessant Avatar answered Oct 28 '22 23:10

Fabrice Le Fessant


Have you tried to print the bytecode or the lambda code ? You can use the -dlambda option or -dinstr of OCaml.

There is also a really good project for binary printer: ocamlpp. Maybe you should take a look.

like image 24
Çağdaş Bozman Avatar answered Oct 28 '22 23:10

Çağdaş Bozman