检查文件是否.NET程序集 [英] Checking if a file is a .NET assembly

查看:123
本文介绍了检查文件是否.NET程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过检查的一些方法,如果PEFile是一个.NET程序集通过检查二元结构

是最快的方法来测试多个文件?我认为试图加载每个文件(例如,通过 Assembly.ReflectionOnlyLoad )文件可能是pretty的慢,因为它会被加载的文件类型的信息。

Is that the fastest method to test multiple files? I assume that trying to load each file (e.g. via Assembly.ReflectionOnlyLoad) file might be pretty slow since it'll be loading file type information.

注:我正在寻找一种方法以编程方式检查文件

Note: I'm looking for a way to check files programmatically.

推荐答案

也许这有助于

http://www.grimes.nildram.co.uk/dotnet /vistaAndDotnet.htm

接下来,我检查,看它是否是一个.NET程序集。要做到这一点,我请检查该文件中包含的CLR头。这个头文件包含的.NET code在文件中的位置,这是用来编写code框架的版本的重要信息。这个头的位置给出了文件的数据目录表。如果数据目录项具有零值,则该文件是不受管理的,如果它有非零值,则该文件是一个.NET程序集。

Next, I check to see if it is a .NET assembly. To do this I check to see if the file contains the CLR header. This header contains important information about the location of the .NET code in the file and the version of the framework that was used to write that code. The location of this header is given in the file's Data Directory table. If the data directory item has zero values then the file is unmanaged, if it has non-zero values then the file is a .NET assembly.

您可以使用DUMPBIN实用工具与/头开关测试这个自己。该实用程序将在命令行上的文件打印各种头。在可选头的最终值,你会看到数据目录的列表(总会有他们的16),如果COM描述符目录下有一个非零位置,它表示该文件是一个.NET程序集。在CLR头的内容还可以使用/ CLRHEADER开关(如果该文件是不受管理的,这将不显示值)上市。 XP测试时,它执行一个文件,并且如果CLR头是present它将初始化运行时和组件的入口点传递到运行时,使得该文件完全运行内运行时的CLR头

You can test this yourself using the dumpbin utility with the /headers switch. This utility will print the various headers in a file on the command line. At the end of the Optional Header Values you'll see a list of the Data Directories (there will always be 16 of them) and if the COM Descriptor Directory has a non-zero location it indicates that the file is a .NET assembly. The contents of the CLR header can also be listed using the /clrheader switch (if the file is unmanaged this will show no values). XP tests for the CLR header when it executes a file and if the CLR header is present it will initialize the runtime and pass the entry point of the assembly to the runtime, so that the file runs totally within the runtime.

这篇关于检查文件是否.NET程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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