Managed Code In the context of .NET
What is a program? ● ● ● ● ● ● ● How to locate and parse them? ? Program.exe
Introducing PE ● ● ● ● ●
Introducing PE
Introducing PE
Introducing PE
Introducing PE
DEMOExploring PE file format with PPEE (puppy) PPEE Tool Website: https://www.mzrst.com/
Managed code loading ● ●
Managed code loading Program.exe mscoree.dll clr.dll Process 1. Read PE Headers 2. Examine headers to decide if it is managed code 3. Load mscoree.dll 4. Load correct version of CLR 5. CLR takes over the execution PE Headers mscoree.dll clr.dll
mscoree.dll and clr.dll are unmanaged
The manager, CLR The Common Language Runtime (CLR) is a complete, high level virtual machine designed to support a broad variety of programming languages and interoperation among them.” ● A Virtual Machine, analogous to Java Virtual Machine ● Supports many languages; C#, VB.NET, Visual C++, F# etc. ● Interoperation between the languages: CLS and CTS ● Extra features https://github.com/dotnet/coreclr/blob/master/Documentation/botr/intro-to-clr.md
CLR in the context of CLI ● CLR is part of a container of standards called Common Language Infrastructure ● Source code is compiled to CIL ● CLR takes CIL, compiles it to machine code at runtime using JIT ● CLR manages the execution of the code to provide extra features
The managed code, CIL Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL), is the lowest-level human-readable programming language defined by the Common Language Infrastructure (CLI) specification and is used by the .NET Framework, .NET Core, and Mono. Languages which target a CLI-compatible runtime environment compile to CIL, which is assembled into an object code that has a bytecode-style format. CIL is an object-oriented assembly language, and is entirely stack-based. Its bytecode is translated into native code or—most commonly—executed by a virtual machine.
DEMODisassembling CIL to C# using ILSPY https://github.com/icsharpcode/ILSpy
Advantages of managed code ● ● ● ● ● ● ●
Compilation tools C# CIL 100101101010 101110101010 011100101101 100111010001 Native Code C# compiler JIT compiler ILDASM
There is a mistake, look closer C# CIL 100101101010 101110101010 011100101101 100111010001 Native Code C# compiler JIT compiler ILDASM
ILASM and ILDASM CIL Human Readable Code CIL bytecode ILASM ILDASM
DEMODisassembling with ILDASM
Thanks

Managed Code .NET