11

What tools produce C code that does not produce errors when you try to recompile it again? Can Hex-Rays decompiler convert everything to project files in a single folder and just compile it?

Uwe Plonus
  • 343
  • 2
  • 8
user8005
  • 151
  • 1
  • 3
  • 1
    Regarding the limitations of machine-code decompilation, see this answer: http://reverseengineering.stackexchange.com/questions/311/why-are-machine-code-decompilers-less-capable-than-for-example-those-for-the-clr/312#312 – Rolf Rolles Aug 09 '13 at 22:02
  • 1
    There have been a long story already on this topic as SO. Better to look through: http://stackoverflow.com/questions/273145/is-it-possible-to-decompile-a-windows-exe-or-at-least-view-the-assembly – T.Todua Jan 17 '17 at 11:28

2 Answers2

5

The primary purpose of decompilation is not to produce code that is compiled back with no errors, but rather recover logical flow of a binary. Hex-Ras Decompiler comes with its own set of limitation noted in Hex-Rays Decompiler Manual, to mention few:

Below are the most important limitations of our decompilers (all processors):
     * exception handling is not supported
     * type recovery is not performed
     * global program analysis is not performed
PSS
  • 3,088
  • 1
  • 21
  • 35
  • 1
    My question was: Is there any decompiler that produces code that can be recompiled easily? – user8005 Aug 09 '13 at 15:16
  • @user8005: Your question is and I quote: "...does not produce errors when your try to compile it"... There is no tools like that. – PSS Aug 09 '13 at 15:18
  • When the source is C# and not C, ILSpy works great btw... – user8005 Aug 09 '13 at 15:34
  • 3
    @user8005: sure...However, your question is about C...not C#. – PSS Aug 09 '13 at 15:38
  • 1
    In fact, it would be trivial to produce cleanly compiling C code that simply inlines any questionable assembly code that it can't understand. As PSS points out, recompilation is not the point of decompilation. – David Hoelzer Aug 13 '13 at 10:56
1

Yes you can recompile C but the decompilation has be be manual. As far as I know there is no automatical tool that provide Recompilable C from assembly.

ddisasm is a tool to make recompiling asm from a binary file.

A good starts should be to:

  1. Disassemble your program to assembly language with ddisasm.
  2. Use ldd tools to list libraries from the old binary
  3. Recompile it with gcc/g++ makefile with linked libraries
  4. Rewrite a function from assembly language to C.

And back to the step 2 again and again until your program is enough decompiled for you.

Note that ddisasm is really slow: it requires around 150 GB of swap / ram to disassemble a 100 MB file.