如何检测给定的 PE 文件(exe 或 dll)是 64 位还是 32 位 [英] How to detect that a given PE file (exe or dll) is 64 bit or 32 bit
问题描述
我需要检测给定的 .dll 或 .exe 文件是 32 位还是 64 位
I need to detect whether a given .dll or .exe file is 32 bit or 64 bit
目前我只有一个解决方案:从指定文件中读取 PE Header 并从那里获取Machine"字段.
At the moment I have only one solution: read the PE Header from the specified file and take the 'Machine' field from there.
( 规范:Microsoft 可移植可执行文件和通用对象文件格式规范(.docx 文件)在3.3. COFF 文件头(对象和图像)"部分)
( Specification: Microsoft Portable Executable and Common Object File Format Specification (.docx file) at section "3.3. COFF File Header (Object and Image)" )
此字段最多可以包含大约 20 个值.其中三个是:
This field can take up to about 20 values. Three of them are:
IMAGE_FILE_MACHINE_I386 ( == 32bit )
IMAGE_FILE_MACHINE_IA64 ( == 64bit )
IMAGE_FILE_MACHINE_AMD64 ( == 64bit )
我的问题:
1) 'Machine' 到 bitness 映射正确还是我错过了什么?还有其他注意事项吗?
1) Is 'Machine' to bitness mapping correct or did I miss something? Are there any other caveats?
2) 是否有更简单的方法来检测 32/64 位(可能是我没有注意到的 PE 格式中的某些特定字段或某些特殊的系统功能)?
2) Is there easier way to detect 32/64 bitness (probably some specific field in PE format I didn't notice or some special system function)?
推荐答案
GetBinaryType(...) 为基于 Windows 的 32 位应用程序返回 SCS_32BIT_BINARY
和 SCS_64BIT_BINARY
用于基于 64 位 Windows 的应用程序.
GetBinaryType(...) returns SCS_32BIT_BINARY
for a 32-bit Windows-based application
and SCS_64BIT_BINARY
for a 64-bit Windows-based application.
这篇关于如何检测给定的 PE 文件(exe 或 dll)是 64 位还是 32 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!