3. .NET framework
ā¢ Software framework
ā¢ First released early 2000ās
ā¢ āconsists of the common language runtime (CLR) and the .NET
Framework class library (FCL)ā [1]
ā¢ Provides a ācode execution environmentā
ā¢ Various runtime hosts for the CLR [2]
ā¢ ASP.NET (via ISAPI filter)
ā¢ Executable
ā¢ Can write your own
3
4. CLR
ā¢ The virtual machine that manages execution of .NET programs [3]
ā¢ Memory
ā¢ Threads
ā¢ Code trust
ā¢ Type checking
ā¢ pinvoke
ā¢ JIT compiling to execute on current hardware
4
6. .NET Framework and CLR
ā¢ Framework and CLR are different [4]
ā¢ Can technically run different framework versions
within the same CLR version
ā¢ E.g. Windows XP only supports framework up to 4.0,
running 4.5 apps is theoretically possible (with some
hex editing of the binary) as long as calls are restricted
to methods that were the same in 4.0 (e.g., no
extensions) [5]
ā¢ Recent framework updates have been focused on
ā¢ Optimization (including SIMD)
ā¢ Accessories (stylus, touch screen, etc)
ā¢ Security
6
7. CLR, CLI, CIL
ā¢ Common Language Infrastructure (CLI)
ā¢ Open standard that describes executable code [6]
ā¢ Common Intermediate Language (CIL) [7]
ā¢ Aka āILā
ā¢ Formerly MSIL
ā¢ Object oriented assembly language
ā¢ Platform independent
ā¢ A compiler takes source code and
ā¢ Converts it to CIL using the CLI specification
ā¢ Adds any required metadata (type information, etc)
ā¢ This is an āassemblyā
7
8. CLR, CLI, CIL
ā¢ Visual Studio tooling supports compiling C#, F#, VB.NET to CIL
ā¢ Semi C++ support [8]
ā¢ Language support include IronPython, ClojureCLR, IronScheme, others [10]
ā¢ Can write your own compiler
ā¢ C to CIL example in F# [9]
ā¢ Ahead of time (AOT) compilation to avoid JIT
ā¢ Has some performance benefits
ā¢ No longer portable across hardware
ā¢ CIL makes calling a method in another CIL library convenient
ā¢ Managed by CLR, vs unsafe dll call through pinvoke
8
9. CLR, CLI, CIL
ā¢ The CIL is available at runtime
ā¢ Metadata for the assembly needs to be available to the CLR
ā¢ This is generally available at runtime as well
ā¢ Can use this information to modify code at runtime
ā¢ See [21] which references [22]
ā¢ Useful for performance profiling, anti-debug avoidance
ā¢ Other more suitable tools exist for aspect oriented programming (AOP) and
mocking frameworks
9
10. .NET framework
ā¢ Includes a set of standard class libraries [11]
ā¢ Base Class Library (BCL) [12]
ā¢ Intrinsic types (e.g. string, datetime) and other base classes (e.g. FileStream)
ā¢ Follows ECMA specification
ā¢ Framework Class Library (FCL)
ā¢ Broader library base
ā¢ Depends on BCL
ā¢ Provides extensions, like LINQ methods
ā¢ System.Web, System.Data, System.Collections, System.Xml etc [13]
ā¢ Source available at [16]
ā¢ Also includes libraries for winforms, WPF, WCF, ASP.NET, etc
ā¢ These other libraries are mostly still proprietary (and will probably remain so)
10
11. ADO.NET, ASP.NET, MVC, webforms, razor
ā¢ ADO.NET is a .NET Framework library to interact with (MSSQL)
database
ā¢ Entity Framework is ORM for ADO.NET
ā¢ ASP.NET is a .NET framework library to serve dynamic web pages [14]
ā¢ Typically hosted in IIS
ā¢ Pages are āWeb Formsā
ā¢ Has ācode behindā file and view file
ā¢ Pages need to be compiled like source code
11
12. ADO.NET, ASP.NET, MVC, webforms, razor
ā¢ ASP.NET cont
ā¢ MVC is an extension to ASP.NET that comes with Visual Studio
ā¢ Implements Model-View-Controller design pattern
ā¢ Methods for a page are handled in the controller, or somewhere else as defined in route
setup
ā¢ Can still include code in the view itself, same as before
ā¢ Razor is typically used with MVC
ā¢ Entire state of the webpage (āViewStateā) no longer needs to be passed around with every
server call
ā¢ Page is no longer re-rendered with every server call
ā¢ Views are compiled on demand and can be changed at runtime
ā¢ No more if (!IsPostback)
// generate form
else
// process submitted data;
12
13. ASP.NET visualized
.NET Framework
CLR BCL
FCL
ASP.NET
(WebForms)
ASP.NET extensions
MVC
Razor
ā¢ Extensions available through Visual Studio, elsewhere
13
14. Mono
ā¢ Started as open source C# compiler and CLR [15]
ā¢ āMonoā includes the mono libraries (e.g. POSIX and OS libraries),
Code Execution Engine, etc
ā¢ Alternative to .NET Framework
ā¢ MonoDevelop is the IDE
14
15. .NET core
ā¢ Cross platform, open source [17]
ā¢ Alternative to .NET framework
ā¢ CoreCLR
ā¢ Fork of FCL
ā¢ ASP.NET core
ā¢ Universal Windows Platform (UWP) libraries
ā¢ Adds additional libraries
ā¢ Missing some .NET Framework libraries
ā¢ Windows forms, WPF
ā¢ Adds deployment to have self contained applications (via AOT compilation)
[20]
15
17. .NET Standard
ā¢ Set of API specifications (guidelines, not code)
ā¢ Supposed to be supported by multiple frameworks [18]
ā¢ Version commentary about 1.6 -> 2.0 at [19]
17
18. .NET Standard
ā¢ Unifying library across platforms
ā¢ Mostly based on .NET Framework mscorlib (BCL, FCL, āand friendsā
[19])
ā¢ Binary compatible, not necessarily behavioral compatible
18
19. .NET FRAMEWORK .NET CORE XAMARIN
MONO
WPF
Windows
Forms
ASP.NET
UWP
ASP.NET
Core
iOS
OS X
Android
GTK#
.NET Standard
BCL FCL (partial?)
CLR CoreCLR Mono CLR
System.Runtime
*
Classes
Runtime
ā¢ Each framework has more libraries not shown (OS specific, compatibility, etc)
ā¢ Sticking to BCL and FCL is mostly cross platform, works well for simple console apps
POSIX
19
[21] https://stackoverflow.com/a/19403979/1462295
[22] https://www.codeproject.com/Articles/463508/NET-CLR-Injection-Modify-IL-Code-during-Run-time
Also, CIL assembly is rather straightforward to decompile back into code (at least for C#) so legacy binary fix doesnāt seem like the ideal use case