-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlackPythonHelper.py
More file actions
249 lines (230 loc) · 6.56 KB
/
BlackPythonHelper.py
File metadata and controls
249 lines (230 loc) · 6.56 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import sys
import io
from typing import Optional, List
import argparse
_build_to_game_version = {
2870186: "1.0.0",
3700114: "1.7.2",
3724489: "1.8.0",
3729133: "1.8.1",
3741772: "1.8.2",
3757339: "1.9",
3775276: "1.9.1",
3790078: "1.10",
3807424: "1.11",
3825894: "2.1",
3841827: "2.2",
3847564: "2.3",
3858292: "2.4",
3870737: "2.4.2",
3889387: "2.5",
3901517: "3.0.0",
3915963: "3.1",
3917250: "3.1.1",
3935073: "3.2",
3942182: "3.3",
4008490: "3.5",
4019403: "3.6",
4039451: "4.0",
4053532: "4.1",
4072250: "4.2",
4117433: "4.4",
4127312: "4.4.1",
4159770: "4.5",
4204761: "5.0",
4214610: "5.01",
4240749: "5.10",
4288479: "5.21",
4305896: "5.30",
4352937: "5.40",
4363240: "5.41",
4395664: "6.0",
4424678: "6.01",
4461277: "6.0.2",
4464155: "6.10",
4476098: "6.10.1",
4480234: "6.10.2",
4526925: "6.21",
4543176: "6.22",
4573279: "6.31",
4629139: "7.0",
4667333: "7.10",
4727874: "7.20",
4834550: "7.30",
5046157: "7.40",
5203069: "8.00",
5625478: "8.20",
5793395: "8.30",
6005771: "8.40",
6058028: "8.50",
6165369: "8.51",
6337466: "9.00",
6428087: "9.01",
6639283: "9.10",
6922310: "9.21",
7095426: "9.30",
7315705: "9.40",
7609292: "9.41",
7704164: "10.00",
7955722: "10.10",
8456527: "10.20",
8723043: "10.31",
9380822: "10.40",
9603448: "11.00",
9901083: "11.10",
10708866: "11.30",
10800459: "11.31",
11265652: "11.50",
11556442: "12.00",
11883027: "12.10",
12353830: "12.21",
12905909: "12.41",
13137020: "12.50",
13498980: "12.61",
14113327: "13.40",
14211474: "14.00",
14456520: "14.30",
14550713: "14.40",
14786821: "14.60",
14835335: "15.00",
15014719: "15.10",
15341163: "15.30",
15526472: "15.50",
15913292: "16.10",
16163563: "16.30",
16218553: "16.40",
16469788: "16.50",
16745144: "17.10",
17004569: "17.30",
17269705: "17.40",
17388565: "17.50",
17468642: "18.00",
17661844: "18.10",
17745267: "18.20",
17811397: "18.21",
17882303: "18.30",
18163738: "18.40",
18489740: "19.01",
18675304: "19.10",
19458861: "20.00",
19598943: "20.10",
19751212: "20.20",
19950687: "20.30",
20244966: "20.40",
20463113: "21.00",
20696680: "21.10",
21035704: "21.20",
21657658: "21.50",
}
def find_files(root: str, filename: str) -> List[str]:
matches = []
for dirpath, _, files in os.walk(root):
if filename in files:
matches.append(os.path.join(dirpath, filename))
return matches
def _extract_utf16le_strings(data: bytes, min_len: int = 8) -> List[str]:
results = []
try:
s = data.decode('utf-16le', errors='ignore')
parts = re.split(r'[\x00-\x1F]{2,}', s)
for p in parts:
if len(p) >= min_len:
results.append(p)
except Exception:
pass
return results
def _extract_ascii_strings(data: bytes, min_len: int = 8) -> List[str]:
results = []
try:
s = data.decode('latin-1', errors='ignore')
parts = re.split(r'[^ -~]+', s)
for p in parts:
if len(p) >= min_len:
results.append(p)
except Exception:
pass
return results
def _search_for_fortnite_header_in_file(path: str):
with open(path, 'rb') as f:
data = f.read()
needle = '++Fortnite'.encode('utf-16le')
idx = data.find(needle)
if idx != -1:
start = max(0, idx - 128)
try:
segment = data[start:start+4096]
decoded = segment.decode('utf-16le', errors='ignore')
pos = decoded.find('++Fortnite')
if pos != -1:
tail = decoded[pos:pos+512]
clean_line = tail.split('\x00')[0].strip()
return clean_line
except Exception:
pass
for extractor in (_extract_ascii_strings, _extract_utf16le_strings):
try:
candidates = extractor(data, min_len=6)
for cand in candidates:
if '++Fortnite' in cand:
clean_line = cand.split('\x00')[0].strip()
return clean_line
except Exception:
continue
return None
def _parse_game_version_from_header(value_str: str, default_version: str) -> str:
if not value_str:
return default_version
header_index = value_str.find('++Fortnite')
if header_index == -1:
return default_version
try:
m = re.search(r'\+\+Fortnite.*?Release-([0-9]+\.[0-9]+(?:\.[0-9]+)?)', value_str, flags=re.IGNORECASE)
if m:
game_version = m.group(1)
return game_version
m_cl = re.search(r'CL-(\d+)', value_str)
if m_cl:
cl_number = int(m_cl.group(1))
resolved = _build_to_game_version.get(cl_number)
if resolved:
return resolved
m2 = re.search(r'Release-([^\s\x00%+-]+)', value_str)
if m2:
game_version = m2.group(1)
if game_version not in ("Cert", "Next"):
return game_version
return default_version
except Exception:
return default_version
def has_fortnite_structure(directory: str) -> bool:
fortnite_game_path = os.path.join(directory, "FortniteGame")
engine_path = os.path.join(directory, "Engine")
return os.path.isdir(fortnite_game_path) or os.path.isdir(engine_path)
def extract_game_version(directory: str) -> Optional[str]:
if not has_fortnite_structure(directory):
return None
default_game_version = os.path.basename(os.path.normpath(directory))
matches = find_files(directory, "CrashReportClient.exe")
if not matches:
return default_game_version
target = matches[-1]
header = _search_for_fortnite_header_in_file(target)
if not header:
return default_game_version
return _parse_game_version_from_header(header, default_game_version)
def main():
if sys.stdout.encoding != 'utf-8':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-path')
args = parser.parse_args()
directory = args.path
version = extract_game_version(directory)
if version:
print(f"[VERSION] {version}")
if __name__ == '__main__':
main()