is it possible to obtain C code from module (file .o)???
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But if you know where that file.o came from, then there's a good chance that you can fetch the sources from the original authors. So, where did this file.o came from?
But if you know where that file.o came from, then there's a good chance that you can fetch the sources from the original authors. So, where did this file.o came from?
Are you sure ? I think you can decompile it, it just won't be usable.
But, yes it would be a much better idea to get the sources from the authors.
I meant that you can't get back the original source, and probably nothing remotely similar neither.
But yes, you are right. My post was inaccurate, to say the least. Reading the original post I can't see why I assumed that he wanted to obtain the original source code... Go figure, my bad.
There are decompilers that can guess high level code on a given language that will do the same that the assembly code for the given object file. That's not "the source code" for the application. Just some -almost- meaningless source code that will require deep study and some hard work to be able to do anything useful with it (I guess we are talking about programs of at least a medium complexity, we probably won't be decompiling helloworld.o.
Note that the .o file -more than probably- is not a standalone program either, but a plain non-linked object file. Which probably will make the resulting source even more meaningless -or not, it depends on the purpose of the OP-.
You can't recover C code from an object file. If debug symbols and symbol tables are intact, a disassembler can at least provide somewhat readable assembly code. Of course you don't have the benefits of sensible comments since comments are stripped during the compilation process. Since it is rather rare that there is a unique C code to produce the assembly code in each function, you can't possibly reproduce the C code.
[edit]
On the other hand, you can always write C code which produces the same effect - but don't expect it to be possible to automate such a task.
It's perfectly possible to generate (which is not the same than to restore/recover) ansi c compliant code that does the same work than a given set of assembly instructions from a theoretical point of view. The problem is that it will not be the real source of the program. Semantically, nor procedurally, nor conceptually nor anything similar in any way to the original source code (other than the name of some symbols as you say, if they can be recovered at all).
There are some programs to do this, but usually the generated code is useless because it just takes the assembly dump and adds another layers of complexity on top of it. I've never seen any program that can decompile to C in a way that the result is actually useful, unless the size of the project is manageable, and the only purpose is to recompile for another architecture or whatever. The work wouldn't be trivial either I presume (I am not mad enough even to try).
If the OP feels motivated enough he could try something like this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.