Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is an assembly .exe file?

Tags:

.net

clr

Assembly in .net Framework is, as I understand, intermediate language file + some metadata, manifest and maybe something else.

CLR translates an assembly to the machine code, which can be executed on the given local machine.

That means that assembly shouldn't be executable by the machine before being processed by CLR. If it's so, then why does it have .exe extension, which is executable on Windows machines?

like image 450
Sergey Avatar asked Mar 29 '11 16:03

Sergey


People also ask

Is an exe an assembly?

An EXE assembly actually runs in its own address space while a DLL can not run by itself. It doesn't have its own address space, which means it has to run inside some host and needs a consumer to invoke it. For example, we can use the class library as a reference (dependency) in the console app.

What is EXE file in assembly language?

An EXE file is a Windows file. Your assembler should output a binary file, which would probably need to be converted to an Intel Hex file, the standard for burning to EPROMs, depending on where the Z80 is executing the code from.

What is the purpose of a .EXE file?

An executable file (EXE file) is a computer file that contains an encoded sequence of instructions that the system can execute directly when the user clicks the file icon. Executable files commonly have an EXE file extension, but there are hundreds of other executable file formats.

What is assembly exe and DLL?

An assembly is a collection of one or more files and one of them DLL or EXE. DLL contains library code to be used by any program running on Windows. A DLL may contain either structured or object oriented libraries. A DLL file can have a nearly infinite possible entry points.


3 Answers

Since Windows needs to create a process and the first thing .exe will do is to host CLR by loading mscoree.

From CLR via C#:

After Windows has examined the EXE file's header to determine whether to create a 32-bit process, a 64-bit process, or a WoW64 process, Windows loads the x86, x64, or IA64 version of MSCorEE.dll into the process's address space. On an x86 version of Windows, the x86 version of MSCorEE.dll can be found in the C:\Windows\System32 directory. On an x64 or IA64 version of Windows, the x86 version of MSCorEE.dll can be found in the C:\Windows\ SysWow64 directory, whereas the 64-bit version (x64 or IA64) can be found in the C:\Windows\System32 directory (for backward compatibility reasons). Then, the process' primary thread calls a method defined inside MSCorEE.dll. This method initializes the CLR, loads the EXE assembly, and then calls its entry point method (Main). At this point, the managed application is up and running.

like image 186
Aliostad Avatar answered Oct 19 '22 19:10

Aliostad


I have recently written a blog post on the CLR stub in a .NET assembly and how it fits inside the PE file executable format. The whole series can be found here.

Essentially, inside a .NET assembly is a tiny bit of native code that starts the CLR. However, this code only exists for backwards-compatibility. From Windows XP, the OS loader natively knows to load the CLR for executable that have the CLI header in them.

like image 7
thecoop Avatar answered Oct 19 '22 18:10

thecoop


A .NET .exe is a special kind of .exe that will first load up the CLR (Common Language Runtime). It will then compile the IL code inside the .exe through the CLR.

An .exe compiled through the .NET framework is a kind of Portable Executable. The .exe has a CLR Header and CLR Data section. When the .exe loads, the OS will yield control to the CLR. The CLR Data section in the .exe has a metadata and an IL (Intermediate Language) segment. The metadata segment contains information about the assembly (such as the assembly manifest). The IL segment contains the code for the program in IL format. This is an intermediate format similar to Java bytecode.

like image 3
Vivin Paliath Avatar answered Oct 19 '22 17:10

Vivin Paliath