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

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

问题描述

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



有没有一个类可以做到这一点?



我需要得到更好的dll是x86,x64,MSIL等。

解决方案

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



这篇博文解释了确定如何读取结果的用法。摘录:


用法:Corflags.exe Assembly [options]



如果没有指定选项,显示给定图像的标志。



...



这里标题的每个组成部分是什么意思:



版本:包含二进制文件的$ Redist版本b $ b内置。



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



CorFlags:这是由OR'g特定的标志计算,以指示
图像是否为ILONLY ,它的位等等,
由装载器使用。 ILONLY:被管理的
图像允许包含本机
代码。要成为anycpu图像,
只包含IL。



32BIT:即使您的图像只包含IL它仍然可能
具有平台依赖性,32BIT
标志用于区分anycpu图像中的x86
图像。 64位
图像由事实
区分,它们具有PE类型的PE32 +。

最有趣的方面是标题的PE和32BIT标志。
这些组合指定程序集
类型。以下是他们将如何看待
像:




  • anycpu:PE = PE32和32BIT = 0

  • x86:PE = PE32和32BIT = 1

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



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

Is there a class that can do this?

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

解决方案

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:

Usage: Corflags.exe Assembly [options]

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

...

Here is what each component of the header means:

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

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: 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: 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 and 32BIT = 0
  • x86: PE = PE32 and 32BIT = 1
  • 64-bit: PE = PE32+ and 32BIT = 0

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

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