How to extract C source code from .so file?

风流意气都作罢 提交于 2019-11-30 08:27:07

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 he 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?

No. In general, this is impossible. Source is not packaged in compiled objects or libraries.

arshad

You cannot. But you can open it as an archive in 7-Zip. You can see the file type and size of each file separately in that. You can replace the files in it with your custom files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!