Pavunkumar
Pavunkumar

Reputation: 5335

Getting source from object file

Is there any way to get the source code by using object file in C?

For example I have a source code simple.c

cc simple.c

Now I have a.out (object file). By this a.out whether can I get the source?

code of simple.c

Upvotes: 23

Views: 37519

Answers (6)

god damn
god damn

Reputation: 1

you can extract the strings present in the executable with the command strings if you are using linux.

Upvotes: 0

prabhakaran9397
prabhakaran9397

Reputation: 97

If you're using Linux, use gdb

$gdb a.out

(gdb) list

Upvotes: 1

bortzmeyer
bortzmeyer

Reputation: 35469

The words for the programs you are looking for are "disassembler" (turning the machine language in a.out into assembly language) and "decompiler" (turning assembly language into C, as explained by Dacav, it is much more difficult and the result is never satisfying).

But using a Web search engine with these words may yield results.

Upvotes: 1

Dacav
Dacav

Reputation: 14078

There are many useful tools to retrieve information from your executable. None of them is able to give you back the original source code (as some other user pointed out, it's impossible for C), but you can try some reverse engineering tools. My preferred one are:

  • Objdump (part of the "binutils" package)
  • hte (debian packages it as "ht")

With the first one you can actually get all the exported symbols and their relative executable code in terms of assembly (obviously this is true only for the .text sections). The second one is aimed to work with intel architectures, but you will be able to analize every executable file and get information about the ELF sections and symbols.

Upvotes: 21

Jerry Coffin
Jerry Coffin

Reputation: 490178

No. Turning a cow into hamburger is fairly easy. Turning hamburger into a living cow, somewhat more difficult.

Upvotes: 68

kennytm
kennytm

Reputation: 523344

No.

With reverse engineering (reading the disassembly) one could reconstruct the logic, but the variable names, comments, etc. will usually be lost.

Upvotes: 0

Related Questions