LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-03-2008, 02:35 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: España
Distribution: Suse
Posts: 227

Rep: Reputation: 32
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.
 
Old 11-03-2008, 03:09 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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?
 
Old 11-03-2008, 04:03 AM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by i92guboj View Post
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.
 
Old 11-03-2008, 05:09 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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-.
 
Old 11-03-2008, 05:25 AM   #5
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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.

Last edited by pinniped; 11-03-2008 at 05:27 AM.
 
Old 11-03-2008, 05:32 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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).

Last edited by i92guboj; 11-03-2008 at 05:34 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to obtain Source Code theunixwizard Linux - Newbie 2 05-03-2008 03:28 PM
How to obtain source code in FC6 anirudhamshinde Linux - Kernel 1 01-02-2007 08:15 AM
Including the header file of a module in kernel code omkarlagu Linux - Newbie 0 02-05-2006 07:55 AM
obtain Gnome same game source code linuxmandrake General 1 12-26-2005 11:31 AM
Not able to obtain file size skie_knite007 Programming 5 08-08-2005 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration