annyoung

python ctypes GetFileVersion 본문

프로그래밍

python ctypes GetFileVersion

nopsled 2016. 11. 9. 23:39

몇일 전부터 혼자 삽질해보려고 했는데 국방망이라서 할수도 없고... 열심히 기본적으로 제공해주는 모듈로도 할 수 있을꺼같아서 사지방에서 검색하고 또 검색해서 찾은 아웃풋..

 

import array
from ctypes import *


def get_file_info(filename, info):
    size = windll.version.GetFileVersionInfoSizeA(filename, None)
    if not size:
        return ''
    res = create_string_buffer(size)
    windll.version.GetFileVersionInfoA(filename, None, size, res)
    r = c_uint()
    l = c_uint()
    windll.version.VerQueryValueA(res, '\\VarFileInfo\\Translation',
                                  byref(r), byref(l))
    if not l.value:
        return ''
    codepages = array.array('H', string_at(r.value, l.value))
    codepage = tuple(codepages[:2].tolist())
    windll.version.VerQueryValueA(res, ('\\StringFileInfo\\%04x%04x\\'
+ info) % codepage,byref(r), byref(l))
    return string_at(r.value, l.value)


print get_file_info(r'C:\WINDOWS\system32\calc.exe', 'FileVersion')

출처 : https://mail.python.org/pipermail//python-list/2006-November/402797.html

 

기본적으로 제공해주는 ctypes와 array 모듈... 처음에 API도 없다고 떠서 한참 고민했다.

 

get_file_info의 두번째 파라미터인 info에는 Comments, CompanyName, FileDescription, InternalName, LegalCopyright, OriginalFilename, ProductVersion, ProductName, FileVersion 등등이 들어갈 수 있다.

 

python Get File Version from binary

'프로그래밍' 카테고리의 다른 글

[javascript] calculate datetime  (0) 2018.04.24
[javascript] get ip only using javascript  (5) 2018.04.19
python 윈도우 한글문제  (0) 2016.04.26
python unicode unescape (html unescape)  (0) 2015.11.07
django standard install..  (0) 2015.10.13
Comments