140

I have a program in which I've lost the C++ source code. Are there any good C++ decompilers out there?

I've already ran across Boomerang.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Bryan Denny
  • 27,363
  • 32
  • 109
  • 125

5 Answers5

101

You can use IDA Pro by Hex-Rays. You will usually not get good C++ out of a binary unless you compiled in debugging information. Prepare to spend a lot of manual labor reversing the code.

If you didn't strip the binaries there is some hope as IDA Pro can produce C-alike code for you to work with. Usually it is very rough though, at least when I used it a couple of years ago.

David Holm
  • 17,522
  • 8
  • 47
  • 47
  • 35
    To clarify, IDA will only give the disassembly. There's an add-on to it called Hex-Rays that will decompile the rest of the way into C/C++ source, to the extent that's possible. – davenpcj May 05 '12 at 12:55
  • 2
    To my reading of the docs, hex-rays only outputs C like pseudo-code. Not that that makes it useless for decompilling C++, you just need to know a bit about how compilers convert C++ structures. – Michael Anderson Apr 11 '13 at 05:32
  • To Clarify Some more, Disassembly is the most you can decompile with Hex-Rays will translate ASM to C++ ASM can be translated to any programming language with work as all programs can run as ASM – Barkermn01 Apr 12 '14 at 12:08
  • Note that even the earliest release of the [Hex-Rays plugin](https://www.hex-rays.com/products/decompiler/index.shtml) is not compatible with the [IDA 5.0 Freeware](https://www.hex-rays.com/products/ida/support/download_freeware.shtml) release of IDA. – CODE-REaD Sep 19 '16 at 22:26
  • 6
    SNOWMAN is a good free c++ decompiler – Inga Apr 13 '18 at 01:05
  • 3
    +1 for Snowman, but as others have mentioned, even a simple [Hello, World](https://derevenets.com/examples.html#_hello_world) becomes practically unreadable once decompiled. – bdetweiler Dec 02 '18 at 17:28
29

information is discarded in the compiling process. Even if a decompiler could produce the logical equivalent code with classes and everything (it probably can't), the self-documenting part is gone in optimized release code. No variable names, no routine names, no class names - just addresses.

Dustin Getz
  • 21,282
  • 15
  • 82
  • 131
21

Yes, but none of them will manage to produce readable enough code to worth the effort. You will spend more time trying to read the decompiled source with assembler blocks inside, than rewriting your old app from scratch.

m_pGladiator
  • 8,462
  • 7
  • 43
  • 61
6

I haven't seen any decompilers that generate C++ code. I've seen a few experimental ones that make a reasonable attempt at generating C code, but they tended to be dependent on matching the code-generation patterns of a particular compiler (that may have changed, it's been awhile since I last looked into this). Of course any symbolic information will be gone. Google for "decompiler".

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
3

Depending on how large and how well-written the original code was, it might be worth starting again in your favourite language (which might still be C++) and learning from any mistakes made in the last version. Didn't someone once say about writing one to throw away?

n.b. Clearly if this is a huge product, then it may not be worth the time.

harriyott
  • 10,505
  • 10
  • 64
  • 103
  • http://www.joelonsoftware.com/articles/fog0000000069.html – Dustin Getz Oct 15 '08 at 16:56
  • 26
    Joel is a great columnist, but at times wrong. And then there are times when he's quoted wrong. Like here, since the question centers around the loss of source code. Joels article explains why source code is valuable. – MSalters Oct 16 '08 at 10:47
  • 6
    *Didn't someone once say about writing one to throw away?* Yeah, and he changed his mind http://www.davewsmith.com/blog/2010/brook-revisits-plan-to-throw-one-away *[I]n 1975, I counseled programmers to “throw the first version away,” then build a second one. By the 20th-anniversary edition, I realized that constant incremental iteration is a far sounder approach* – ta.speot.is Apr 06 '15 at 03:13