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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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: