Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How exactly do executables work?

I know that executables contain instructions, but what exactly are these instructions? If I want to call the MessageBox API function for example, what does the instruction look like?

Thanks.

like image 561
Alon Gubkin Avatar asked Oct 24 '09 02:10

Alon Gubkin


People also ask

How an executable is executed?

In order to be executed by the system (such as an operating system, firmware, or boot loader), an executable file must conform to the system's application binary interface (ABI). In simple interfaces, a file is executed by loading it into memory and jumping to the start of the address space and executing from there.

How is an executable made?

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.

What makes up an executable file?

An Executable file contains several blobs of data and instructions on how the datas should be loaded into memory. Some of these sections happen to contain machine code that can be executed. Other sections contain program data, resources, relocation information, import information etc.

Can humans read exe files?

Until an exe runs its just a binary file, so yes you can read it.


1 Answers

Executables are binary files that are understood by the operating system. The executable will contain sections which have data in them. Windows uses the PE format. The PE Format has a section which has machine instructions. These instructions are just numbers which are ordered in a sequence and is understood by the CPU.

A function call to MessageBox(), would be a sequence of instructions which will

1) have the address of the function which is in a DLL. This address is put in by the compiler

2) instructions to "push" the parameters onto a stack

3) The actual function call

4) some sort of cleanup (depends on the calling convention).

Its important to remember that EXE files are just specially formatted files. I dont have a disassembly for you, but you can try compiling your code, then open your EXE in visual studio to see the disassembly.

like image 120
Andrew Keith Avatar answered Nov 02 '22 10:11

Andrew Keith