Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the code stored in an executable? [closed]

I read that an executable stores the code in different sections. For example, a separate section for data etc. Is this generic across different platforms such as Win or MacOs or Linux?

Some insight into it would be really helpful.

like image 290
ssk Avatar asked Sep 01 '12 23:09

ssk


People also ask

How are executable files executed?

When a user or other event triggers an executable file, the computer runs the code that the file contains. Executable files contain binary machine code that has been compiled from source code. This low-level code instructs a computer's central processing unit on how to run a program.

What is a closed source code?

Closed source means computer programs whose source code is not published except to licensees. It is available to be edited only by the organization that developed it and those licensed to use the software.

What is used to store only the executable program code?

EXE Files. The second DOS format for executable programs is the . EXE file, which is another type of binary file. This format is also used under Windows.

Where is the executable program stored?

On a Windows system, the application's executable files are generally kept (by default) in C:\Program Files or C:\Program Files (x86) , but this could be changed by the user at install time.


1 Answers

You are correct in that an executable has several sections or segments: Not all of them, however, are code.

There is usually one segment for code - in ELF and PE, this is usually called .text. Additional ones exist to store dynamic linkage data, hard coded strings, read only data, global variables, etc.

To see these for yourself, rather than Wiki and Google , try hands on:

In Windows: You have a tool called DUMPBIN.EXE , part of visual studio. If you can't get your hands on that, use Dependency Walker (which is freely downloadable). This will parse PE and PE32+ (that is, 64-bit) files

In Linux: Use objdump -x , or readelf (both are pretty much the same, though with slightly different options) for ELF files.

In Mac: Use otool -l to see the load commands (which show you the sections and the segments) in Mach-O files.

Using either or all tools will hopefully get you a better idea of how things work.

Hope this helps,

TG

like image 146
Technologeeks Avatar answered Sep 29 '22 07:09

Technologeeks