1826499 Members
1640 Online
109692 Solutions
New Discussion

Re: determine C objects

 
mango_1
Frequent Advisor

determine C objects

hello all! I want to determine the C source files that I compiled an executable with.
example:
gcc -o example main1.c sub1.c sub2.c

so I get an example exe.

Problem:
Given only the executable and not knowing which files it was compiled with. Is it possible to determine the *.c files he/she used to compile the executable?

any help is much appreciated. thanks! :)
2 REPLIES 2
ranganath ramachandra
Esteemed Contributor

Re: determine C objects

if hp cc/aCC has been used, the following commands can help with unstripped binaries:
"odump -compunit" for 32-bit SOM binaries & "elfdump -dc" for 64-bit ELF binraies.
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

Kenneth Platz
Esteemed Contributor

Re: determine C objects

It's possible if you are a little bit creative with the way you create your source files.

Add the line:

static char ident[]="@(#)foo.c";

At the top of your source file. That way, when you compile it into an object file, that string "@(#)foo.c" will be embedded within your object file, and the resulting executable. Then you can use the "what" command to extract the information from your object.

# cc -o foo foo1.c foo2.c
# what foo
foo:
$Revision: 92453-07 linker linker crt0.o B.11.33 020617 $
foo1.c
foo2.c

Hope this helps.
I think, therefore I am... I think!