Metadata is stored in one area of the PE file, while msil is stored in another area of the PE file. The metadata section contains a series of tables and heaps. The msil part contains the Il language and metadata tags that point to a row of a table in the metadata part or to a heap.
Metadata table and heap
A metadata table contains various information about a program, such as a table that describes various classes in the program, and another table that describes fields in various classes. If there are 10 classes in your code, there will be 10 rows in the class table, each row corresponds to a class. At the same time, the class table also references other tables and heaps. For example, the class Table references the method definition table.
Metadata also stores information in the heap structure. There are four heap structures: String, blob, user string, and guid. All strings used for Naming types and members are stored in the String Heap. For example, a method table does not store the name of a method directly, but instead points a pointer to the place where the method name is stored in the String Heap.
Metadata ID:
The metadata identifiers in msil are unique and point to a row in a specific metadata table. Each metadata representation is a 4-byte number. The first byte is used to describe which table points to the metadata, and the last three bytes are used to indicate which row points to the table, that is, the offset in the table. For example, if the number of the method definition table is 0x06, 0x06000004 points to the fourth row of the method definition table.
Metadata in the PE file:
After a C # program is compiled, a PE file is generated, which contains three parts. The following table describes the content of each part: