LinuxQuestions.org
Help answer threads with 0 replies.
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 05-08-2009, 10:34 PM   #1
saagar
Member
 
Registered: Jul 2008
Location: Chennai, India
Distribution: RHEL5, Ubuntu
Posts: 191

Rep: Reputation: 37
How to view the content of executable binaries?


Hello Friends...
Sorry if this is a wierd question. Suppose if I am writing a script called
myscript.sh and if I put it to /bin directory and if I just type:
[ ]#myscript
it works. So, if i open it via
[ ]#vi /bin/myscript
....I can see its contents... my question is why it is not possible to open an executable command, say, /bin/ls like this?. Is there any other way to see the source code of it?...

Thank you.
 
Old 05-08-2009, 10:47 PM   #2
lazlow
Senior Member
 
Registered: Jan 2006
Posts: 4,362

Rep: Reputation: 172Reputation: 172
You script has not been compiled, binaires have been. You can look at the source code of the binaires. In Rpm based systems you do this by looking at the src rpm of the package that the binary came from.
 
Old 05-08-2009, 10:53 PM   #3
saagar
Member
 
Registered: Jul 2008
Location: Chennai, India
Distribution: RHEL5, Ubuntu
Posts: 191

Original Poster
Rep: Reputation: 37
lazlow, thanks for the quick reply...
I got the point related to compilation of the script, but the second one, that is, viewing the source code...
suppose if i want to look at the source code of /bin/ls. Its rpm package is coreutils. So how to go about with that src rpm thing. Could u pls eloborate...?
 
Old 05-08-2009, 11:00 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
To extend what lazlow already said, there's a difference between scripts and binary object files. Or more correctly, there's a different between interpreted languages and compiled ones.

Technically you could write an interpreter or a compiler for any language, but tipically some languages are compiled, and some others are interpreted. An interpreter takes a file that's written in the language and translates it to a language that the machine can understand in the same moment that you run the file. A compiler, on the contrary, takes the source file and translates it to machine object code permanently, producing a binary file (in windows this is tipically a .exe, .dll, .vbx or whatever suits the occasion). Then you run that file which doesn't need to be translated anymore.

Compiled programs are usually faster since they don't need to be translated to machine code when you run them. They can also be optimized in lots of ways since the compilation time is not really important. On the contrary, an interpreter can't spend a whole life to interpret a program, otherwise the user might think that his core7 is an amstrad loading from a tape.

Binary files are not human readable, you can always see the bytes with an hex editor though, and you could always use a dissassembler to read the instructions in an easier way.

If you want to get the source code for a program, visit their website. It's the logical place to start looking. However this is only true for open source stuff. Closed source programs do not make their sources available to the public.
 
Old 05-08-2009, 11:08 PM   #5
lazlow
Senior Member
 
Registered: Jan 2006
Posts: 4,362

Rep: Reputation: 172Reputation: 172
saagar

In all rpm distros they have a section of their repo that contains the source rpms. For instance I run Centos 5.3:

If I download the coreutils src.rpm and then extract it, I will find the file coreutils-5.97.tar.bz2. If I extract that file(coreutils-5.97.tar.bz2) I will find the ls.c and ls.h files(in the src directory of the extracted portion).
 
Old 05-09-2009, 02:20 PM   #6
saagar
Member
 
Registered: Jul 2008
Location: Chennai, India
Distribution: RHEL5, Ubuntu
Posts: 191

Original Poster
Rep: Reputation: 37
Thanks a lot i92guboj for that wonderful explanation and lazlow for that very useful info...
This is why I love this site...! u all are great!!
 
Old 05-09-2009, 02:25 PM   #7
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Here is doc on Reverse Engineering Linux ELF Binaries
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 view raw content in a disk? fjkum Linux - Newbie 6 03-23-2009 06:09 PM
view the content of tape binuveranal Linux - Server 1 02-27-2008 12:18 AM
how to view content of tape angelfire Linux - Hardware 5 07-22-2006 05:21 AM
Way to view quiz content? frob23 LQ Suggestions & Feedback 4 01-16-2005 04:03 AM
Cannot not run executable jar file after set content type for download antony_csf Programming 1 12-08-2004 01:22 AM


All times are GMT -5. The time now is 01:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration