How to detect that a given PE file (exe or dll) has 64-bit or 32-bit

I need to determine if a given .dll or .exe file is 32-bit or 64-bit

At the moment I have only one solution: read the PE-header from the specified file and from there take the "Machine" field.

(Specification: Microsoft Executable and Common Object File Specification file format specification (.docx file) in "3.3. COFF file header (object and image)")

This field can take up to 20 values. Three of them:

IMAGE_FILE_MACHINE_I386 ( == 32bit ) IMAGE_FILE_MACHINE_IA64 ( == 64bit ) IMAGE_FILE_MACHINE_AMD64 ( == 64bit ) 

My questions:

1) Is the "Machine" display in bitte correct or am I missing something? Are there any other reservations?

2) Is there an easier way to detect 32/64 bitness (perhaps some specific field in PE format that I did not notice or some special system function)?

+6
c ++ x86 64bit winapi
source share
2 answers

GetBinaryType (...) returns SCS_32BIT_BINARY for a 32-bit Windows-based application and SCS_64BIT_BINARY for a 64-bit Windows-based application.

+15
source share

Note this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms680339%28v=vs.85%29.aspx Find the member "Magic" - you can find out if the PE header is 32 -bit (PE32) or 64-bit (PE32 +).

+2
source share

All Articles