查找二进制文件的版本 [英] Find Version of Binary File
问题描述
有人知道如何找到已传递给函数的二进制文件的版本吗?
Does anyone know how I can find the version of a binary file that has been passed to my function?
我从这里页面:
def version(fpath):
f = open(fpath, 'rb')
s = f.read(1024)
print s
f.close()
但是,这并没有给我任何类似于上述网站显示的有用输出.
However, this does not give me any useful output similar to what the mentioned website shows.
编辑:@BoazYaniv告诉我文件格式在此问题中起着重要的作用.这是Windows EXE档案
Edit: @BoazYaniv tells me that the file format plays in important part in this problem. This is a windows EXE file
推荐答案
我们使用此代码从我们的一个可执行文件中提取版本,以供其他程序使用.
We use this code to pull versions from one of our executables for use throughout other programs.
import win32api
try:
info = win32api.GetFileVersionInfo('rpmsrv.exe', "\\")
ms = info['FileVersionMS']
ls = info['FileVersionLS']
__version__ = "%d.%d.%d.%d" % (win32api.HIWORD(ms), win32api.LOWORD (ms),
win32api.HIWORD (ls), win32api.LOWORD (ls))
except:
__version__ = '5.1.1.000' # some appropriate default here.
---包含评论---
--- To encompass the comments ---
这要求安装Windows绑定的Python.它们在此处可用: http://starship.python.net/~skippy/win32/一个>.这也将这种解决方案限制在Windows平台上(在最终项目中这可能是重要因素,也可能不是重要因素).
This requires that the Windows Bindings for Python be installed. They're available here: http://starship.python.net/~skippy/win32/. This also limits this solution to Windows platforms (which may or may not be an important factor in the final project).
这篇关于查找二进制文件的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!