2009-08-12 108 views
1

我想用Python來得到執行的文件版本,然後我知道pefile.py我怎麼能使用的「pefile.py」獲取文件(.exe)的版本

如何用它來做到這一點?

備註:執行的文件可能不完全。

+1

這是屬於計算器 – 2009-08-12 08:47:54

+2

歡迎計算器。此問題現在已成爲http://stackoverflow.com/questions/1264472/using-the-pefile-py-to-get-file-exe-version的欺騙 – innaM 2009-08-12 09:11:17

回答

2

我不知道我理解正確,你的問題,但如果它是沿着使用pefile檢索提供可執行文件的版本,那麼也許

(從[教程] [1]所)線的東西
import pefile 
pe = pefile.PE("/path/to/pefile.exe") 
print pe.dump_info() 

將爲您提供版本信息。我不知道在解析不完整的文件時pefile文件是多麼的明智,但是猜測版本信息是在頭文件中的某處,並且pefile使用一個生成器來讀取文件,那麼如果頭文件是可解析的,應該可以讀取信息。

4

這是最好的答案,我認爲你可以找到:

import pefile 
pe = pefile.PE("/path/to/something.exe") 

print hex(pe.VS_VERSIONINFO.Length) 
print hex(pe.VS_VERSIONINFO.Type) 
print hex(pe.VS_VERSIONINFO.ValueLength) 
print hex(pe.VS_FIXEDFILEINFO.Signature) 
print hex(pe.VS_FIXEDFILEINFO.FileFlags) 
print hex(pe.VS_FIXEDFILEINFO.FileOS) 
for fileinfo in pe.FileInfo: 
    if fileinfo.Key == 'StringFileInfo': 
    for st in fileinfo.StringTable: 
     for entry in st.entries.items(): 
     print '%s: %s' % (entry[0], entry[1])  
    if fileinfo.Key == 'VarFileInfo': 
    for var in fileinfo.Var: 
     print '%s: %s' % var.entry.items()[0] 

From Ero Carrera's (the author of pefile.py) own blog

+1

我試過這在NSIS安裝程序二進制文件沒有成功('fileinfo.StringTable'沒有定義)。 [我想出了一個解決方案](http://stackoverflow.com/a/16076661/274483)使用'pe.VS_FIXEDFILEINFO.ProductVersionMS','pe.VS_FIXEDFILEINFO.ProductVersionLS'屬性。 – flocki 2013-04-18 07:19:40

相關問題