20

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

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
Ravi
  • 653
  • 3
  • 10
  • 21

5 Answers5

19

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.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • 5
    Decompilers produce some pretty gawd-awful code. The variable names are meaningless and there are no useful comments. You might as well be staring at the assembly. – Chris Eberle May 09 '11 at 06:04
  • 1
    @Christ I agree. I didn't get to use Hex-rays (which I heard is quite good) but the others I tried were awful. – cnicutar May 09 '11 at 06:05
6

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.

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
phoxis
  • 60,131
  • 14
  • 81
  • 117
4

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?

Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
-3

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

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
-16

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.

Jens
  • 69,818
  • 15
  • 125
  • 179
arshad
  • 267
  • 4
  • 11