간단하게 파이썬 pefile 라이브러리를 이용해 임포트 DLL과 SHA256 해시 값을 구하는 코드로 DLL별 함수갯수와 DLL 갯수 임포트된 전체 함수갯수를 구하고 파일 전체에 대한 SHA256 해시를 구해 출력하도록 되어있다.

 

아나콘다에서 PEfile 설치

더보기

conda install -c conda-forge pefile

 

from hashlib import sha256

import pefile

target_file = 'GOM.exe'

pe = pefile.PE(target_file)
pe.parse_data_directories()

tcnt = 0
dcnt = 0
try:
    for entry in pe.DIRECTORY_ENTRY_IMPORT:
        print(entry.dll)
        fcnt = 0
        dcnt = dcnt + 1
        for imp in entry.imports:
            try:
                print('\t', hex(imp.address), imp.name)
                fcnt = fcnt + 1
            except:
                pass
        print('import functions : ' + str(fcnt))
        tcnt = tcnt + fcnt
    print('')
    print('import dlls : ' + str(dcnt))
    print('total functions : ' + str(tcnt))
except:
    pass

print('------------------------------------------------')

data_f = open(target_file, 'rb')
data = data_f.read()
data_f.close()

data_hash = sha256(data).hexdigest()
print(data_hash)

 

위의 코드로 곰플레이어 실행파일를 지정해 수행한 결과는 아래와 같다.

...... (생략) ......
b'd3d9.dll'
	 0xa71d3c b'Direct3DCreate9'
import functions : 1
b'VERSION.dll'
	 0xa71c2c b'VerQueryValueW'
	 0xa71c30 b'GetFileVersionInfoW'
	 0xa71c34 b'GetFileVersionInfoSizeW'
import functions : 3
b'OLEACC.dll'
	 0xa716ec b'AccessibleObjectFromWindow'
	 0xa716f0 b'LresultFromObject'
	 0xa716f4 b'CreateStdAccessibleObject'
import functions : 3

import dlls : 27
total functions : 1015
------------------------------------------------
1717fa7af18aefb3bf57559dd7ae28ec7a10ab705442278d488e1c63d2b3ea72
Posted by 휘프노스
,