基础知识

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. 1391: [Ceoi2008]order

    有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给出这些参数,求最大利润 Input 第一行给出 N,M( ...

  2. linux删除特殊字符命名的文件

    今天在服务器上不小心创建了一个!命名的文件还有一个\命名的文件,本来想用转义字符进行删除,又担心误删了项目文件....最后找到最好的解决办法 如下: ls -i  查看文件inum值 执行删除inum ...

  3. Web前端开发最佳实践(11):使用更严格的JavaScript编码方式,提高代码质量

    前言 JavaScript语言由于其固有的灵活性,所以导致开发者可以写出很多诡异的代码,甚至一些较为正常的特性,如类型隐式转换.this的指代等等,也会让刚接触此语言的开发者头大不已.尤其是那些熟知其 ...

  4. USACO 5.2 Snail Trails

    Snail TrailsAll Ireland Contest Sally Snail likes to stroll on a N x N square grid (1 <n <= 12 ...

  5. ref:详解MYSQL数据库密码的加密方式及破解方法

    ref:https://blog.csdn.net/paul123456789io/article/details/53081921 MySQL数据库用户密码跟其它数据库用户密码一样,在应用系统代码中 ...

  6. 20169211《Linux内核原理及分析》第十二周作业

    Collabtive 系统 SQL 注入实验 实验介绍 SQL注入漏洞的代码注入技术,利用web应用程序和数据库服务器之间的接口.通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串, ...

  7. 在 Pandas 中更改列的数据类型

    import pandas as pd import numpy as np a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0' ...

  8. python list的应用

    先看下面的操作 In [2]: lis = [(1,2),(3,4),(5,6)] In [3]: for a,b in lis: ...: if a == 1: ...: print (" ...

  9. [ 转载 ] Java基础11--Java总结篇系列:Java泛型

    一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(Stri ...

  10. opencv 掩膜操作 滤波 卷积核定义 增强对比度 掩膜运算

    /* 矩阵的掩膜操作 0 掩膜mask 在这里进行增强对比度: [ [ 0,-1, 0 ], [-1, 5, -1], [ 0,-1, 0 ] ] 使用mask滑动图片每一个位置,进行卷积运算 这里这 ...