Skip to content

Commit

Permalink
add script to MajorOperatingSystemVersion and MajorSubsystemVersion i…
Browse files Browse the repository at this point in the history
…n PE header from 6 to 5
  • Loading branch information
tacoxnguyen committed May 6, 2015
1 parent 611e9d9 commit 09559a6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions suite/patch_major_os_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
# By Nguyen Anh Quynh

import sys, struct

if len(sys.argv) < 2:
print("Usage: %s <pe_file_path>" % sys.argv[0])
sys.exit(0)

pe_file_path = sys.argv[1]

with open(pe_file_path, "rb") as f:
b = f.read()

if not b.startswith("MZ"):
print("Not a PE file")
sys.exit(0)

e_lfanew = struct.unpack_from("<I", b, 0x3C)[0]
vb = struct.pack("<HHHHH", 5, 0, 0, 0, 5) # encode versions
# patches MajorOperatingSystemVersion and MajorSubsystemVersion
b = b[0:e_lfanew + 0x40] + vb + b[e_lfanew + 0x4A:]
# write back to file
with open(pe_file_path, "wb") as f:
f.write(b)

0 comments on commit 09559a6

Please sign in to comment.