Re: Getting source file from the object file
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 13 Mar 2009 17:40:18 -0700
"JosephKK"<quiettechblue@xxxxxxxxx> writes:
On Fri, 06 Mar 2009 15:38:42 -0800, Nate Eldredge <nate@xxxxxxxxxx>[...]
wrote:
There's some confusion here. If we know that the given executable file
is the output of a particular compiler whose output is a deterministic
function of its input, then certainly a brute-force search will find, in
finite time, some source file which when compiled by that compiler
yields the desired output.
I am not so assured about that. How reliably can you disambiguate
between pointer and array style accesses? How can you reconstruct
structs and unions reliably (especially those defined in header
files)? Furthermore, what if they are typedef'ed in header files?
(just to push the points) How about incomplete types?
You don't need to. It's not possible to reconstruct *the* C source
file that produced a given executable (unless the executable is
annotated with a lot of extra information), but it should be possible
to construct *a* C source file that, when compiled, will produce an
executable with the same behavior as the one you started with. If the
original C source used arrays and the re-generated one uses pointers,
that shouldn't matter.
If nothing else, you can emit the code for a C emulator for the
machine code, and include the machine code as a static array.
Whether it's possible to produce the exact same executable is
another question.
Of course, none of this is of any use for the original poster, who (as
I recall) was looking for a way to recover a C source file that he had
accidentally deleted. The answer to that is (a) he's almost certainly
out of luck, unless his system provides some way to recover deleted
files, and (b) for the future, use backups and a source control
system.
--
Keith Thompson (The_Other_Keith) kst@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Getting source file from the object file
- From: JosephKK
- Re: Getting source file from the object file
- References:
- Getting source file from the object file
- From: pavunkumar
- Re: Getting source file from the object file
- From: user923005
- Re: Getting source file from the object file
- From: Richard Tobin
- Re: Getting source file from the object file
- From: Phil Carmody
- Re: Getting source file from the object file
- From: Nate Eldredge
- Re: Getting source file from the object file
- From: JosephKK
- Getting source file from the object file
- Prev by Date: Re: Copying clipboard into string
- Next by Date: Re: Memory consumption
- Previous by thread: Re: Getting source file from the object file
- Next by thread: Re: Getting source file from the object file
- Index(es):
Relevant Pages
|