LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   is it possible to obtain C code from module (file .o)??? (https://www.linuxquestions.org/questions/linux-newbie-8/is-it-possible-to-obtain-c-code-from-module-file-o-680765/)

webquinty 11-03-2008 02:35 AM

is it possible to obtain C code from module (file .o)???
 
Hello,

I am not sure if it is possible to do it.

I have a file .o (module) and I would like to obtain code from this module, and if it is possible to obatin this code in C.

Can I do it???


Best regards.

i92guboj 11-03-2008 03:09 AM

If you mean to de-compile it, no, you can't.

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?

H_TeXMeX_H 11-03-2008 04:03 AM

Quote:

Originally Posted by i92guboj (Post 3329818)
If you mean to de-compile it, no, you can't.

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.

i92guboj 11-03-2008 05:09 AM

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-.

pinniped 11-03-2008 05:25 AM

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.

i92guboj 11-03-2008 05:32 AM

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:

http://boomerang.sourceforge.net/

I doubt it's of any use, but there you are anyway.

PS: By all means, try to get the source from the author(s).


All times are GMT -5. The time now is 10:53 PM.