-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameexePacker.py
67 lines (58 loc) · 1.55 KB
/
GameexePacker.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
# -*- coding: utf-8 -*-
# For Windows OS Only....
import sys
import os
import struct
from Decryption import Decrypt1,Decrypt4,FakeCompress,Compress
def main(argv,key):
if argv.count('-p')>0:
needKey=True
argv.remove('-p')
else:
needKey=False
if argv.count('-c')>0:
try:
comp=int(argv[argv.index('-c')+1])
except:
comp=17
else:
argv.pop(argv.index('-c')+1)
if comp<2:
comp=2
elif comp>17:
comp=17
argv.remove('-c')
else:
comp=0
if len(argv)<2 or argv[1]=='':
print ("Usage: "+argv[0][argv[0].rfind("\\")+1:]+" <Gameexe.ini> [Gameexe.dat2] [-p] [-c]")
return False
if len(argv)<3 or argv[2]=='':
outFN="Gameexe.dat2"
else:
outFN=argv[2]
try:
ini=open(argv[1],'rb')
ini.read(2)
except:
return False
data=ini.read()
ini.close()
size=len(data)
if comp:
compData=Compress(data,comp)
else:
compSize=size+int(size/8)+8
if not size%8==0:
compSize+=1
compData=struct.pack('2I',compSize,size)+FakeCompress(data)
if needKey:
outData=b'\x00\x00\x00\x00\x01\x00\x00\x00'+Decrypt4(Decrypt1(compData,key))
else:
outData=b'\x00\x00\x00\x00\x00\x00\x00\x00'+Decrypt4(compData)
output=open(outFN,'wb')
output.write(outData)
output.close()
return True
if __name__=="__main__":
main(sys.argv,[])