CLR中的模块,组件,标题 [英] Modules, Assemblies, Headers in CLR

查看:103
本文介绍了CLR中的模块,组件,标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读C#3.0的CLR,并且一直在思考程序集,模块和标题,但是事情变得复杂了.这是我的理解,但是如果有人可以进一步澄清一下,那就太好了

I've been reading CLR with C# 3.0 and I've been reflecting on Assemblies, Modules and Headers however things got complicated. This is what I understood but if would be great if someone can clarify things little bit more:

  1. 模块是csc.exe的结果,其中包含IL代码和元数据表.元数据表包含三个不同的表,它们是:

  1. Modules are result of csc.exe which contains IL code and Metadata tables. Metadata tables contains three different tables which are:

  • 定义表,例如"ModuleDef,TypeDef,PropertyDef,MethodDef,EventDef,FieldDef"
  • 参考表,例如"TypeRef,ModuleRef,MemberRef等".
  • 清单表**

程序集是包含许多模块以及资源(例如图像,文档,pdf等)的容器.

Assemblies are containers which contain many Modules as well as resources such as images, docs, pdf, etc.

书中说Assembly是一个包含Modules的容器,并且还说Managed Module是

The books says Assembly is a container consists of Modules and it also says Managed Module is

受管模块:

受管模块是标准的32位Microsoft Windows便携式计算机 可执行(PE32)文件或标准的64位Windows便携式计算机 需要CLR执行的可执行(PE32 +)文件.

A managed module is a standard 32-bit Microsoft Windows portable executable (PE32) file or a standard 64-bit Windows portable executable (PE32+) file that requires the CLR to execute.

Richter,Jeffrey(2010-02-05).通过C#进行CLR(Kindle位置696-697). OReilly Media-A. Kindle Edition.

Richter, Jeffrey (2010-02-05). CLR via C# (Kindle Locations 696-697). OReilly Media - A. Kindle Edition.

大会的定义:

程序集是一个或多个模块或资源的逻辑分组 文件.

An assembly is a logical grouping of one or more modules or resource files.

Richter,Jeffrey(2010-02-05).通过C#进行CLR(Kindle位置766-767). OReilly Media-A. Kindle版.

Richter, Jeffrey (2010-02-05). CLR via C# (Kindle Locations 766-767). OReilly Media - A. Kindle Edition.

在同一本书的图片中,似乎托管模块实际上是程序集的一部分.

So it seems that Managed Module are actually part of the Assembly in the image taken from the same book.

PE32标头属于程序集,但是作者还说它也属于托管模块,等等.

PE32 headers belong to Assemblies, however author also says it belongs to Managed Modules as well, etc.

这里的分隔是什么?为什么即使认为模块和装配看起来足够分开,他也可以互换使用?

What's the separation here? Why did he use Module and Assemblies interchangeable even thought they look separate enough.

受管理的PE文件包含四个主要部分:PE32(+)标头,CLR 标头,元数据和IL. PE32(+)接头是标准的 Windows期望的信息. CLR标头是 特定于需要CLR(托管)的模块的信息 模块).

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).

Richter,Jeffrey(2010-02-05).通过C#进行CLR(Kindle位置 1628-1629). OReilly Media-A. Kindle版.

Richter, Jeffrey (2010-02-05). CLR via C# (Kindle Locations 1628-1629). OReilly Media - A. Kindle Edition.

该图像还清楚地表明,模块仅具有元数据,而没有PE32(+),CLR头等.您认为清单和元数据可以互换使用吗?

Also the image clearly shows that Modules have only Metadata not PE32(+), CLR headers, etc. Do you think Manifest and Metadata can be used interchangeably?

还可以请您解释一下**模块中的清单表吗?

And also could you please explain **Manifest tables in the Modules as well?

推荐答案

您发布的内容有点不了解托管程序集如何在PE32文件中嵌入.这是一种非常灵活的格式,最初旨在存储本机可执行代码和资源,但也足够灵活以存储数据.从Windows的角度来看,这实际上是一个程序集.只有CLR才能将数据转换为可执行文件.

What you posted is a bit of shy of exactly how a managed assembly is embedded in a PE32 file. It is a very flexible format, originally intended to store native executable code and resources but flexible enough to also store data. Which is really what an assembly is from the point of view of Windows. Only the CLR can turn that data into something executable.

PE32文件不仅包含程序集,还包含更多内容.实际上也有本机代码. 5个字节用于纯托管程序集.它具有进入mscoree.dll(托管代码的引导程序)的跳转指令.一个EXE包含一个到_CorExeMain的跳转,一个DLL包含一个到_CorDllMain的跳转.对于混合模式程序集,此功能得到了进一步扩展,System.Data.dll和PresentationCore.dll就是这些示例.它们中包含大量的本机代码,这些代码由托管类包装. C ++/CLI编译器和链接器是创建此类程序集的方法. .text部分包含代码,.reloc部分包含重定位信息,可帮助DLL在内存中的任意地址加载.

A PE32 file contains more than just the assembly. There is actually native code in it as well. 5 bytes of it for pure managed assemblies. It has a jump instruction into mscoree.dll, the bootstrapper for managed code. An EXE contains a jump to _CorExeMain, a DLL contains a jump to _CorDllMain. This is further extended for mixed mode assemblies, System.Data.dll and PresentationCore.dll are examples of those. They have large chunks of native code in them, code that's wrapped by managed classes. The C++/CLI compiler and linker is the way to create assemblies like that. The .text section contains the code, the .reloc section contains relocation information that helps a DLL get loaded at an arbitrary address in memory.

大多数PE32文件还包含非托管资源. Windows可以理解的格式.该内容存储在.rsrc部分中.例如,C#编译器会在此处自动创建资源,您可以使用/win32res选项覆盖这些内容.您可以通过File + Open + File看到它,然后选择一个程序集.有三个重要的要素:

Most PE32 files also contain unmanaged resources. A format that Windows understands. That's stored in the .rsrc section. The C# compiler for example automatically creates resources there, something you can override with the /win32res option. You can see this with File + Open + File and select an assembly. There are three important ones:

  • RT_MANIFEST包含资源ID为1的清单.这是Windows需要了解的C#程序与UAC兼容的内容.您可以通过将Application Manifest文件添加到项目中来创建自己的清单.
  • ICON,其中包含一个图标,该图标被选作桌面快捷方式的默认图标
  • 版本,包含非托管版本资源.在浏览器详细信息"属性表中可见,该属性表由编译器根据AssemblyInfo.cs中的程序集属性合成而成.

Dumpbin.exe是用于窥视PE32文件内部的工具.不幸的是,它了解托管程序集,因此您看不到所有内容.

Dumpbin.exe is a tool to peek at the internals of a PE32 file. Unfortunately it knows about managed assemblies so you can't see everything.

这篇关于CLR中的模块,组件,标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆