10 Replies - 6827 Views - Last Post: 12 December 2010 - 12:09 PM Rate Topic: -----

#1 komi87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 10

extract C code from exe file!

Posted 12 December 2010 - 10:00 AM

hello everyone,
i was doing my assignment in C language and somehow i lost the code of it :( it has been deleted by certen reasons i dono how :(((
but when i searched i found out that i still have the exe file and it works but i lost the code which is quite long :(
dose any one know how i can extract a c code from exe file plzzzz? cuz i really need to handle it this week !!! i need help???

Is This A Good Question/Topic? 0
  • +

Replies To: extract C code from exe file!

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1654
  • View blog
  • Posts: 3,133
  • Joined: 30-May 10

Re: extract C code from exe file!

Posted 12 December 2010 - 10:15 AM

The short answer is no, you will not be able to recover YOUR program from the executable.

The long answer is that you can (sometimes) recover an equivalent C program which does the same thing. But it won't be any code you would want to work with. Your meaningful variable names will likely be replaced with var1, var2, func1() etc.

Is this your personal machine, or some campus server?
If it's your own, then I would suggest you stop using it until you've read this:
If it's a windows machine, make sure automatic defragmentation is turned OFF, as this will destroy any recoverable information.

http://www.google.co...=utf-8&oe=utf-8
Add words like "free" and the name of your OS to the end of the search.

Most file systems, when you delete a file, just drop the directory entry. The actual bytes of your file are still on the disk, somewhere in the free block list. But the longer you leave between deleting the file and attempting recovery, the less chance of success you will have.

Finding another machine and putting a couple of tools onto a USB stick might just work.

If you're using an IDE, then check to see if any "backup" files have been saved.
Was This Post Helpful? 1
  • +
  • -

#3 vbym  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 19
  • Joined: 30-November 10

Re: extract C code from exe file!

Posted 12 December 2010 - 10:16 AM

How do I turn a hamburger into a cow?

You could possibly decompile it, but what it would give you wouldn't be very human readable and it won't resemble your source code very much either.

Edit: Ninja'd by a much better post.

This post has been edited by vbym: 12 December 2010 - 10:16 AM

Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: extract C code from exe file!

Posted 12 December 2010 - 10:19 AM

Well... you may have to re-write the program as decompiling is not a very viable solution.

if you did a "debug" build and you have all of the associated files you actually may stand a good chance.

Past that though things go down hill quickly. When a compiler compiles code it strips out the nice variable names that you used and replaces them with either stack references or with encoded "symbols" -- all function names are replaces by encoded symbols too. When the linker links the object files it replaces the symbols with references (relative memory addresses). -- So in the final exe most of the variable and function names are whipped out (some actually remain in the PE especially if you are creating a dll file).

Next the control structures (if-else blocks, while loops, for loops etc.) tend to get optimized and it can be VERY difficult to reverse the process and guess what the original source looked like.

Basically a great deal of the information and structure available in the source file is lost in compiling. The BEST to you can do utilizing the most expensive code analyzers is generate some C source that does the same thing. -- Using free tools I think the best you can really achieve is disassemble.

If however you have all of the debugging information you can try to load the program into a debugger and see what you can recover.


You might do better to look into getting some forensic software to try to recover the source or fragments of it from the harddrive.
Was This Post Helpful? 0
  • +
  • -

#5 komi87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 10

Re: extract C code from exe file!

Posted 12 December 2010 - 10:31 AM

ok thx, it seems that impossible to have it again :(
if i ask a Question about C problem dose any one help me and give me some ideas of how to do it???
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: extract C code from exe file!

Posted 12 December 2010 - 11:33 AM

If you already WROTE the program, you should be able to REWRITE it with little help, correct? I mean, you learned stuff by writing your program, that was the whole point of writing it as your assignment; that makes it easier for you to reproduce it and continue on in your studies.
Was This Post Helpful? 0
  • +
  • -

#7 komi87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 10

Re: extract C code from exe file!

Posted 12 December 2010 - 11:45 AM

my C Question is that it showes like a menu as below and when i chose any number of those it dose something:


1-enter student grades
2-show student grades:
3-sort by id:
4-sort by final grades:
5-show statistics:
6-Add students grades:
7-delete students grades:
0-Quit the program:
enter your choice:

if i chose number 1 it will show the following:

Enter student id (0 t end): 20311
after i enterd the id student it show this :

Enter exam-I >=0 and <=25:22

Enter exam-II >=0 and <=25:22

Enter finalExam >=0 and <=50:22

and then ask u again for another id
Enter student id (0 t end):

and the same thing till i enter chose 0 then will return me to the main menu:
1-enter student grades
2-show student grades:
3-sort by id:
4-sort by final grades:
5-show statistics:
6-Add students grades:
7-delete students grades:
0-Quit the program:
enter your choice:

if i chose 2 it show to me the grades as :

id_number midTerm final grade
--------- ------- ----- -----
20311 44 22 66

1-enter student grades
2-show student grades:
3-sort by id:
4-sort by final grades:
5-show statistics:
6-Add students grades:
7-delete students grades:
0-Quit the program:
enter your choice:
number 2 and 3 is sorting
and number 5 is show statistics:

MidTerm fExam fGrade
------ ------- ------ ------
average 44 22 66
maximum 44 22 66
minmum 44 22 66

1-enter student grades
2-show student grades:
3-sort by id:
4-sort by final grades:
5-show statistics:
6-Add students grades:
7-delete students grades:
0-Quit the program:
enter your choice:


i hope i am clear to explain this problem and i would like to discuss this problem with u and hope i have ideas how i can make the code to that work
i will tell u my ideas to the solution plz help me

i think i have to do it in array and different functions which make the requiremnts
but in the main function first i have to so switch so i can control my menu i will write my suggestion code and plzz give me your ideas if possible???
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: extract C code from exe file!

Posted 12 December 2010 - 11:53 AM

OK, so if you already did this, why are you asking us how to do it???

/smells something funny
Was This Post Helpful? 0
  • +
  • -

#9 komi87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 10

Re: extract C code from exe file!

Posted 12 December 2010 - 11:59 AM

of couse if i am sure of my answers i wouldnt be funny and ask but that was my suggstion to the problem i am not sure of it and i wanted to have more ideas how to do it ok dear thx anyway ;)
Was This Post Helpful? 0
  • +
  • -

#10 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: extract C code from exe file!

Posted 12 December 2010 - 12:03 PM

View PostJackOfAllTrades, on 12 December 2010 - 01:53 PM, said:

OK, so if you already did this, why are you asking us how to do it???

/smells something funny

:shit:
I thought I smelled that about 2 hours ago.
Was This Post Helpful? 0
  • +
  • -

#11 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: extract C code from exe file!

Posted 12 December 2010 - 12:09 PM

And this is one of the many reasons why we use source.revision control! It's vital practice, so get used to it.

My own personal preference is Perforce which is free to the individual up to two licenses. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1