How to extract C source code from .so file? How to extract C source code from .so file? linux linux

How to extract C source code from .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.


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.


Disclaimer: I work for Hex-Rays SA.

The Hex-Rays decompiler is the only commercially available decompiler I know of that works well with real-life x86 and ARM code. It's true that you don't get the original source, but you get something which is equivalent to it. If you didn't strip your binary, you might even get the function names, or, with some luck, even types and local variables. However, even if you don't have symbol info, you don't have to stick to the first round of decompilation. The Hex-Rays decompiler is interactive - you can rename any variable or function, change variable types, create structure types to represent the structures in the original code, add comments and so on. With a little work you can recover a lot. And quite often what you need is not the whole original file, but some critical algorithm or function - and this Hex-Rays can usually provide to you.

Have a look at the demo videos and the comparison pages. Still think "staring at the assembly" is the same thing?