2011-11-17 10:29:58 +0000 2011-11-17 10:29:58 +0000
341
341
Advertisement

如何在Windows上检查一个二进制程序是32位还是64位?

Advertisement

有什么简单的方法可以在Windows上检查一个二进制程序是32位还是64位?我需要先检查一下,然后再把程序移到32位的机器上,遇到壮观的故障。

Advertisement
Advertisement

答案 (20)

377
377
377
2015-03-13 17:08:57 +0000

在研究了Richard的回答的标题值后,我想出了一个快速、简单、只需要一个文本编辑器就能解决的方案。即使是Windows的默认的记事本.exe也可以使用。在文本编辑器中打开可执行文件。你可能需要拖放或使用编辑器的Open...对话框,因为Windows在上下文菜单中不显示Open with...选项。检查第一次出现PE之后的第一个可打印字符。这部分很可能至少被一些白格包围(可能是很多),所以很容易直观地看到。

这里是你会发现:

32位:

PE L

64位:

PE d†

警告一句话:在大文件上使用默认的记事本会很慢,所以最好不要用它来处理大于一兆或几兆的文件。在我的案例中,用了大约30秒的时间来显示一个12MIB的文件。

如果你需要在你无法安装任何额外软件的机器上检查一个文件,这个解决方案可能会很有用。签名是0x3C (字母 “P "和 "E "后面是两个空字节),后面是两个字节的小尾巴机器类型。还有很多可能的值,但你可能永远不会遇到这些值,也无法在你的Windows PC上运行这样的可执行文件。

完整的机器类型列表,以及其余的.exe规范,可以在Microsoft PE和COFF规范 机器类型部分找到。

129
129
129
2011-11-17 12:14:43 +0000

SDK工具dumpbin.exe/headers选项中包含了这些信息,对比一下这两个(关键信息我加粗了)

PS [64] E:\ #4\> dumpbin /headers C:\Windows\system32\cmd.exe Microsoft (R) COFF/PE Dumper Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file C:\Windows\system32\cmd.exe PE signature found File Type: EXECUTABLE IMAGE FILE HEADER VALUES **8664 machine (x64)** 6 number of sections 4CE798E5 time date stamp Sat Nov 20 09:46:13 2010 0 file pointer to symbol table 0 number of symbols F0 size of optional header 22 characteristics Executable Application can handle large (\>2GB) addresses [...]

PS [64] E:\ #5\> dumpbin /headers C:\Windows\syswow64\cmd.exe Microsoft (R) COFF/PE Dumper Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file C:\Windows\syswow64\cmd.exe PE signature found File Type: EXECUTABLE IMAGE FILE HEADER VALUES **14C machine (x86)** 4 number of sections 4CE78E2B time date stamp Sat Nov 20 09:00:27 2010 0 file pointer to symbol table 0 number of symbols E0 size of optional header 102 characteristics Executable 32 bit word machine [...]
50
Advertisement
50
50
2014-09-06 15:02:25 +0000
Advertisement

如果你没有或不需要整个Windows SDK或Visual Studio,你可以使用sigcheck.exe from SysInternals:

sigcheck.exe C:\Windows\Notepad.exe

输出:

Sigcheck v2.1 - File version and signature viewer
Copyright (C) 2004-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

c:\windows\notepad.exe:
    Verified: Signed
    Signing date: 8:59 AM 8/22/2013
    Publisher: Microsoft Windows
    Description: Notepad
    Product: Microsoft« Windows« Operating System
    Prod version: 6.3.9600.16384
    File version: 6.3.9600.16384 (winblue_rtm.130821-1623)
    MachineType: 64-bit
46
46
46
2014-01-17 02:08:47 +0000

我可以确认一下,file实用程序(如cygwin的)会区分32位和64位的可执行文件。它们出现如下:

32.exe: PE32 executable (GUI) Intel 80386, for MS Windows
64.exe: PE32+ executable (console) x86-64, for MS Windows

正如你所看到的那样,很明显的是哪个是哪个。此外,它还能区分控制台和GUI可执行文件,也是很明显的。

33
Advertisement
33
33
2011-11-17 10:39:49 +0000
Advertisement

一个简单的方法是运行它(假设你信任它),看看任务管理器中的进程选项卡。32位进程会在进程名称的末尾显示 “* 32"。如果你不愿意在你的电脑上运行,你可以试试EXE资源管理器。它将显示一大堆关于可执行文件的信息,包括32位或64位。

28
28
28
2015-10-04 10:56:52 +0000

很多人都安装了优秀的【7-zip】(http://www.7-zip.org/),并在`PATH`中加入了7-Zip文件夹。7-ZIP可以理解ZIP和RAR以外的文件格式,如MSI文件和PE可执行文件等。只需在PE文件(Exe或DLL)上使用命令行`7z.exe`:

7z l some.exe | more
7z l some.exe | findstr CPU

输出结果如下,其中CPU行读为x86x64,也就是这里所说的

Path = C:\Extra\AV\neroAacEnc.exe
Type = PE
CPU = x86
Characteristics = Executable 32-bit

Path = C:\Extra\AV\LAME\lame_enc.dll
Type = PE
CPU = x86
Characteristics = Executable DLL 32-bit

Path = C:\Extra\AV\FFmpeg\bin\ffmpeg.exe
Type = PE
CPU = x64
64-bit = +
Characteristics = Executable LargeAddress NoRelocs NoLineNums NoLocalSyms NoDebugInfo

Path = C:\Extra\AV\FFmpeg\bin\avcodec-56.dll
Type = PE
CPU = x64
64-bit = +
Characteristics = Executable DLL LargeAddress NoLineNums NoLocalSyms NoDebugInfo
21
Advertisement
21
21
2011-11-17 13:36:05 +0000
Advertisement

64位版本的【进程资源管理器】(http://technet.microsoft.com/en-us/sysinternals/bb896653)可以告诉你。只要运行可执行程序,打开进程的属性窗口。在主选项卡上有一个 “Image:32位 "或 "Image:64位 "的条目,

17
17
17
2015-01-05 16:53:58 +0000

最简单的方法*(当数据不保密时)

我发现Virustotal File detail是最简单的方法,可以查出二进制是32位还是64位。

14
Advertisement
14
14
2012-09-27 07:08:26 +0000
Advertisement

运行一个可执行程序,然后在进程资源管理器或类似的工具中检查的方法,有一些明显的缺点:

1.我们必须执行进程。我们必须执行进程 2.

2.对于那些寿命较短的进程(如echo hello world类型),进程资源管理器可能连一个新的进程已经开始了都不知道。不过,我还没有在windows系统上测试过。

Usage: file program_under_test.exe

EDIT: 刚刚在windows上测试了file.exe,效果很好。)

13
13
13
2015-03-19 12:09:30 +0000

这里有一个Powershell的解决方案,没有外部依赖关系什么的。打开Powershell,将函数粘贴到那里(按两次回车键,这样你就可以返回到提示符),然后使用它,就像我下面的例子中的函数:

function Test-is64Bit {
    param($FilePath=“$env:windir\notepad.exe”)

    [int32]$MACHINE_OFFSET = 4
    [int32]$PE_POINTER_OFFSET = 60

    [byte[]]$data = New-Object -TypeName System.Byte[] -ArgumentList 4096
    $stream = New-Object -TypeName System.IO.FileStream -ArgumentList ($FilePath, 'Open', 'Read')
    $stream.Read($data, 0, 4096) | Out-Null

    [int32]$PE_HEADER_ADDR = [System.BitConverter]::ToInt32($data, $PE_POINTER_OFFSET)
    [int32]$machineUint = [System.BitConverter]::ToUInt16($data, $PE_HEADER_ADDR + $MACHINE_OFFSET)
    $stream.Close()

    $result = "" | select FilePath, FileType, Is64Bit
    $result.FilePath = $FilePath
    $result.Is64Bit = $false

    switch ($machineUint) 
    {
        0 { $result.FileType = 'Native' }
        0x014c { $result.FileType = 'x86' }
        0x0200 { $result.FileType = 'Itanium' }
        0x8664 { $result.FileType = 'x64'; $result.is64Bit = $true; }
    }

    $result
}

以下是输出的例子:

D:\> Test-is64bit

FilePath FileType Is64Bit
-------- -------- -------
C:\Windows\notepad.exe x64 True

D:\> Test-is64bit 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'

FilePath FileType Is64Bit
-------- -------- -------
C:\Program Files (x86)\Mozilla Firefox\firefox.exe x86 False
9
9
9
2015-10-07 15:32:36 +0000

即使是标注为32位的可执行文件,如果是.NET可执行文件可以作为32位或64位运行,也可以作为64位运行。更多信息请参见https://stackoverflow.com/questions/3782191/how-do-i-determine-if-a-net-application-is-32-or-64-bit ,其中有一个答案说,可以用CORFLAGS实用程序来确定.NET应用程序的运行方式。 EXE输出**

对于32位的可执行文件:

Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 0x3
ILONLY : 1
32BITREQ : 1
32BITPREF : 0
Signed : 0

对于64位的可执行文件: Version : v2.0.50727 CLR Header: 2.5 PE : PE32+ CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0

对于可以作为32位或64位运行的可执行文件,并且在可能的情况下会作为64位运行:

Version : v2.0.50727
CLR Header: 2.5
PE : PE32
CorFlags : 0x1
ILONLY : 1
32BITREQ : 0
32BITPREF : 0
Signed : 0

对于可以作为32位或64位运行的可执行文件,但除非加载到64位进程中,否则会作为32位运行:

Version : v4.0.30319
CLR Header: 2.5
PE : PE32
CorFlags : 0x20003
ILONLY : 1
32BITREQ : 0
32BITPREF : 1
Signed : 0
6
6
6
2016-06-14 00:19:11 +0000

我的两点建议是下载dependency walker,然后检查一下在可执行文件中使用了什么架构。 exe文件→选择,在底部反射扫描完成后,你会看到一个有数据的网格,其中有一列有 “架构 "的详细信息(x86, x64)

打开可执行文件,看到构建架构

5
5
5
2015-05-06 08:51:55 +0000

如果您使用的是Windows 7,在Windows资源管理器上,右击可执行文件,然后选择属性。在 “属性 "窗口中选择 "兼容性 "选项卡。如果在 "兼容性模式 "部分中看到的是Windows XP,那么这是一个32位的可执行文件。如果你看到的是Windows Vista,则是64位。

5
5
5
2015-01-05 13:54:17 +0000

你也可以在msys bundle of mingw 中使用file工具。它的工作原理和unix命令一样。与GNUwin32中的file工具的工作原理类似。

5
5
5
2016-01-16 11:20:03 +0000

如何在你的上下文菜单中添加32/64位测试

创建一个名为exetest. reg,并包含这行代码:

Windows Registry Editor Version 5.00

; What will appear in the contextual menu when right-clicking on a .exe file
[HKEY_CLASSES_ROOT\exefile\shell\command32_64]
@="32/64 bit test"

; What to do with it
; here, %1 is the file given as argument of the script
[HKEY_CLASSES_ROOT\exefile\shell\command32_64\command]
@="\"c:\temp\x86TestStart.bat\" \"%1\""

创建一个名为x86TestStart.bat的文本文件,包含这行代码,并保存在C:\temp:

c:\temp\x86or64.vbs %1

创建一个名为x86or64.vbs的文本文件,包含这行代码,并保存在C:\temp:

rem Reading binary file in VBScript: http://stackoverflow.com/questions/21249440/modify-first-two-bytes-of-a-file-using-vbscript
rem Info on executables: https://dmoj.ca/problem/exe

rem x86/64 signature is located dinamycally; its position is addressed
rem from bytes in 0x3C-0x3D position.

rem Possible signatures;
rem "PE..L" (hex code: 50.45.00.00.4C) = 32 bit
rem "PE..d†" (hex code: 50.45.00.00.64.86) = 64 bit

' ------------------------------------
' Source code by Jumpkack 2015
' ------------------------------------

' Read all arguments from command line:
Set args = Wscript.Arguments

' Store first argument (full path to file)
FileName = args(0)

' Find address of executable signature:
FirstChars = readBinary(FileName)
FirstChars = FirstChars
Addr1 = asc(mid(FirstChars,61,1))
Addr2 = asc(mid(FirstChars,62,1))
AddrFinal = Addr2*256 + Addr1 + 1

' Check signature:
if ucase(hex(asc(mid(FirstChars,AddrFinal+4,2)))) = "4C" then Wscript.Echo Filename & " is a 32 bit executable."
if ucase(hex(asc(mid(FirstChars,AddrFinal+4,2)))) = "64" then Wscript.Echo Filename & " is a 64 bit executable."

Function readBinary(path)
    Dim a, fso, file, i, ts
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set file = fso.getFile(path)
    If isNull(file) Then
        wscript.echo "File not found: " & path
        Exit Function
    End If
    Set ts = file.OpenAsTextStream()
    'a = makeArray(file.size)
    a=""
    i = 0
    While (Not ts.atEndOfStream) and (i<60000)
       'a(i) = ts.read(1)
       a = a + ts.read(1)
       i = i + 1
    Wend
    ts.close
    readBinary = a
 End Function

双击exetest. reg文件:在windows注册表中会添加一个新的密钥:

[HKEY_CLASSES_ROOT\exefile\shell\command32_64\command]

,在右键点击可执行文件后,在上下文菜单中会显示为 “32/64位测试"。

点击该项目将导致启动批处理文件`c:\temp\x86TestStart.bat# 如何在你的上下文菜单中添加32/64位测试

创建一个名为exetest. reg,并包含这行代码:

Windows Registry Editor Version 5.00

; What will appear in the contextual menu when right-clicking on a .exe file
[HKEY_CLASSES_ROOT\exefile\shell\command32_64]
@="32/64 bit test"

; What to do with it
; here, %1 is the file given as argument of the script
[HKEY_CLASSES_ROOT\exefile\shell\command32_64\command]
@="\"c:\temp\x86TestStart.bat\" \"%1\""

创建一个名为x86TestStart.bat的文本文件,包含这行代码,并保存在C:\temp:

c:\temp\x86or64.vbs %1

创建一个名为x86or64.vbs的文本文件,包含这行代码,并保存在C:\temp:

rem Reading binary file in VBScript: http://stackoverflow.com/questions/21249440/modify-first-two-bytes-of-a-file-using-vbscript
rem Info on executables: https://dmoj.ca/problem/exe

rem x86/64 signature is located dinamycally; its position is addressed
rem from bytes in 0x3C-0x3D position.

rem Possible signatures;
rem "PE..L" (hex code: 50.45.00.00.4C) = 32 bit
rem "PE..d†" (hex code: 50.45.00.00.64.86) = 64 bit

' ------------------------------------
' Source code by Jumpkack 2015
' ------------------------------------

' Read all arguments from command line:
Set args = Wscript.Arguments

' Store first argument (full path to file)
FileName = args(0)

' Find address of executable signature:
FirstChars = readBinary(FileName)
FirstChars = FirstChars
Addr1 = asc(mid(FirstChars,61,1))
Addr2 = asc(mid(FirstChars,62,1))
AddrFinal = Addr2*256 + Addr1 + 1

' Check signature:
if ucase(hex(asc(mid(FirstChars,AddrFinal+4,2)))) = "4C" then Wscript.Echo Filename & " is a 32 bit executable."
if ucase(hex(asc(mid(FirstChars,AddrFinal+4,2)))) = "64" then Wscript.Echo Filename & " is a 64 bit executable."

Function readBinary(path)
    Dim a, fso, file, i, ts
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set file = fso.getFile(path)
    If isNull(file) Then
        wscript.echo "File not found: " & path
        Exit Function
    End If
    Set ts = file.OpenAsTextStream()
    'a = makeArray(file.size)
    a=""
    i = 0
    While (Not ts.atEndOfStream) and (i<60000)
       'a(i) = ts.read(1)
       a = a + ts.read(1)
       i = i + 1
    Wend
    ts.close
    readBinary = a
 End Function

双击exetest. reg文件:在windows注册表中会添加一个新的密钥:

[HKEY_CLASSES_ROOT\exefile\shell\command32_64\command]

,在右键点击可执行文件后,在上下文菜单中会显示为 ”32/64位测试“。

点击该项目将导致启动批处理文件,启动VBscript文件x86or64.vbs,读取exe签名并显示结果。

2
2
2
2017-10-10 00:41:35 +0000

然而,WSLfile命令的作用很大。

2
2
2
2017-02-01 22:27:17 +0000

我没有看到有人提到过这个问题。有一个叫NTCore的CFF Explorer的PE查看器程序,可以为你提供这些信息。它可以下载并作为可移植程序运行,但如果你愿意的话,也可以安装它。在 “特征 "栏中点击 "点击这里”

如果是32位程序,"32位字机 “这个复选框会被勾选。例如,我安装的是32位的Notepad++,如下图所示。否则,它是64位的。

1
1
1
2017-09-28 07:37:39 +0000

我的两点意见:作为一个C++开发者,依赖关系行者http://www.dependencywalker.com/ )的信息量非常大,不仅显示64/32位,而且每一个Dll涉及的Dll都会显示:

你可以在每个文件名的左边看到64位…..

0
0
0
2019-08-02 22:55:25 +0000

Windows 10的任务管理器中的平台列

Windows 7没有平台列。

在windows 10中,选择列不在 “视图 "下了。在Windows 10中,当在 "详细信息 "选项卡中,你可以右击列标题,然后选择 "选择列"。然后勾选 "平台"。

0
0
0
2015-03-19 11:39:51 +0000
  • 运行应用程序 —-打开任务管理器 –右键单击并创建转储文件 –记下路径 –转到路径,在Visual Studio中打开.DMP转储 –在那里你可以得到所有的细节 –检查进程架构。
Advertisement

Verwandte Fragen

3
19
10
28
8
Advertisement
Advertisement