views:

5577

answers:

3

Someone just sent me a decompile of a program into C. It was a very good decompile, producing nice, mostly readabe C code (if you overlook the fact that none of the variables or functions had a human-readable name) that mostly looked like it would actually compile.

There was one big problem, though. I happen to know that the program he was decompiling was written in Delphi, which is full of concepts that are difficult to translate into C. But I was really impressed by the decompiler's output, and it made me wonder. Is there anything that can do that for Delphi?

The best decompiling tool I've seen for Delphi is DeDe. It can do a lot of things, but it doesn't even try to produce Object Pascal code as its output, and it hasn't been updated since Delphi 6. Is there anything better out there?

+6  A: 

I don't think there are any machine code decompilers that produce Pascal code. Most "Delphi decompilers" parse form and RTTI data, but do not actually decompile the machine code. I can only recommend using something like DeDe (or similar software) to extract symbol information in combination with a C decompiler, then translate the decompiled C code to Delphi (there are many source code converters out there).

CyberShadow
FWIW, there was, in the early days of Delphi, a full decompiler. I've not seen or heard of it for many years though.
mj2008
+1  A: 

Here's a list : http://delphi.about.com/od/devutilities/a/decompiling_3.htm (and this page mentions some more : http://www.program-transformation.org/Transform/DelphiDecompilers )

I've used DeDe on occasion, but it's not really all that powerfull, and it's not up-to-date with current Delphi versions (latest version it supports is Delphi 7 I believe)

PatrickvL
+2  A: 

Languages like Delphi, C and C++ Compile to processor-native machine code, and the output executables have little or no metadata in them. This is in contrast with Java or .Net, which compile to object-oriented platform-independent bytecode, which retains the names of methods, method parameters, classes and namespaces, and other metadata.

So there is a lot less useful decompiling that can be done on Delphi or C code. However, Delphi typically has embedded form data for any form in the project (generated by the $R *.dfm line), and it also has metadata on all published properties, so a Delphi-specific tool would be able to extract this information.

Anthony
Even if it's not reflection-rich managed code, it's not very difficult to read the ASM that Delphi produces and convert it in my head back to Object Pascal code. I do a lot of debugging at that level. All you lose is the names, and you can infer them from context most of the time.
Mason Wheeler
Tip: If you think it is easy, then start implementing it yourself.
Jim McKeeth