基础知识

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. CCF CSP 201412-4 最优灌溉

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201412-4 最优灌溉 问题描述 雷雷承包了很多片麦田,为了灌溉这些麦田,雷雷在第一个麦田挖 ...

  2. MFC+WinPcap编写一个嗅探器之一(准备)

    知识准备: MFC:http://www.jizhuomi.com/software/257.html WinPcap:http://www.ferrisxu.com/WinPcap/html/ind ...

  3. Rookey.Frame之实体类

    上周跟大家分享了Rookey.Frame框架的初始化功能,今天继续给大家介绍实体类的设计. 先看下下面菜单实体示例代码: using Rookey.Frame.EntityBase; using Ro ...

  4. rabbit:Mnesia could not connect to any nodes

    环境: rabbitmq集群   2台机器,挂了一台后重启服务,发现在服务启动不了错误如下: 这里rabbit连接不商rabbit02这里这个服务也无法启动 解决办法: rabbitmq默认的数据库位 ...

  5. 深入理解Python生成器(Generator)

    我们可以通过列表生成式简单直接地创建一个列表,但是受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,而且如果我们仅仅需要访问前面几个元素,那后面绝大多 ...

  6. python 自带的range是不能实现对小数的操作的,如果要对小数操作可以使用numpy

    import numpy as np s = np.arange(0, 1, 0.1) print s [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]

  7. 线性表之单链表C++实现

    线性表之单链表 一.头文件:LinkedList.h //单链表是用一组任意的存储单元存放线性表的元素,这组单元可以是连续的也可以是不连续的,甚至可以是零散分布在内存中的任意位置. //单链表头文件 ...

  8. CF280C Game on Tree 期望

    期望多少次操作,我们可以看做是染黑了多少节点 那么,我们可以用期望的线性性质,求出每个节点被染黑的概率之和(权值为$1$) 一个节点$u$被染黑仅跟祖先有关 我们把$u$到祖先的链抽出来 只要选取链上 ...

  9. [Hdu4372] Count the Buildings

    [Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...

  10. 【推导】Codeforces Round #484 (Div. 2) C. Cut 'em all!

    题意:给你一棵树,让你切掉尽可能多的边,使得产生的所有连通块都有偶数个结点. 对于一棵子树,如果它有奇数个结点,你再从里面怎么抠掉偶数结点的连通块,它都不会变得合法.如果它本来就有偶数个结点,那么你怎 ...