How to decode the c source code which is gcc compiled

2.6k views Asked by At

I accidentally deleted my source program, now i only have the gcc compiled code.Is there any way to get back my source code.

3

There are 3 answers

0
SirPython On

You can use a disassembler, but you'll never be able to fully restore the program's source code.


To prevent this in the future, I recommend either using source control, like Git or Subversion. Using these tools, you will always have backups of your code in case a big mistake like this were to happen.

2
apandit On

If you are using an Eclipse-based IDE, it might have a saved version of your source in its history. If so, right-click on the project and select "Restore from Local History...".

EDIT Otherwise try grep -a -C 200 -F 'Unique string in text file' /dev/sda1 > OutputFile; replace 200 with the number of lines you think are in the file and /dev/sda1 with the partition.

See the Text file recovery section at https://wiki.archlinux.org/index.php/File_recovery for more info.

Good luck!

0
John Bode On

Recovering C source from a binary has been described as "turning hamburger back into cows". You will not be able to recover your original source code. At best, you will get back some code that's functionally equivalent to your original source, but it won't contain any of your original variable names, comments, macros, etc., it may not be structured the same (depending on how aggressively it was optimized), and it may not be very understandable (again, depending on how it was optimized).

Hopefully the original is still recoverable somehow.