5

I am writing a C program and I have converted it from .c to .so file using GCC. I was little curious to know if is there any way to convert back the .so file to .c file.

Assume I am shipping my code to someone and it contains all the .so files. Is there a chance that someone can get access to my source code using any tool, editor, technique etc?

Biffen
  • 6,249
  • 6
  • 28
  • 36
user3457384
  • 593
  • 6
  • 14
  • 2
    Saying that you “convert” .c files to .so files is really quite misleading. It’s not simply a format conversion. They represent fundamentally different things. Otherwise a back-conversion would be trivial. – Konrad Rudolph Apr 10 '19 at 09:19
  • 2
    @KonradRudolph You forgot to mention what the "conversion" *is* called :) – Timo Apr 10 '19 at 09:23
  • 2
    If you don't want anyone to know what your code does, you can't give them the binary that actually does it. – Andrew Henle Apr 10 '19 at 09:29
  • 2
    Possible duplicate of [How to extract C source code from .so file?](https://stackoverflow.com/questions/5933057/how-to-extract-c-source-code-from-so-file) – GSerg Apr 10 '19 at 09:32
  • @AndrewHenle, so what should be the right approach for giving the code, provided we don't have any other option rather than giving it and we also don't want the source code to be revealed. – user3457384 Apr 10 '19 at 09:32
  • You can try to use [a decompiler](https://www.hex-rays.com/products/decompiler/index.shtml), but because of reverse-translating of binary code to a higher level language has many different interpretations - resulting code is very mangled and can be used only for a initial study / overview of code structure before jumping to assembly. – Agnius Vasiliauskas Apr 10 '19 at 09:34
  • 2
    Possible duplicate: [What's a good C decompiler?](https://stackoverflow.com/questions/193896/whats-a-good-c-decompiler) – SKi Apr 10 '19 at 09:35
  • 1
    You don't have to give them your code (barring license issues such as those from the GPL), but if you distribute binaries compiled from that code, whoever gets those binaries **WILL** be able to tell what your code does if they wish. If you give someone a binary that does something, whoever you give that binary too **WILL** be able to tell what it does. The **ONLY** way to keep what your code does a secret is to not distribute binaries compiled from it. You can make it harder to figure out, but it's **IMPOSSIBLE** to keep secret. If your management doesn't like that, too bad. That's reality. – Andrew Henle Apr 10 '19 at 10:54

1 Answers1

16

You can’t get the original C source file back, because that contains information that are simply not represented in the machine code inside a shared object (.so) file.

However, object code can be disassembled into readable machine code, which an expert can understand. So the logic in your C code shouldn’t be considered “secret”.

There are methods of obfuscating code to make it harder to understand disassembled code but these methods have varying degree of effectiveness, and the more effective they are the more side-effects they carry (predominantly by making code execution a lot slower).

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214