Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract C source code from .so file?

I am working on previously developed software and source code is compiled as linux shared libraries (.so) and source code is not present. Is there any tool which can extract source code from the linux shared libraries?

Thanks, Ravi

like image 999
Ravi Avatar asked May 09 '11 05:05

Ravi


People also ask

How do I get the source code of an .so file?

There isn't. Once you compile your code there is no trace of it left in the binary, only machine code. Some may mention decompilers but those don't extract the source, they analyze the executable and produce some source that should have the same effect as the original one did.

What is .so in C?

so (shared object) over . a library is that they are linked during the runtime i.e. after creation of your .o file -o option in gcc. So, if there's any change in . so file, you don't need to recompile your main program. But make sure that your main program is linked to the new .

Can we decompile. SO file?

The source is not part of binary files. You can decompile the binary code, but it will not be the original source code, and will not really be readable.


2 Answers

There isn't. Once you compile your code there is no trace of it left in the binary, only machine code.

Some may mention decompilers but those don't extract the source, they analyze the executable and produce some source that should have the same effect as the original one did.

like image 89
cnicutar Avatar answered Oct 07 '22 01:10

cnicutar


You can try disassembling the object code and get the machine code mnemonics.

objdump -D --disassembler-options intel sjt.o to get Intel syntax assembly

objdump -D --disassembler-options att sjt.o or objdump -D sjt.o to get AT&T syntax assembly

But the original source code could never be found. You might try to reverse the process by studying and reconstruct the sections. It would be hell pain.

like image 27
phoxis Avatar answered Oct 06 '22 23:10

phoxis