在Windows / Linux上使用python3脚本检查可执行文件是32位还是64位

穆里尔

我正在用Python3(更具体地说:)编写软件Python 3.8.1在某个时候,软件需要检查某些任意可执行文件是64位还是32位。经过研究,我发现以下内容:

检查exe是32位还是64位

在这篇文章中,提供了以下解决方案:

subprocess.call(['dumpbin', '/HEADERS', 'test2.exe', '|', 'find', '"machine"'])

不幸的是,这不适用于Python 3.8.1该职位将近8年了,可以追溯到Python 2.x过去。

如何从内部测试64位Python 3.x我需要针对Linux和Windows 10的解决方案。

编辑:
与Windows相关的注释:
显然,DumpBin解决方案(请参阅检查exe是32位还是64位),需要安装Visual Studio。对我来说这是一个禁忌。我的Python3软件应可在任何Windows 10计算机上运行。

与Linux有关的注释:
在Linux上,我不需要测试PE格式的可执行文件。只是Linux可执行文件就可以了。

L3viathan

检测ELF二进制文件(即Linux)的64位很容易,因为它始终位于标头中的同一位置:

def is_64bit_elf(filename):
    with open(filename, "rb") as f:
        return f.read(5)[-1] == 2

我没有Windows系统,因此无法测试,但这可能在Windows上有效:

def is_64bit_pe(filename):
    import win32file
    return win32file.GetBinaryType(filename) == 6

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用mingw-w64编译和链接32位Windows可执行文件

如果我们可以在64位Windows上运行32位可执行文件,为什么不能将其转换?

Windows 说 64 位可执行文件是“不受支持的 16 位应用程序”

将Linux上的Python脚本打包到Windows可执行文件中

将COBOL编译为Windows的32位可执行文件

C ++可执行文件无法在Windows 7中运行-64位不兼容

如何从Windows上开发的Python脚本在Mac上创建可执行文件

我如何在Windows PE 32位可执行文件中为代码洞穴腾出空间

使用批处理脚本在 Windows 上运行所需数量的可执行文件

在 Windows 上制作 python 独立的 Linux 可执行文件

我可以在Mac上生成可在Windows上使用的python可执行文件吗?

使用Windows Machine构建适用于Linux的Python独立可执行文件

32 位 Windows 上的 64 位 Python?

Windows可执行文件已在我的Linux上执行

如何在PowerShell中检查要安装的可执行文件是32位还是64位?

如何在Linux Shell脚本中运行Windows可执行文件?

Windows上与位置代码无关的可执行文件

Windows路径上的Sourcetree git可执行文件

在Ubuntu上编译C文件并在Windows上使用可执行文件

我应该使用调试构建可执行文件还是发布构建可执行文件来安装 Windows 服务?

在 Windows 10 中调度 Python 脚本可执行文件

如何使用 Windows 批处理脚本识别操作系统是 64 位还是 32 位?

获取有关Linux系统上Windows可执行文件的信息

(C / C ++)如何生成可在Windows和Linux上运行的可执行文件?

为什么我的64位可执行文件比32位可执行文件大3倍?

使用 pip 安装 Windows 可执行文件

使用NASM编译Windows可执行文件

使用pyinstaller在Linux中创建python可执行文件,无法在Windows计算机上运行

如何在Windows 10上更改默认的python可执行文件?