基础知识

A managed PE file has four main parts: the PE32(+) header, the CLR header, the metadata, and the IL. The PE32(+) header is the standard information that Windows expects. The CLR header is a small block of information that is specific to modules that require the CLR (managed modules). The header includes the major and minor version number of the CLR that the module was built for: some flags, a MethodDef token (described later) indicating the module’s entry point method if this module is a CUI, GUI, or Windows Store executable, and an optional strong-name digital signature. Finally, the header contains the size and offsets of certain metadata tables contained within the module.

The metadata is a block of binary data that consists of several tables. There are three categories of tables: definition tables, reference tables, and manifest tables. T

Metadata table entries are also created as the compiler detects the types, fields, methods, properties, and events that the source code references. The metadata created includes a set of reference tables that keep a record of the referenced items.

示例

C# 代码

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Main
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Type.GetType("A.ClassA, A"));
}
} public class ClassMain
{
public string Property { get; set; } public void Method(string msg)
{
Console.WriteLine(msg);
}
}
}

元数据

 ===========================================================
ScopeName : Main.exe
MVID : {8C836651-F32E-4341-B87A-3479E4412916}
===========================================================
Global functions
------------------------------------------------------- Global fields
------------------------------------------------------- Global MemberRefs
------------------------------------------------------- TypeDef #1 (02000002)
-------------------------------------------------------
TypDefName: Main.Program (02000002)
Flags : [NotPublic] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100000)
Extends : 01000001 [TypeRef] System.Object
Method #1 (06000001) [ENTRYPOINT]
-------------------------------------------------------
MethodName: Main (06000001)
Flags : [Private] [Static] [HideBySig] [ReuseSlot] (00000091)
RVA : 0x00002050
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
ReturnType: Void
1 Arguments
Argument #1: SZArray String
1 Parameters
(1) ParamToken : (08000001) Name : args flags: [none] (00000000) Method #2 (06000002)
-------------------------------------------------------
MethodName: .ctor (06000002)
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] [RTSpecialName] [.ctor] (00001886)
RVA : 0x00002063
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
No arguments. TypeDef #2 (02000003)
-------------------------------------------------------
TypDefName: Main.ClassMain (02000003)
Flags : [Public] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100001)
Extends : 01000001 [TypeRef] System.Object
Field #1 (04000001)
-------------------------------------------------------
Field Name: <Property>k__BackingField (04000001)
Flags : [Private] (00000001)
CallCnvntn: [FIELD]
Field type: String
CustomAttribute #1 (0c000001)
-------------------------------------------------------
CustomAttribute Type: 0a000008
CustomAttributeName: System.Runtime.CompilerServices.CompilerGeneratedAttribute :: instance void .ctor()
Length: 4
Value : 01 00 00 00 > <
ctor args: () Method #1 (06000003)
-------------------------------------------------------
MethodName: get_Property (06000003)
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] (00000886)
RVA : 0x0000206c
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: String
No arguments.
CustomAttribute #1 (0c000006)
-------------------------------------------------------
CustomAttribute Type: 0a000008
CustomAttributeName: System.Runtime.CompilerServices.CompilerGeneratedAttribute :: instance void .ctor()
Length: 4
Value : 01 00 00 00 > <
ctor args: () Method #2 (06000004)
-------------------------------------------------------
MethodName: set_Property (06000004)
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] (00000886)
RVA : 0x00002083
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
1 Arguments
Argument #1: String
1 Parameters
(1) ParamToken : (08000002) Name : value flags: [none] (00000000)
CustomAttribute #1 (0c000007)
-------------------------------------------------------
CustomAttribute Type: 0a000008
CustomAttributeName: System.Runtime.CompilerServices.CompilerGeneratedAttribute :: instance void .ctor()
Length: 4
Value : 01 00 00 00 > <
ctor args: () Method #3 (06000005)
-------------------------------------------------------
MethodName: Method (06000005)
Flags : [Public] [HideBySig] [ReuseSlot] (00000086)
RVA : 0x0000208c
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
1 Arguments
Argument #1: String
1 Parameters
(1) ParamToken : (08000003) Name : msg flags: [none] (00000000) Method #4 (06000006)
-------------------------------------------------------
MethodName: .ctor (06000006)
Flags : [Public] [HideBySig] [ReuseSlot] [SpecialName] [RTSpecialName] [.ctor] (00001886)
RVA : 0x00002096
ImplFlags : [IL] [Managed] (00000000)
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
No arguments. Property #1 (17000001)
-------------------------------------------------------
Prop.Name : Property (17000001)
Flags : [none] (00000000)
CallCnvntn: [PROPERTY]
hasThis
ReturnType: String
No arguments.
DefltValue:
Setter : (06000004) set_Property
Getter : (06000003) get_Property
0 Others TypeRef #1 (01000001)
-------------------------------------------------------
Token: 0x01000001
ResolutionScope: 0x23000001
TypeRefName: System.Object
MemberRef #1 (0a000007)
-------------------------------------------------------
Member: (0a000007) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
No arguments. TypeRef #2 (01000002)
-------------------------------------------------------
Token: 0x01000002
ResolutionScope: 0x23000001
TypeRefName: System.Runtime.Versioning.TargetFrameworkAttribute
MemberRef #1 (0a000001)
-------------------------------------------------------
Member: (0a000001) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
1 Arguments
Argument #1: String TypeRef #3 (01000003)
-------------------------------------------------------
Token: 0x01000003
ResolutionScope: 0x23000001
TypeRefName: System.Diagnostics.DebuggableAttribute
MemberRef #1 (0a000002)
-------------------------------------------------------
Member: (0a000002) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
1 Arguments
Argument #1: ValueClass DebuggingModes TypeRef #4 (01000004)
-------------------------------------------------------
Token: 0x01000004
ResolutionScope: 0x01000003
TypeRefName: DebuggingModes TypeRef #5 (01000005)
-------------------------------------------------------
Token: 0x01000005
ResolutionScope: 0x23000001
TypeRefName: System.Runtime.CompilerServices.CompilationRelaxationsAttribute
MemberRef #1 (0a000003)
-------------------------------------------------------
Member: (0a000003) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
1 Arguments
Argument #1: I4 TypeRef #6 (01000006)
-------------------------------------------------------
Token: 0x01000006
ResolutionScope: 0x23000001
TypeRefName: System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
MemberRef #1 (0a000004)
-------------------------------------------------------
Member: (0a000004) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
No arguments. TypeRef #7 (01000007)
-------------------------------------------------------
Token: 0x01000007
ResolutionScope: 0x23000001
TypeRefName: System.Type
MemberRef #1 (0a000005)
-------------------------------------------------------
Member: (0a000005) GetType:
CallCnvntn: [DEFAULT]
ReturnType: Class System.Type
1 Arguments
Argument #1: String TypeRef #8 (01000008)
-------------------------------------------------------
Token: 0x01000008
ResolutionScope: 0x23000001
TypeRefName: System.Console
MemberRef #1 (0a000006)
-------------------------------------------------------
Member: (0a000006) WriteLine:
CallCnvntn: [DEFAULT]
ReturnType: Void
1 Arguments
Argument #1: Object
MemberRef #2 (0a000009)
-------------------------------------------------------
Member: (0a000009) WriteLine:
CallCnvntn: [DEFAULT]
ReturnType: Void
1 Arguments
Argument #1: String TypeRef #9 (01000009)
-------------------------------------------------------
Token: 0x01000009
ResolutionScope: 0x23000001
TypeRefName: System.Runtime.CompilerServices.CompilerGeneratedAttribute
MemberRef #1 (0a000008)
-------------------------------------------------------
Member: (0a000008) .ctor:
CallCnvntn: [DEFAULT]
hasThis
ReturnType: Void
No arguments. Signature #1 (0x11000001)
-------------------------------------------------------
CallCnvntn: [LOCALSIG]
1 Arguments
Argument #1: String Assembly
-------------------------------------------------------
Token: 0x20000001
Name : Main
Public Key :
Hash Algorithm : 0x00008004
Version: 0.0.0.0
Major Version: 0x00000000
Minor Version: 0x00000000
Build Number: 0x00000000
Revision Number: 0x00000000
Locale: <null>
Flags : [none] (00000000)
CustomAttribute #1 (0c000002)
-------------------------------------------------------
CustomAttribute Type: 0a000001
CustomAttributeName: System.Runtime.Versioning.TargetFrameworkAttribute :: instance void .ctor(class System.String)
Length: 73
Value : 01 00 1a 2e 4e 45 54 46 72 61 6d 65 77 6f 72 6b > .NETFramework<
: 2c 56 65 72 73 69 6f 6e 3d 76 34 2e 35 01 00 54 >,Version=v4.5 T<
: 0e 14 46 72 61 6d 65 77 6f 72 6b 44 69 73 70 6c > FrameworkDispl<
: 61 79 4e 61 6d 65 12 2e 4e 45 54 20 46 72 61 6d >ayName .NET Fram<
: 65 77 6f 72 6b 20 34 2e 35 >ework 4.5 <
ctor args: (".NETFramework,Version=v4.5") CustomAttribute #2 (0c000003)
-------------------------------------------------------
CustomAttribute Type: 0a000002
CustomAttributeName: System.Diagnostics.DebuggableAttribute :: instance void .ctor(value class DebuggingModes)
Length: 8
Value : 01 00 07 01 00 00 00 00 > <
ctor args: ( <can not decode> ) CustomAttribute #3 (0c000004)
-------------------------------------------------------
CustomAttribute Type: 0a000003
CustomAttributeName: System.Runtime.CompilerServices.CompilationRelaxationsAttribute :: instance void .ctor(int32)
Length: 8
Value : 01 00 08 00 00 00 00 00 > <
ctor args: (8) CustomAttribute #4 (0c000005)
-------------------------------------------------------
CustomAttribute Type: 0a000004
CustomAttributeName: System.Runtime.CompilerServices.RuntimeCompatibilityAttribute :: instance void .ctor()
Length: 30
Value : 01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78 > T WrapNonEx<
: 63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01 >ceptionThrows <
ctor args: () AssemblyRef #1 (23000001)
-------------------------------------------------------
Token: 0x23000001
Public Key or Token: b7 7a 5c 56 19 34 e0 89
Name: mscorlib
Version: 4.0.0.0
Major Version: 0x00000004
Minor Version: 0x00000000
Build Number: 0x00000000
Revision Number: 0x00000000
Locale: <null>
HashValue Blob:
Flags: [none] (00000000) User Strings
-------------------------------------------------------
70000001 : (11) L"A.ClassA, A" Coff symbol name overhead: 0
===========================================================
===========================================================
===========================================================

.NET:CLR via C# A Brief Look at Metadata的更多相关文章

  1. 第一节:CLR寄宿

    本系列文章来自 CLR VIA C# .NET FrameWork在Microsoft  Windows平台的顶部运行.这意味着.NET必须用Windows可以理解的技术来构建.首先,所有的托管模块和 ...

  2. 解决“ 故障模块名称: clr.dll ”

    错误内容: 微软的错误说明:http://support.microsoft.com/kb/2640103/zh-cn 类似下面的错误: 错误应用程序名称:xxx.exe,版本: 1.0.0.0,时间 ...

  3. CLR via C#读书笔记一:CLR的执行模型

    CLR(Common Language Runtime)公共语言进行时是一个可由多种编程语言使用的“进行时”. 将源代码编译成托管模块 可用支持CLR的任何语言创建源代码文件,然后用对应的编译器检查语 ...

  4. .NET:CLR via C# Compute-Bound Asynchronous Operations

    线程槽 使用线程池了以后就不要使用线程槽了,当线程池执行完调度任务后,线程槽的数据还在. 测试代码 using System; using System.Collections.Generic; us ...

  5. .NET:CLR via C# The CLR’s Execution Model

    The CLR’s Execution Model The core features of the CLR memory management. assembly loading. security ...

  6. [C#] 类型学习笔记一:CLR中的类型,装箱和拆箱

    在学习.NET的时候,因为一些疑问,让我打算把.NET的类型篇做一个总结.总结以三篇博文的形式呈现. 这篇博文,作为三篇博文的第一篇,主要探讨了.NET Framework中的基本类型,以及这些类型一 ...

  7. 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的

    异常原因: 1.写了一个死循环,这个可能性最大. 2.进行大数据量的运算,导致假死状况. 解决办法:Debug -> Exceptions -> Managed Debug Assista ...

  8. .NET:CLR via C# User-Mode Constructs

    The CLR guarantees that reads and writes to variables of the following data types are atomic: Boolea ...

  9. .NET:CLR via C# Primitive Thread Synchronization Constructs

    User-Mode Constructs The CLR guarantees that reads and writes to variables of the following data typ ...

随机推荐

  1. **PHP转义Json里的特殊字符的函数

    http://www.banghui.org/11332.html 在给一个 App 做 API,从服务器端的 MySQL 取出数据,然后生成 JSON.数据中有个字段叫 content,里面保存了文 ...

  2. 常用网络命令(windows)

      Ping命令的常用参数选项 ·ping IP –t 连续对IP地址执行Ping命令,直到被用户以Ctrl+C中断. ·ping IP -l 3000 指定Ping命令中的数据长度为3000字节,而 ...

  3. 9-4 Unidirectional TSP uva116 (DP)

    题意:给一个n行m列矩阵    从第一列任意一个位置出发 每次往右 右上 右下三个方向走一格 直到最后一列   输出所类和的最小值和路径!! 最小值相同则输出字典序最小路径 很像一开始介绍的三角形dp ...

  4. RabbitMQ路由类型

    关于RabbitMQ的Exchange类型 参考地址:<RabbitMQ学习系列(四): 几种Exchange 模式> github地址:https://github.com/ChenWe ...

  5. xshell连接不上linux问题

    1.首先确定linux系统有网络. 使用ipconfig查看是否有ip地址,没有的话需要先配置. 2.打开sshd服务:service sshd start 3.关闭防火墙服务:service ipt ...

  6. [ 转载 ] js十大排序算法:冒泡排序

    js十大排序算法:冒泡排序  http://www.cnblogs.com/beli/p/6297741.html

  7. Qt Quick快速入门之信号、槽

    信号和槽主要用于组件之间的通信,类似于.net和java中的委托. 使用QObject::connect方法将信号与槽关联起来,然后信号的发起者发出信号,接受者中的槽函数就会执行. 比如connect ...

  8. 【二分答案】Google Code Jam Round 1A 2018

    题意:有R个机器人,去买B件商品,有C个收银员,每个收银员有能处理的商品数量上限mi,处理单件商品所需的时间si,以及最后的装袋时间pi. 每个收银员最多只能对应一个机器人,每个机器人也最多只能对应一 ...

  9. Apache2.4使用require指令进行访问控制--允许或限制IP访问/通过User-Agent禁止不友好网络爬虫

    从Apache2.2.X到Apache2.4.X,在配置上稍微有点不同,需要特别注意.现在记录下关于访问控制的配置. 经过苦苦搜索,终于配置成功.参考了这篇文章:http://www.cnblogs. ...

  10. HTML5 UI 控件Mobiscroll的使用(年月日三级联动)

    概述: 遇到制作一个html5界面,需要选择年月日,其实这个功能很常用.一般我们都是网上找,之前也没有收藏一个自己常用的,今天发现一个不错的库.特此记录一下使用过程,以便以后遇到了方面查阅. 1.官方 ...