How can I determine if a .NET assembly was built for x86 or x64?

后端 未结 15 1050
面向向阳花
面向向阳花 2020-11-22 09:08

I\'ve got an arbitrary list of .NET assemblies.

I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible?

15条回答
  •  温柔的废话
    2020-11-22 09:49

    You can use the CorFlags CLI tool (for instance, C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\CorFlags.exe) to determine the status of an assembly, based on its output and opening an assembly as a binary asset you should be able to determine where you need to seek to determine if the 32BIT flag is set to 1 (x86) or 0 (Any CPU or x64, depending on PE):

    Option    | PE    | 32BIT
    ----------|-------|---------
    x86       | PE32  | 1
    Any CPU   | PE32  | 0
    x64       | PE32+ | 0
    

    The blog post x64 Development with .NET has some information about corflags.

    Even better, you can use Module.GetPEKind to determine whether an assembly is PortableExecutableKinds value PE32Plus (64-bit), Required32Bit (32-bit and WOW), or ILOnly (any CPU) along with other attributes.

提交回复
热议问题