I accidentally deleted my source program, now i only have the gcc compiled code.Is there any way to get back my source code.
-
yes, but not in the same form as it was compiled in. – Marc B Sep 04 '15 at 19:56
-
Depending on how you deleted it, you may be able to simply perform a file recovery. – Zsw Sep 04 '15 at 19:58
-
Been there man, if it wasn't a gigantic project it'll be much faster to rewrite it then to try and recover it. – asdf Sep 04 '15 at 19:58
-
Please see the EDIT in my answer below. There may be a way to recover your original source directly. – apandit Sep 04 '15 at 21:03
-
forget about recovery and all,is there any way to get the source code back.like can you people suggest a good free disassembler ? – 404 Sep 05 '15 at 02:32
3 Answers
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.

- 119,563
- 19
- 122
- 198
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.

- 647
- 6
- 19
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!

- 808
- 1
- 7
- 16
-
-
@CristiFati See my edit. Also, I know some universities do nightly backups of their file systems. – apandit Sep 04 '15 at 21:00