How can I get the processor architecture of the dll collector?

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 dll x86, x64, msil etc.

+5
source share
3 answers

Assuming you only look at .net assemblies, you can use CorFlags.exe to view the image header.

This blog post explains the use of determining how to read the results. Excerpts:

Usage: Corflags.exe Assembly [options]

If no parameters are specified, flags for this image are displayed.

...

Here is what each header component means:

Version : contains the .NET Redist version with which the binary is embedded.

The CLR header : 2.0 means .Net 1.0 or .Net 1.1 (Everett) image, and 2.5 means .Net 2.0 (Whidbey) image.

CorFlags:. This is calculated using special ORg flags to indicate whether the image is MILK, its bit size, etc. and used by the bootloader. LIGHTNING: Managed images are allowed to contain code. To be "anycpu", the image must contain only IL.

32BIT: Even if you have an image containing only IL, it can still be platform dependent, the 32BIT flag is used to denote "x86", the image from "anycpu" images. 64-bit images are distinguished by the fact that they have a PE-type PE32 +.
The most interesting aspect is the PE and the 32BIT header flag. They are combined to indicate assembly types. Here's how they will look like for:

  • anycpu: PE = PE32 and 32BIT = 0
  • x86: PE = PE32 and 32BIT = 1
  • 64-bit: PE = PE32 + and 32BIT = 0
+9
source

Trying to find out by downloading the assembly is a chicken egg offer. If you don't get a BadImageFormatException, then the arch will be appropriate, and you don't care what that is. If you get an exception, then the program configuration is incorrect. You cannot do anything in the code.

+1
source

You can also read the assembly file using FileStream. The format of Windows executables is specified in the Microsoft pe / coff specification. You can read it here:

http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx

0
source

All Articles