CLR在加载程序集的时候会查看程序集清单,程序集清单包含哪些内容呢?可执行文件和程序集有什么区别/

程序集清单

□ 查看程序集清单

→清空F盘as文件夹中的所有内容
→创建MainClass.cs文件
→把MainClass.cs编译成程序集

→反编译MyDll.dll,在1.txt文件中呈现

ildasm /out:1.txt MyDll.dll

→打开1.txt文件

1.txt
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly MyDll
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 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.
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module MyDll.dll
// MVID: {7BE59AA1-0AE6-426E-B77D-5B85AB4B163F}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00A00000

// *********** 反汇编完成 ***********************
// 警告: 创建了 Win32 资源文件 1.res


○ .assembly extern mscorlib,不管MainClass.cs中有没有代码,一定会引用mscorlib程序集
○ .assembly MyDll语句块中的内容就是程序集清单,manifest
○ .hash algorithm 0x00008004和.ver 0:0:0:0是程序集清单中2个重要的方面

□ 查看module清单

→把MainClass.cs编译成module

csc /t:module /out:MyModule.netmodule MainClass.cs

→反编译MyModule,在2.txt文件中打开

ildasm /out:2.txt MyModule.netmodule

→打开2.txt文件

2.txt
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.module MyModule.netmodule
// MVID: {17B1ABDD-85D4-42F8-AF6D-07B860FCADEC}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00260000

.custom ([mscorlib]System.Runtime.CompilerServices.AssemblyAttributesGoHere) instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 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.
// *********** 反汇编完成 ***********************


○ 以上只有mscorlib这个程序集的清单。

DLL和EXE的区别

→删除F盘as文件夹中除了MainClass.cs之外的所有文件
→用记事本打开MainClass.cs文件,修改如下,保存

using System;

class MainClass
{
    static void Main()
    {
        Console.WriteLine("Hello World");
    }
}


→编译MainClass.cs,生成MainClass.exe文件

csc MainClass.cs

→运行MainiClass.exe

MainClass.exe

→编译MainClass.cs,生成MainClass.dll文件

csc  /t:library MainClass.cs

→反编译MainClass.exe,在1.txt文件中显示

ildasm /out:1.txt MainClass.exe

→打开1.txt文件

1.txt
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly MainClass
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 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.
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module MainClass.exe
// MVID: {1FD51DE8-5CD3-4408-AAB2-630AA5482E23}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x003B0000


// =============== CLASS MEMBERS DECLARATION ===================

.class private auto ansi beforefieldinit MainClass
       extends [mscorlib]System.Object
{
  .method private hidebysig static void  Main() cil managed
  {
    .entrypoint
    // 代码大小       13 (0xd)
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldstr      "Hello World"
    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_000b:  nop
    IL_000c:  ret
  } // end of method MainClass::Main

  .method public hidebysig specialname rtspecialname
          instance void  .ctor() cil managed
  {
    // 代码大小       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method MainClass::.ctor

} // end of class MainClass


// =============================================================

// *********** 反汇编完成 ***********************
// 警告: 创建了 Win32 资源文件 1.res


→反编译MainClass.dll,在2.txt文件中显示

ildasm /out:2.txt MainClass.dll

→打开2.txt文件

2.txt
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly MainClass
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 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.
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module MainClass.dll
// MVID: {765C3610-5865-4A53-995C-22B24BDCAEDE}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00370000


// =============== CLASS MEMBERS DECLARATION ===================

.class private auto ansi beforefieldinit MainClass
       extends [mscorlib]System.Object
{
  .method private hidebysig static void  Main() cil managed
  {
    // 代码大小       13 (0xd)
    .maxstack  8
    IL_0000:  nop
    IL_0001:  ldstr      "Hello World"
    IL_0006:  call       void [mscorlib]System.Console::WriteLine(string)
    IL_000b:  nop
    IL_000c:  ret
  } // end of method MainClass::Main

  .method public hidebysig specialname rtspecialname
          instance void  .ctor() cil managed
  {
    // 代码大小       7 (0x7)
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method MainClass::.ctor

} // end of class MainClass


// =============================================================

// *********** 反汇编完成 ***********************
// 警告: 创建了 Win32 资源文件 2.res


MainClass.exe和MainClass.dll在IL上的不同体现在:
○ EXE有程序的入口店.entrypoint,而DLL没有
○ EXE的modlue名称为MainClass.exe,DLL的module名称为MainClass.dll

“C#程序集系列”包括:

C#程序集系列01,用记事本编写C#,IL代码,用DOS命令编译程序集,运行程序

C#程序集系列02,使用记事本查看可执行程序集的IL代码

C#程序集系列03,引用多个module

C#程序集系列04,在程序集包含多个module的场景下理解关键字internal

C#程序集系列05,让程序集包含多个module

C#程序集系列06,程序集清单,EXE和DLL的区别

C#程序集系列07,篡改程序集

C#程序集系列08,设置程序集版本

C#程序集系列09,程序集签名

C#程序集系列10,强名称程序集

C#程序集系列11,全局程序集缓存

C#程序集系列12,C#编译器和CLR如何找寻程序集

C#程序集系列13,如何让CLR选择不同版本的程序集

参考资料:

http://www.computersciencevideos.org/  created by Jamie King

C#程序集系列06,程序集清单,EXE和DLL的区别的更多相关文章

  1. .NET配置引用程序集的路径(分离exe和dll)

    按照引用程序集路径的不同,程序集DLL分为两类: 1)全局DLL(在GAC中注册,GAC——全局程序集缓存),有关GAC的详细资料可以参考一下链接: http://dddspace.com/2011/ ...

  2. C#程序集系列13,如何让CLR选择不同版本的程序集

    本篇主要体验,在存在多个版本程序集的情况下,如何让CLR选择哪个版本程序集运行,以及程序集版本的切换. 分别生成非强名称程序集不同版本 □ 生成某个版本的程序集 →清理F盘as文件夹,剩下如下文件 → ...

  3. C#程序集系列12,C#编译器和CLR如何找寻程序集

    本篇体验C#编译器和CLR运行时如何查找程序集,并自定义CLR运行时查找程序集的方式. □ C#编译器和CLR运行时如何查找程序集 C#编译器在哪里?--在C:\Windows\Microsoft.N ...

  4. C#程序集系列11,全局程序集缓存

    全局程序集缓存(GAC:Global Assembly Cache)用来存放可能被多次使用的强名称程序集.当主程序需要加载程序集的时候,优先选择到全局程序集缓存中去找寻需要的程序集. 为什么需要全局程 ...

  5. C#程序集系列10,强名称程序集

    当一个程序集的名称,版本,文化,Public Key都做了设置,就可以把这个程序集叫做"强名称程序集".强名称程序集可以防止被仿冒或篡改.本篇首先创建一个强名称程序集,接着模拟篡改 ...

  6. C#程序集系列09,程序集签名

    在"C#程序集系列08,设置程序集版本"中体验了为程序集设置版本,但对于程序集的安全性来说,还远远不够.本篇体验程序集的签名. □ 程序集的签名 →F盘as文件夹下有多个文件→在程 ...

  7. C#程序集系列08,设置程序集版本

    区别一个程序集,不仅仅是程序集名称,还包括程序集版本.程序集公匙.程序集文化等,本篇体验通过界面和编码设置程序集版本. □ 通过Visual Studio设置程序集版本 →右键项目,选择"属 ...

  8. C#程序集系列07,篡改程序集

    以下几个方面用来区分不同的程序集:○ 程序集名称:Name○ 程序集版本:Version○ 程序集公匙: Public Token○ 程序集文化:Culture 如果没有很严格地按照上面的几个方面来创 ...

  9. C#程序集系列05,让程序集包含多个module

    本篇体验在一个程序集中包含多个module. □ 创建3个module →删除F盘as文件夹中的一些文件,只剩下如下3个文件→用记事本打开MyFirstModule.cs文件,修改如下,并保存 usi ...

随机推荐

  1. 嵌入式 探讨父子线程、进程终止顺序不同产生的结果_skdkjxy_新浪博客

    嵌入式 探讨父子线程.进程终止顺序不同产生的结果 Linux下编程,线程.进程退出顺序问题纷纷扰扰,如果父进程/线程先于子进程/线程终止,系统会做什么处理呢?反之,如果子进程/线程先于父进程/线 程终 ...

  2. Struts 2 - Hello World Example

    As you learnt from the Struts 2 architecture, when you click on a hyperlink or submit an HTML form i ...

  3. day5模块学习--configparser模块

       使用ConfigParser模块读写ini文件(http://blog.csdn.net/linda1000/article/details/11729561) ConfigParserPyth ...

  4. Ionic实战八:ionic登陆页面源码

    onic登陆页面模板源码,可以用于ionic开发中登陆页面制作或者参考 下面是此模板的一些页面 此模板免费提供给大家  登陆用户名和密码都是 phonegap100     

  5. thinkphp结合ajax实现统计页面pv的浏览量

    统计pv量很常用,下面的代码用ajax实现的,使用ajax可以避免页面缓存造成的影响,只要客户端的js代码执行了就可以统计流量. 一共就两部 将下面代码放在要统计的html页面中,测试时把地址换成自己 ...

  6. Python之路【第十一篇】: 进程与线程

    阅读目录 一. cpython并发编程之多进程1.1 multiprocessing模块介绍1.2 Process类的介绍1.3 Process类的使用1.4 进程间通信(IPC)方式一:队列1.5 ...

  7. 变量覆盖漏洞学习及在webshell中的运用

    一.发生条件: 函数使用不当($$.extract().parse_str().import_request_variables()等) 开启全局变量 二.基础了解: 1.$$定义 $$代表可变变量, ...

  8. 快递鸟电子面单打印功能基于java

    之前的后天管理系统的电子面单打印使用的是灵通打单. 使用相对比较麻烦,需要到处Excel之后再导入,麻烦. 快递鸟有电子面单api,后台系统直接对接很是方便,不过也遇到了好些问题. 不难是不难,但是遇 ...

  9. 前端安全系列之二:如何防止CSRF攻击?

    背景 随着互联网的高速发展,信息安全问题已经成为企业最为关注的焦点之一,而前端又是引发企业安全问题的高危据点.在移动互联网时代,前端人员除了传统的 XSS.CSRF 等安全问题之外,又时常遭遇网络劫持 ...

  10. iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面

    iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面 在1.2.2小节中提到过编辑界面(Interface builder),编辑界面是用来设计用户界面的,单击打开Main. ...