aboutsummaryrefslogtreecommitdiffstats
path: root/capstone/suite/patch_major_os_version.py
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /capstone/suite/patch_major_os_version.py
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'capstone/suite/patch_major_os_version.py')
-rwxr-xr-xcapstone/suite/patch_major_os_version.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/capstone/suite/patch_major_os_version.py b/capstone/suite/patch_major_os_version.py
new file mode 100755
index 000000000..d5036e887
--- /dev/null
+++ b/capstone/suite/patch_major_os_version.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# By Daniel Pistelli & Nguyen Tan Cong
+
+# This script is to patch DLL/EXE MajorVersion to 5,
+# so they can be loaded by Windows XP.
+# This is the problem introduced by compiling on Windows 7, using VS2013.
+
+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)