-
Notifications
You must be signed in to change notification settings - Fork 17
/
dumpPakKey.py
168 lines (136 loc) · 5.59 KB
/
dumpPakKey.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import re
import sys
import codecs
import binascii
import os
import pyperclip
import json
## Pattern section
initPattern = b'\x48\x8D\x41\x1F\xC7\x45\xD8'
junkPattern = ["c745d4", "488d411fc745d8", "c745dc",
"c745e0", "c745e4", "c745e8", "c745ec"]
##
## Array section
offsetArray = []
dumpKeySectionList = []
##
## Error section
errorFile = "[!] Please provide a filename to proceed."
errorData = "[!] File specified doesn't exist, please proceed a valid file."
errorOffset = "[!] Something went wrong, no offset value has been set."
errorDumpKey = "[!] Something went wrong, can't dump bytes to array."
errorGenKey = "[!] Something went wrong, can't generate key."
errorCryptoData = "[!] Something went wrong, can't create Crypto.json file."
errorB64toBytes = "[!] Something went wrong, can't convert string to bytes."
##
## Function section
def incrementOffset(offset, jumpBytes):
for i in range(0, jumpBytes):
i = int(offset, 16)
i += 1
offset = hex(i)
offsetArray.append(offset)
def decrementOffset(offset, jumpBytes):
for i in range(0, jumpBytes):
i = int(offset, 16)
i -= 1
offset = hex(i)
offsetArray.append(offset)
def DumpKeyBlock():
for offset in offsetArray:
offset = int(offset, 16)
f.seek(offset, 0)
keyData = f.read(1)
keyData = binascii.hexlify(keyData)
dumpKeySectionList.append(keyData.decode('utf-8'))
def cleanGenKey(junkHex, hexBlock):
cleanHex = hexBlock
for trash in junkHex:
cleanHex = re.sub(trash, '', cleanHex)
print("[i] Pure [hex] key extracted: " + cleanHex)
b64 = codecs.encode(codecs.decode(cleanHex, 'hex'), 'base64').decode()
return b64
##
## argv contains data?!
if len(sys.argv) > 1:
fileName = sys.argv[1]
filePath = os.path.exists(fileName)
## Checking if file in argv exists, exec.
if filePath:
f = open(fileName, "rb")
data = f.read()
regex = re.compile(initPattern)
for match_obj in regex.finditer(data):
offset = match_obj.start()
print("[i] Pattern match found, our initial offset is: " + hex(offset))
offset = hex(offset)
## Add manualy initial offset to array
offsetArray.append(offset)
## Getting offset section (where are key stored), up and down from initial match
incrementOffset(offset, 45)
decrementOffset(offset, 11)
## Sortnig your offsets by increase (dafault sort option)
offsetArray.sort()
print("[i] Retreaving key offset section.")
print(*offsetArray)
if offsetArray:
DumpKeyBlock()
f.close()
print("[i] Retreaving key block section.")
print(*dumpKeySectionList)
else:
print(errorDumpKey)
if dumpKeySectionList:
## Generating base64 key from sorted HEX block
hex = ''.join(dumpKeySectionList)
## Filtering junk from key block and Gen key
b64 = cleanGenKey(junkPattern, hex).rstrip()
print("[i] Base64 Decription *.pak key: " + b64)
else:
print(errorGenKey)
## Json pattern generation
data = {}
types = {}
EncryptionKey = {}
data['$types'] = types
types['UnrealBuildTool.EncryptionAndSigning+CryptoSettings, UnrealBuildTool, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'] = "1"
types['UnrealBuildTool.EncryptionAndSigning+EncryptionKey, UnrealBuildTool, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'] = "2"
types['UnrealBuildTool.EncryptionAndSigning+SigningKeyPair, UnrealBuildTool, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'] = "3"
types['UnrealBuildTool.EncryptionAndSigning+SigningKey, UnrealBuildTool, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'] = "4"
data['$type'] = "1"
data['EncryptionKey'] = EncryptionKey
EncryptionKey['$type'] = "2"
EncryptionKey['Name'] = "null"
EncryptionKey['Guid'] = "null"
EncryptionKey['Key'] = b64
data['SigningKey'] = "null"
data['bEnablePakSigning'] = "true"
data['bEnablePakIndexEncryption'] = "true"
data['bEnablePakIniEncryption'] = "true"
data['bEnablePakUAssetEncryption'] = "true"
data['bEnablePakFullAssetEncryption'] = "false"
data['bDataCryptoRequired'] = "true"
data['PakEncryptionRequired'] = "true"
data['PakSigningRequired'] = "true"
data['SecondaryEncryptionKeys'] = "[ ]"
##
if b64:
Crypto = open('Crypto.json', 'w', encoding='utf-8')
json.dump(data, Crypto, ensure_ascii=False,
indent=4, sort_keys=True)
Crypto.close()
print(
"[i] Crypto.json was successfuly created with your dumped (Base64) key in it.")
b64likebytes = str.encode(b64)
if b64likebytes:
hexToClipboard = codecs.encode(codecs.decode(b64likebytes, 'base64'), 'hex').decode()
pyperclip.copy("0x" + hexToClipboard.upper())
print("[i] Raw [hex] key was added to your clipboard aka (Ctrl+V) where you want.")
else:
print(errorB64toBytes)
else:
print(errorCryptoData)
else:
print(errorData)
else:
print(errorFile)