2

I want to used python to get the executed file version, and i know the pefile.py

how to used it to do this?

notes: the executed file may be not completely.

weide
  • 67
  • 1
  • 2
  • 4
  • 1
    This is belong to stackoverflow –  Aug 12 '09 at 08:47
  • 3
    Welcome to stackoverflow. This question has now become a dupe of http://stackoverflow.com/questions/1264472/using-the-pefile-py-to-get-file-exe-version – innaM Aug 12 '09 at 09:11
  • Possible duplicate of [using the "pefile.py" to get file(.exe) version](https://stackoverflow.com/questions/1264472/using-the-pefile-py-to-get-file-exe-version) – Jongware Jan 13 '19 at 00:37

2 Answers2

6

This is the best answer I think you can find:

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

evandrix
  • 6,041
  • 4
  • 27
  • 38
sroberts
  • 61
  • 1
  • 3
  • 2
    I have tried this on an NSIS-Installer binary without success (`fileinfo.StringTable` was not defined). [I came up with a solution](http://stackoverflow.com/a/16076661/274483) using the `pe.VS_FIXEDFILEINFO.ProductVersionMS`,`pe.VS_FIXEDFILEINFO.ProductVersionLS` attributes. – derflocki Apr 18 '13 at 07:19
  • 1
    Note that VS_FIXEDFILEINFO is now a list, so you need to use, e.g., pe.VS_FIXEDFILEINFO[0].ProductVersionMS. Also, see the responses to the original question http://stackoverflow.com/questions/1264472/using-the-pefile-py-to-get-file-exe-version for notes on speed improvements. – Erik Knowles Feb 18 '20 at 18:28
2

I'm not sure that I understand your problem correctly, but if it's something along the lines of using pefile to retrieve the version of a provided executable, then perhaps (taken from [the tutorial][1])

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

will provide you with the version information. I have no idea how sensible pefile is when parsing incomplete files, but conjecturing that the version information is somewhere in the header and that pefile uses a generator to read the file, then it should be possible to read the information if the header is parseable.

evandrix
  • 6,041
  • 4
  • 27
  • 38
Steen
  • 6,573
  • 3
  • 39
  • 56