-
Notifications
You must be signed in to change notification settings - Fork 0
/
dash-patcher.py
94 lines (69 loc) · 2.02 KB
/
dash-patcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import sys
def printHelp():
print("Usage: dash-patcher.py [OPTIONS]\n")
print("Options: ")
print("patch Patch dash2.dll into dash2.exe")
print("unpatch Restore dash2.exe back to default")
print("-h Print help menu")
#mml2 exe we want to patch
pe = 'dash2.exe'
def byte2ascii(hval):
ascii_object = hval.decode("utf-8")
return ascii_object
def byte2int(hval):
int_object = int.from_bytes(hval, "little")
return int_object
def patchCheck(dll):
dll = byte2ascii(dll)
if dll == "dash2.dll":
return True
elif dll == "ole32.dll":
return False
def patchDll(f):
f.seek(0x23083E, 0)
f.write(str.encode("dash2.dll"))
def unpatchDll(f):
f.seek(0x23083E, 0)
f.write(str.encode("ole32.dll"))
def patch():
with open(pe, "r+b") as f:
f.seek(0x23083E, 0)
dll = f.read(9)
if patchCheck(dll):
print("Game is already patched.")
return
else:
patchDll(f)
f.seek(0x23083E, 0)
dll = f.read(9)
if patchCheck(dll):
print("Game patched successfully!")
if not patchCheck(dll):
print("Patching failed. Please restore dash2.exe from a backup and try again.")
def unpatch():
with open(pe, "r+b") as f:
f.seek(0x23083E, 0)
dll = f.read(9)
if not patchCheck(dll):
print("No patch detetcted.")
return
else:
unpatchDll(f)
f.seek(0x23083E, 0)
dll = f.read(9)
if patchCheck(dll):
print("Patching revert failed. Please restore dash2.exe from a backup")
if not patchCheck(dll):
print("Patch reverted successfully!")
if __name__ == "__main__":
if len(sys.argv) > 1:
patchMode = sys.argv[1]
else:
printHelp()
exit()
if patchMode == "patch":
patch()
elif patchMode == "unpatch":
unpatch()
else:
printHelp()