• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 643
  • Last Modified:

Identify .Exe is 32 bit or 64 bit

Hi,
     
      Any API or function which would say that a .exe file is either 64bit or 32 bit.
      I don't want to load the .exe in to the memory and then find out 32 or 64 bit.

Thanks in Advance,
Ramesh.
0
ramesh_hyd_ap
Asked:
ramesh_hyd_ap
  • 2
  • 2
2 Solutions
 
Deepu AbrahamR & D Engineering ManagerCommented:
I don't know any API but this might work:

1.Open .exe file in using fopen
2.Search for string "This program must be run under Win32" or "Win32"./Search for string "This program must be run under Win64 or "Win64".
3.Close file.

Best Regards,
DeepuAbrahamK
0
 
ramesh_hyd_apAuthor Commented:
Hi,
     I think there should be a more better approach because if in the future if Microsoft changes these strings, my validation will fail.

Thanks,
Ramesh.
0
 
karfiCommented:
maybe this works:

check "magic" field in the PE header, and if its value is 0x020b, the file is a 64bit executable.
0
 
ramesh_hyd_apAuthor Commented:
Hi karfi,
 
I don't much about PE header, can u please be more detail.

Thanks,
Ramesh.
0
 
karfiCommented:
Hi!

you can read more here (for example):

http://en.wikibooks.org/wiki/Reverse_Engineering/PE#MS-DOS_header

some explanation for the page:

The offset of the PE exe header is in the DOS header in the beginning of the .exe file.
(e_lfanew in the DOS_Header structure, 0x00000080 is tipical, sometimes it is 0x000000e0 but can be any value (maybe aligned to 4 or 16? bytes)).

After you get PE offset (from the beginning of the file), you can read a COFF header(you can skip this) and a PE Optional header.

The field "magic" I mentioned is called "signature" on the wiki page. (It is the first member of the PEOptHeader struct)

BR,
mate
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now