-5

What is the process of compiling C# into PE (.exe file)?
Correct me if I'm wrong:

  1. C# gets compiled into MSIL
  2. MSIL gets translated to bytecode
  3. When we launch PE file the .net vm translates it back to MSIL code and executes it

If that's correct then does that mean when I open PE file in text editor is that bytecode or is there any other step I'm missing like encrypting the bytecode?

René Vogt
  • 43,056
  • 14
  • 77
  • 99
  • This is really a topic for which you really should spend a little time searching the web. It's pretty well documented – LordWilmore Jan 25 '18 at 13:30
  • https://stackoverflow.com/questions/8837329/is-c-sharp-partially-interpreted-or-really-compiled – juharr Jan 25 '18 at 13:31
  • Have a look at https://sharplab.io/ there you can actually see what the different steps look like – Robin B Jan 25 '18 at 13:40
  • 1
    No, MSIL is already "bytecode". The format of an EXE or DLL file is very flexible, it can store arbitrary data. Like MSIL and the metadata that a .NET assembly requires. At runtime the MSIL gets translated to machine code, done by the just-in-time compiler. – Hans Passant Jan 25 '18 at 13:46
  • So the the exe file is just bytecode ? – Capteez Ferjani Jan 25 '18 at 13:57

1 Answers1

2

C# compiler->exe(PE File)->Machine code

This PE file is Pe header, MSIL instructions and Metadata.

When a compiler generates (MSIL), it also generates Meta-data. MSIL and Meta-data are included in a transportable PE file . This PE file hosting is .NET Framework not OS. When you run PE file ,this run on .NET Framework .

run .Net PE file->mscorlib.dll->CLR->JIT->Machine Code

Hasan Jafarov
  • 628
  • 6
  • 16