如何获得程序集 dll 的处理器架构? [英] How can I get the processor architecture of an assembly dll?

查看:32
本文介绍了如何获得程序集 dll 的处理器架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过在 c# 中以编程方式加载 dll 来获取处理器架构吗?

Can I get the processor architecture by loading the dll programmatically in c#?

有可以做到这一点的课程吗?

Is there a class that can do this?

我需要知道 dll 是 x86、x64、MSIL 等.

I need to get wether the dll is x86, x64, MSIL etc..

推荐答案

假设您只查看 .net 程序集,您可以使用 CorFlags.exe 查看图像的标题.

Assuming you are only looking at .net assemblies, you can use CorFlags.exe for look at the header of the image.

这篇博文解释了用于确定如何读取结果.摘录:

This blog post explains the usage to determing how to read the results. Excerpt:

用法:Corflags.exe 程序集 [选项]

Usage: Corflags.exe Assembly [options]

如果未指定任何选项,则显示给定图像的标志.

If no options are specified, the flags for the given image are displayed.

...

这里是标题的每个组成部分的含义:

Version:包含二进制文件所在的 .NET Redist 版本已建成.

Version: Contains the version of .NET Redist with which the binary is built.

CLR 标头:2.0 表示 .Net 1.0 或 .Net 1.1 (Everett) 图像,而 2.5 表示 .Net 2.0 (Whidbey) 图像.

CLR Header: 2.0 indicates a .Net 1.0 or .Net 1.1 (Everett) image while 2.5 indicates a .Net 2.0 (Whidbey) image.

CorFlags: 这是通过 OR'g 特定标志计算的,以指示是否图像是 ILONLY,它的位数等.和由加载程序使用.ILONLY:管理图像允许包含原生代码.要成为anycpu",图像应仅包含 IL.

CorFlags: This is computed by OR’g specific flags to indicate whether the image is ILONLY, its bitness etc. and is used by the loader. ILONLY: Managed images are allowed to contain native code. To be "anycpu" an image shall only contain IL.

32BIT:即使您的图像仅包含 IL,它仍然可能有平台依赖,32BIT标志用于区分x86"来自anycpu"图像的图像.64位图像是由事实区分的他们有 PE32+ 的 PE 类型.
最有趣的方面是头部的 PE 和 32BIT 标志.这些结合起来指定程序集类型.这是它们的外观喜欢:

32BIT: Even if you have an image that only contains IL it still might have platform dependencies, the 32BIT flag is used to distinguish "x86" images from "anycpu" images. 64-bit images are distinguished by the fact that they have a PE type of PE32+.
The most interesting aspect is the PE and the 32BIT flag of the header. These combine to specify the assembly types. Here is how they would look like for:

  • anycpu:PE = PE32 和 32BIT = 0
  • x86:PE = PE32 和 32BIT = 1
  • 64 位:PE = PE32+ 和 32BIT = 0

这篇关于如何获得程序集 dll 的处理器架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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