Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you retrieve source from a debug-compiled binary?

I was digging around and found an executable for something I wrote in Visual C++ 6.0 about 8 years ago. I never backed up the source code, but I think I always compiled everything in debug mode. I also vaguely remember hearing somewhere that "you can't decompile an executable into source code unless you have your compiler's debugging symbols or something." The code would have sentimental value, but its not mission-critical that I retrieve it.

That's the background; here are the questions:

  1. How do I check if an executable was compiled in debug mode or not?
  2. If it is, what information comes with a debug mode executable?
  3. Can I retrieve full source code? Failing that, can I get any substantial improvement when decompiling compared to a release version? If so, how?

Thanks,

-- Michael Burge

like image 842
Michael Burge Avatar asked Nov 25 '22 16:11

Michael Burge


1 Answers

  1. I do not believe there is a flag though you might find something by using PEDUMP which will dump out COFF file formats (Windows EXE and DLLs). You can infer if an executable was compiled for debug rather quickly by running Dependecy Walker and seeing if your EXE is linking to any debug DLLs (suffixed with D, e.g. MSVCRT5D.DLL).

    FYI in VC6 Debug and Release are simple named builds, not modes per say, each build a collection of compiler and linker settings. The EXE is just code, debug exes normally not having been optimized which makes using a debugger with it easy (versus debugging optimized code). Thus you can compile a Release binary with Debug Symbols which is sometimes useful for tracking down optimized code errors.

  2. Debug EXEs and DLLs did not contain any debugging information but instead had a sidecar PDB file that resided in the same folder and contains all the debugging symbols information that was produced during compilation.

  3. No, source is source and not compiled into the symbols file or executables. There are some amazing decompilers out there that can regenerate decent C versions of your code but they are amazing only in how good the C is, not in how well they can recreate your source.

like image 180
Troy Sandal Avatar answered Dec 28 '22 09:12

Troy Sandal