30

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?

Tim Farley
  • 11,720
  • 4
  • 29
  • 30
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • Do you have the name of the program that decompiled the Delphi application to C source psuedo code? I want to look at how an old 1999 program implemented an algorithm. I cannot run the application to determine behavior because there is a resource leak in the graphics handling and I have to reboot about ten minutes of using the application. – AMissico May 20 '10 at 19:29
  • @AMissico: According to the email, it was made with IDA Pro, with a plugin called "Hex Rays Decompiler." – Mason Wheeler May 20 '10 at 20:27
  • Thank you for replying. I figured it was Hex-Rays Decompiler. The only thing I found to do what you described. – AMissico May 20 '10 at 22:26

4 Answers4

13

You can use IDR it is a great program to decompile Delphi, it is updated to the current Delphi versions and it has a lot of features.

Kenly
  • 24,317
  • 7
  • 44
  • 60
Hanan
  • 1,169
  • 3
  • 23
  • 40
  • It appears that IDR only works up to D2009 (with theoretical D2010 support but the context data archive for it is password protected) and has no support for XE or later, or for actually decompiling the code back to Pascal. – Mason Wheeler Nov 09 '12 at 01:34
  • @MasonWheeler The D2010 is now free without password protection. – Hanan Jun 11 '14 at 11:25
  • 1
    The IDR decompiler doesn't seem to support 64bit based software packages. – Ben Feb 04 '23 at 16:20
12

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).

Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114
  • 2
    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 Dec 03 '08 at 11:22
  • @mj2008 Does anyone know more about it? I have a Delphi 4/5 project, this might be "early days" in today's view :-) – Daniel Alder Aug 21 '16 at 16:49
  • Delphi uses different function call semantics (not __stdcall). In a test with retdec.com it "forgot" to keep the return values and didn't properly detect function start and endings which made the result unusable – Daniel Alder Nov 11 '16 at 13:12
  • @DanielAlder It's been a while but IIRC the calling convention is specific to the compiler backend, not language - as such, you'll see the same calling convention used in Borland's C compilers. – Vladimir Panteleev Nov 11 '16 at 14:25
7

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
  • 4,104
  • 2
  • 29
  • 45
3

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
  • 5,176
  • 6
  • 65
  • 87
  • 1
    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 Dec 03 '08 at 17:43
  • 8
    Tip: If you think it is easy, then start implementing it yourself. – Jim McKeeth Dec 08 '08 at 20:51
  • 3
    Mason: did you do that test on code with optimization on? – Marco van de Voort Mar 11 '11 at 20:41