Expert. NET 2.0 il interpreter notes

Source: Internet
Author: User
Tags types of tables

I wanted to put it behind each chapter of the translation and write it into chapter 5th, so I found that it was a dog-slogan. My skill is too different from the original author. I 'd like to put it in my own place.

Source code:

Http://www.apress.com/book/downloadfile/3046 (original book)

Http://www.cnblogs.com/Jax/archive/2008/12/30/1365685.html (my blog, without any changes)

 

Chapter 2

This chapter is very practical:

If the reader just wants to get a preliminary understanding of Il, it is enough to finish chapter 1. At the same time, you can determine whether to continue reading based on your own needs.

The underlying operating mechanism of CLR is just a start here. The following chapters will be more detailed. If you think it is not enough, you can read Jeffrey's "CLR via C #" first. After all, this book is from the perspective of C #, which is more practical and not as boring as this book.

In this chapter, the example for determining the parity is worth a bit of detail. Readers should use this small example to change their ideas-to get rid of the shackles of advanced languages, and to think about problems from the perspective of assembly languages. For example, you can see console. Readline () and console. writeline (), respectively, think of the logic of stack entry and stack exit.

In addition, to distinguish between commands and pseudo commands, we recommend that you use the open-source ide tool sharpdevelop to open the IlProgramThe two statements are highlighted in different colors (in sharpdevelop1.1, the command is in blue and the pseudo command is in green ). In my experience, declarative statements are all pseudo commands, and operations involving inbound and outbound stacks are all commands.

To sum up, to learn or study Il, you must learn a little assembly language in advance.

 

Chapter 2CodeCompression and code protection

Code compression involves commands in the form of long parameters and short parameters. Using Short parameters instead of long parameters seems a bit tricky. Isn't that just a few bytes saved? However, for the assembler, these bytes are very important. For more information about commands, see Chapter 13th.

Code Protection refers to the Il exception handling mechanism. Don't be surprised that assembly languages also have structured exception handling (EH), because il itself is also an OO language. The leave command is amazing! Note that there are strict restrictions on the end and start of the eh block. For more information about eh, see Chapter 14th.

 

Chapter 2 optimization code

The alias mechanism is also available in Il. It can be applied to classes, methods, fields, or custom features. The. typedef keyword. Aliases survive In bidirectional resolution (especially disassembly) because they are not part of the metadata.

# Define sym1 "sometext" -- this set of technologies is also available in C #. You can compare them.

The most amazing thing is that there are also. This and. Base in Il.

 

Chapter 2 PE Header

This chapter is the most difficult part in this book. Because it involves a large number of technologies, especially some non-hosted terms, and many Assembly-level concepts. This is a huge obstacle for readers who are dedicated to hosting application development only. I try my best to explain every term and compare it with English. These terms will appear in the following chapters, so please be sure to understand that Google is a quick way to get online.

It is critical to clarify the flowchart and structure diagram introduced in this chapter. It is the best way to learn to write a program and decompile it.

It is also important to understand how the Il assembler creates a hosted PE file.

The best way to learn is to read the structure of the PE Header according to the content in the book. For more information, see Vijay mukhi'sMetadata tablesI re-typed the C # code on my blog:

Http://www.cnblogs.com/Jax/archive/2009/01/02/1366897.html

Chapter 4 metadata table

Definition of metadata-data that describes data. The most important thing in the book. This chapter provides an overview.

Metadata is a two-dimensional table. Each column in the table contains data or references to a row in another table. These two types of tables are in the stream format in EXE or DLL, and need to be parsed by convection. Even ildsam shows the resolution result as a cascading relationship, but cannot see the two types of tables.

The metadata structure of a module is either optimized or not optimized:

Optimized metadata: records in the method table are sorted based on their parent classes. However, due to the random metadata outflow or incremental compilation results, it is possible to store sub-tables with different parent classes.

Unoptimized metadata: the metadata of the intermediate retrieval table is used to provide non-crossover retrieval tables sorted by their fathers.

Metadata is represented as a group of celebrities, and each stream represents a type of metadata. These streams are divided into two types: Metadata heap and metadata table.

Metadata heap is a storage area of the trivial structure. It stores ordered storage items. In metadata, heap is used to store strings and binary objects. Metadata heap is divided into the following three types:

StringHeap

GuidHeap

Blob heap

A general metadata header consists of a storage signature and a storage header. Next to the storage header is the stream header array, where the rcname field stores the stream name.

There are six types of celebrities in metadata:

# StringsA String Heap that includes the metadata Item Name (Class Name, method name, field name, and so on. This stream does not include the literal constants defined or referenced in the module's methods.

# BlobIncludes the Blob heap of an internal metadata binary object similar to the default value and signature.

# GuidGuid heap includes various globally unique identifiers.

# UsIncludes the Blob heap of the User-Defined string.

#~The compressed (optimized) Metadata stream.

#-Uncompressed (unoptimized) metadatabase data streams.

Metadata table stream

The header structure of the metadata table stream, the descriptor structure of the metadata table, and the column descriptor structure of the metadata table.

There is a field in the column that identifies the type encoding of the column:

0-63 45 most common tables (0-44) and 19 slave tables.

64-95 is used to place tags. They are used internally and are a combination of the RID and table indexes. There are 13 available (64-76) and 19 available.

Chapter 4 assembly and module

This chapter describes CLR in sections 1, 2, 3, and 7 and has nothing to do with IL.

Appdomain: This is too simple. For more information, seeCLR via C #Chapter 2.

In the configuration manifest, three metadata tables are used only for the configuration tables: Assembly, exportedtype, and declsecurity.

The Assembly metadata table contains at most one record, which appears in the metadata of the main module. This table is not widely used, so it is very simple.

Assemblyref

Automatic Detection Technology: the use of the auto keyword. Note that this keyword can be combined with some specified parameters and can only be used for the Assembly in GAC.

The module metadata table contains only one record. It provides the identifier of the current module. Only one field can be explicitly set (Name field ).

The managed methods in the assemblyref metadata table and the records in the file metadata table are one-to-many. The unmanaged method does not have paired file records.

The manifestresource metadata table describes the structure of managed resources. Note that you cannot use Il to manage resources. You only need to use APIs, such as some methods in C.

Exportedtype metadata table contains information about the public classes declared in the non-main modules of the Assembly (visible outside the Assembly.

Classes defined in the main module and classes defined in the exportedtype table must be empty at the intersection.

The class "forwarder" (forwarder), pointing out which Assembly's XX class (once resident in this Assembly) was removed, Based on. NET 2.0.

The order of list declarations in ilasm: In line with the principle of "first declaration, then reference,

1. assemblyref Declaration (. Assembly extern)

2. moduleref Declaration (. Module extern)

3. Assembly Declaration (. Assembly)

4. File Declaration (. File)

5. exportedtype Declaration (. Class extern)

6. manifestresource Declaration (. mresource)

Microsoft's Visual Studio is also harmful. It can only generate a single-Module assembly, so that programmers generally cannot clearly distinguish between the Assembly and the module. Multi-Module assembly can only be generated by manually setting the compiler option. There is a lot of information on this technology-that is, the Al tool.

Chapter 2 class and namespace

After reading this chapter, you can talk to others:

1. type is divided into value type and reference type

2. reference types include object type, interface type, and pointer type, where:

Object type, that is, class, is a type of full or partial self-descriptive value. An abstract class is a type with some self-Descriptive values. The interface type is part of the self-description value type. Interfaces usually represent a subset of behavior characteristics exposed by classes, while classes implement their own interfaces. The pointer type is only a reference to the item, indicating the position of the item.

-- This is not a strange idea, but a CLI standard. However, people who have been at the C # level for a long time may not be able to accept it at the moment.

This chapter covers four metadata tables: typedef, typeref, nestedclass, and classlayout. The classlayout meta-data table should be carefully studied, because we usually do not have much contact with it.

The namespace is not a metadata item. You can use single quotes to avoid full-class name Ambiguity Caused by multiple periods.

Static methods can be implemented in the Il interface, which is not allowed in C.

Class extension technology can be considered as the partial class (partial classification) in C # -- at least I think so.

Enumeration, for example, Enum color {Red = 1, white = 2} corresponds to Il:

As you can see, enumeration is only a structure in which a series of constant fields and instance fields are defined.
If you only use a type such as color. Red, it will be processed as a constant, so that the Code does not reference the defined Enumeration type, you can delete the corresponding DLL (See Chapter 7th );
If the syntax such as color C = new color (); is used, it depends on references and cannot delete the corresponding DLL.

Chapter 2 Basic Types and signatures

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.