. NET Framework Program Design-generate, package, deploy and manage applications and types (1: PE format of the Assembly)

Source: Internet
Author: User

. NET FrameworkProgramDesign-generate, package, deploy and manage applications and types (1: PE format of the Assembly)

(1). Net Framework deployment objectives
When talking about Microsoft's OS-Windows, many people may immediately think of her complexity and instability. A major reason is that DLLhell (DLL hell), which is hard to avoid running various programs on Windows) problems, as well as the complex installation process, as well as program transparency to the customer, so that the program can potentially execute broken LoopsCode, Modify the registry, send the customer's privacy, and so on.

. Net Framework for Application Deployment, improvement and even corrected the above problem: DLLhell basic solution (through simple copy, you can deploy the program, it can be said that it is a real green software ), the code access security model makes a huge step in program security. We (the program designer) can decide the security of the Assembly on our own, windows users can have more control over the installer.

(2) type generation module (. netmodule or EXE, DLL file (the latter two are Assembly ))

We can generate these modules by using compilers such as csc.exe.
(1) Cui (control user interface console interface application); for example: csc.exe app. CS
(2) gui (graph user interface GUI application); for example: CSC/Target: winexe app. CS
(3) DLL (Application assembly, which should be different from the previous DLL-dynamic connection library); for example: CSC/Target: Library app. CS
(4) netmodule (a single hosted module, which is not a simple collection of DLL, makes it more helpful for us to manage the type); for example: CSC/Target: module app. CS

Aside from netmodule, let's take a look at the formats of DLL and exe (Cui, Gui) content.

The EXE file generated by CSC is a standard (hosted) PE file that can run on 32-bit Windows platforms.

This managed PE includes:
(See http://www.cnblogs.com/caca/archive/2004/10/20/54810.html)

(1) PE Header
(This is a Windows application, of course not so simple)
(2) CLR Header
(It is specially used for hosting modules that require CLR to run, including the primary version and minor version number of metadata. If it is an EXE file, there is also a methoddef mark indicating the entry point method, and an optional strong-name digital signature, as well as the size and offset of some metadata tables. Check corhdr In SDK/include. use the image_cor20_header structure of h to obtain the correct CLR Header Format)

Typedef Struct Image_cor20_header
{
// Header Versioning
Ulong CB;
Ushort majorruntimeversion;
Ushort minorruntimeversion;

// Symbol table and startup information
Image_data_directory metadata;
Ulong flags;
Ulong entrypointtoken;

// Binding information
Image_data_directory resources;
Image_data_directory strongnamesignature;

// Regular fixup and binding information
Image_data_directory codemanagertable;
Image_data_directory vtablefixups;
Image_data_directory exportaddresstablejumps;

// Precompiled image info (internal use only-set to zero)
Image_data_directory managednativeheader;

} Image_cor20_header;

(3) Metadata

Metadata is a set of tables. These tables are divided into three types: defining tables, referencing tables, and listing tables:
Definition table: for example, moduledef, typedef, methoddef, fileddef, paramdef, propertydef, eventdef ......
Reference Table: for example, assemblyref, mouuleref, typeref, memberref ......
List table: such as assemblydef, assemblyref, filedef, manifestresoureedef, exportedtypesdef ......
(This table exists in the Assembly, not in. netmodule)
The list provides an indirect association between the Assembly user and each part, and enables the Assembly to implement self-description. The list records all other files in the Assembly, but other files do not know that they are part of an assembly.

(4) Il code

ProgramSource codeThe section in the braces {} In is compiled into the Il language.

(Attachment) For details, refer to the metainfo generated by Hello. CS (you can view it through the CTRL + M Shortcut of ildasm)

Public   Class Hello
{
Static VoidMain ()
{
System. Console. writeline ("Hello C # World!");
}
}

Scopename: hello.exe
Mvid: {BC0BB08E-E11D-4DAC-866B-A584C5C8CD1A}
========================================================== ==============================
Global Functions
-------------------------------------------------------

Global Fields
-------------------------------------------------------

Global memberrefs
-------------------------------------------------------

typedef #1
Frequency
typdefname: Hello (02000002)
flags: [public] [autolayout] [Class] [ansiclass] (00100001)
extends: 01000001 [typeref] system. object
method #1 [entrypoint]
-----------------------------------------------------
methodname: Main (06000001)
flags: [private] [static] [hidebysig] [reuseslot] (00000091)
RVA: 0x00002050
implflags: [il] [managed] (00000000)
callcnvntn: [Default]
returntype: void
no arguments.

method #2
-------------------------------------------------------
methodname :. ctor (06000002)
flags: [public] [hidebysig] [reuseslot] [specialname] [rtspecialname] [. ctor] (00001886)
RVA: 0x00002068
implflags: [il] [managed] (00000000)
callcnvntn: [Default]
hasthis
returntype: void
no arguments.

typeref #1 (01000001)
---------------------------------------------------
token: 0x01000001
resolutionscope: 0x23000001
typerefname: system. object
memberref #1
-----------------------------------------------------
Member: (0a000003 ). ctor:
callcnvntn: [Default]
hasthis
returntype: void
no arguments.

typeref #2 (01000002)
---------------------------------------------------
token: 0x01000002
resolutionscope: 0x23000001
typerefname: system. diagnostics. debuggableattribute
memberref #1
-------------------------------------------------------
Member: (0a000001 ). ctor:
callcnvntn: [Default]
hasthis
returntype: void
2 arguments
argument #1: Boolean
argument #2: boolean

Typeref #3 (01000003)
-------------------------------------------------------
Token: 0x01000003
Resolutionscope: 0x23000001
Typerefname: system. Console
Memberref #1
-------------------------------------------------------
Member: (0a000002) writeline:
Callcnvntn: [Default]
Returntype: void
1 arguments
Argument #1: String

Assembly
-------------------------------------------------------
Token: 0x20000001
Name: Hello
Public Key:
Hash Algorithm: 0x00008004
Major version: 0x00000000
Minor version: 0x00000000
Build number: 0x00000000
Revision number: 0x00000000
Locale: <null>
Flags: [sidebysidecompatible] (00000000)
Customattribute #1 (0c000001)
-------------------------------------------------------
Customattribute type: 0a000001
Customattributename: system. Diagnostics. debuggableattribute: instance void. ctor (bool, bool)
Length: 6
Value: 01 00 00 01 00> <
Ctor ARGs: (<can not decode>)

Assemblyref #1
-------------------------------------------------------
Token: 0x23000001
Public Key or token: B7 7A 5C 56 19 34 E0 89
Name: mscorlib
Major version: 0x00000001
Minor version: 0x00000000
Build number: 0x00001388
Revision number: 0x00000000
Locale: <null>
Hashvalue BLOB:
Flags: [none] (00000000)

User strings
-------------------------------------------------------
70000001: (16) l "Hello C # World! "

Part II: . net Framework Program Design-generate, package, deploy and manage applications and types (2: Generate assembly and Version Information)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.