Skip to content

Commit

Permalink
Rather use r2 to get file version than pefile
Browse files Browse the repository at this point in the history
  • Loading branch information
zeronounours committed Dec 8, 2021
1 parent 8270411 commit 10c04a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 9 additions & 17 deletions Offsets/ExtractOffsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from json import loads, dumps
import subprocess

import pefile
from concurrent.futures import ThreadPoolExecutor
import threading
CSVLock = threading.Lock()
Expand Down Expand Up @@ -105,11 +104,15 @@ def get_field_offset(symbols_info, field_name):
return 0

def get_file_version(path):
pe = pefile.PE(path)
info = pe.VS_FIXEDFILEINFO[0]
ms = info.FileVersionMS
ls = info.FileVersionLS
return (ms >> 16, ms & 0xffff, ls >> 16, ls & 0xffff)
# dump version number using r2
r = run(["r2", "-c", "iV", "-qq", path], capture_output=True)
for line in r.stdout.decode().splitlines():
line = line.strip()
if line.startswith("FileVersion:"):
return [int(frag) for frag in line.split(" ")[-1].split(".")]

print(f'[!] ERROR : failed to extract version from {path}.')
exit(1)

def extractOffsets(input_file, output_file, mode):
if os.path.isfile(input_file):
Expand All @@ -131,17 +134,6 @@ def extractOffsets(input_file, output_file, mode):
if mode != imageType:
print(f"[*] Skipping {input_file} since we are in {mode} mode")
return
# dump version number
"""
r = run(["r2", "-c", "iV", "-qq", input_file], capture_output=True)
for line in r.stdout.decode().splitlines():
line = line.strip()
if line.startswith("FileVersion:"):
full_version = [int(frag) for frag in line.split(" ")[-1].split(".")]
break
else:
assert(False)
"""
if os.path.sep not in input_file:
input_file = "." + os.path.sep + input_file
full_version = get_file_version(input_file)
Expand Down
1 change: 0 additions & 1 deletion Offsets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
requests
pefile

0 comments on commit 10c04a9

Please sign in to comment.