Win32 API的告诉给定的二进制文件(EXE或DLL)是否为X86,x64或IA64 [英] Win32 API to tell whether a given binary (EXE or DLL) is x86, x64, or ia64
问题描述
我想找到一个编程的方式来判断一个二进制文件的x86,x64或IA64。
I am trying to find a programmatic way to tell if a binary is x86, x64, or ia64.
平台:Windows操作系统。 语言:C / C ++
Platform: Windows. Language: c/c++.
背景:在试图加载第三方DLL,我需要找出其位数
Background: Before trying to load a third-party dll, I need to find out its bitness.
鸭preciate的指针。
Appreciate any pointers.
推荐答案
<一个href="http://stackoverflow.com/questions/197951/how-can-i-determine-for-which-platform-an-executable-is-compiled/198009">Here是同一个问题获得manged exe文件。
Here is same question for manged exe.
使用 ImageNtHeader(...)得到该文件的PE数据,然后检查IMAGE_FILE_HEADER.Machine领域。
Use the ImageNtHeader(...) to get the PE data of the file and then check the IMAGE_FILE_HEADER.Machine field.
<一个href="http://www.google.com/$c$csearch/p?hl=en#RRljDOJ5z1I/dyninstAPI-4.0.3/core/dyninstAPI/src/Object-nt.C&q=ImageNtHeader%20lang:c%2B%2B&l=641">Here一些code 我发现使用谷歌code搜索
Here is some code I found using Google Code Search
没有清理,并没有错误检查
// map the file to our address space
// first, create a file mapping object
hMap = CreateFileMapping(
hFile,
NULL, // security attrs
PAGE_READONLY, // protection flags
0, // max size - high DWORD
0, // max size - low DWORD
NULL ); // mapping name - not used
// next, map the file to our address space
void* mapAddr = MapViewOfFileEx(
hMap, // mapping object
FILE_MAP_READ, // desired access
0, // loc to map - hi DWORD
0, // loc to map - lo DWORD
0, // #bytes to map - 0=all
NULL ); // suggested map addr
peHdr = ImageNtHeader( mapAddr );
这篇关于Win32 API的告诉给定的二进制文件(EXE或DLL)是否为X86,x64或IA64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!