Dear Friend
Can we get the source file from the object ?
example :
file a.c
cc a.c
Now I have a.out
But I not have the a.c
how could I get the source file using a.out
thanks
The truthful answer is that it depends upon how much symbol table
information is kept in the object file and how much is discarded. But,
the answer is that, for arbitrary code, in general, it is not
possible.
If only the function locations are kept in the symbol table, you can,
with a good decompiler, recreate a realy ugly set of source code that
will produce a functionally equivalent object. The big help here is
that the decomplier can know entry point information and can therefore
determine some of the boundaries of functions. If the decompiler is
REALLY good, it MAY be able to guess that some inaccessible locations
between functions are code space data (for literals, initializations,
etc).
If more symbol information (necessarily including data locations and,
with good fortune, structure definitions) is available in the object
file, the decompiler might be able to produce a reasonable facsimile
of the original source code. It won't be able to tell, for instance,
whether the original code used a for, while, or do loop (or, in some
cases, an if and goto, but the label locations will usually be in the
retained symbol information, if anything is).
However, if you have a large set of source code one of which is known
to have produced the object file and would like to know which among
the source files produced the object file, you could simply compile
all of the source code files and find the object file that has the
smallest amount of difference to the object file that you wish to
create. The object files won't always be identical, because often
modification and compilation date information is retained in the
object file, even when no symbol information is. You can determine
this by compiling the same source to two different object files and
examining their differences.
Good Luck.