LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to view the content of executable binaries? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-view-the-content-of-executable-binaries-724787/)

saagar 05-08-2009 09:34 PM

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.

lazlow 05-08-2009 09:47 PM

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.

saagar 05-08-2009 09:53 PM

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

i92guboj 05-08-2009 10:00 PM

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.

lazlow 05-08-2009 10:08 PM

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

saagar 05-09-2009 01:20 PM

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

dxqcanada 05-09-2009 01:25 PM

Here is doc on Reverse Engineering Linux ELF Binaries


All times are GMT -5. The time now is 08:32 AM.