Assembly definition
Under the. NET Framework, high-level languages such as C # are compiled with the resulting file as an assembly (with a suffix of. exe or. dll).
Composition of assemblies
- Pe/coff header enables the Windows operating system to load and run
- The CLR header tells the system to be. NET assembly
- Manifest (manifest) assembly identity can be viewed by anti-compilation
- Metadata content includes modules, types, and so on that the assembly contains
- CIL code
- Resource file
Assembly Anti-compilation
- Compile the CS file with the "vs Developer command Prompt".
csc MyClass.csCompile commands, parameters that can be set for compilation
parameter type
| |
|
| /t: |
library |
compiled as DLL library file |
| /out: |
myclass.dll |
output file |
| /r: |
myclass.dll |
referencing assemblies |
| /addmodule: |
myfirstmoduldle.netmodule |
load module |
| /resource: |
resourcedemo.resx |
load Resource |
| /keyfile: |
key |
encryption key | /tr>
- Assembly Anti-compilation CIL code
ildam /out:1.txt MainClass.exeYou can decompile the MainClass.exe assembly to a 1.txt file.
| instruction Name |
Sample Example |
meaning |
| . assembly extern |
mscorlib |
Referenced assemblies |
| . Assembly |
MainClass |
Current Assembly |
| . module |
MainClass.exe |
Current module |
| . file |
Myfirstmodule.netmodule |
Reference module |
Multi-Module assemblies
Assemblies compiled with VS are all but module assemblies, but one assembly can contain multiple modules. The new MyFirstMOdule.cs MySecondModule.cs file is compiled as a module, MainClass references.
using System;class MyFirstModule{ public static void Hello() { Console.WriteLine("Hello,I am from Module 1"); }}
using System;class MySecondModule{ public static void Hello() { Console.WriteLine("Hello,I am from Module 2"); }}
using System;class MainClass{ static void Main() { MyFirstModule.Hello(); }}
Compile Commands csc /t:module /out:MyFirstModule.netmodule MyFirstModule.cs , csc /t:module /out:MySecondModule.netmodule MySecondModule.cscsc /addmodule:MyFirstModule.netmodule,MySecondModule.netmodule MainClass.cs
Using the benefits of the module, the runtime can delete modules that are not needed, thus reducing the load on the module. (However, the author recommends using multiple small assemblies)
Strong Name Assemblies
- Version of the Assembly
Specifies the version for the Assembly, which makes it easy to change later.
Use the public/private key to prevent the assembly from being tampered with
Compile your own class library with a key to prevent others from faking it and not running it. This is a bit confusing, if you decompile the encrypted DLL file to txt, modify the content in the and extension IL, and then edit it as a DLL, you can tamper with it.
Global Assembly CacheAdding multiple referenced DLL assemblies to the global cache increases efficiency. Add buffers gacutil i MyClass.dll and exit buffersgacutil u MyClass.dll
. NET Beauty Reading notes 6