forked from Al-Azif/ps4-exploit-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-static.py
385 lines (295 loc) · 18.6 KB
/
build-static.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import hashlib
import json
import os
import shutil
import sys
from urllib.parse import quote
CWD = ""
if getattr(sys, "frozen", False):
# PyInstaller
CWD = os.path.abspath(os.path.dirname(sys.executable))
elif __file__:
# Script
CWD = os.path.dirname(os.path.realpath(__file__))
def UNUSED(variable):
return variable
def get_categories():
output = {}
for entry in os.scandir(os.path.join(CWD, "exploits")):
if entry.is_dir(follow_symlinks=False):
new_data = {}
finished_data = {
entry.name: {
"title": entry.name,
"device": "",
"firmware": "",
"user_agents": [],
"notes": {
"default": ""
},
"offline": False
}
}
try:
with open(os.path.join(CWD, "exploits", entry.name, "meta.json"), "rb") as buf:
new_data = json.loads(buf.read())
except (IOError, PermissionError, json.decoder.JSONDecodeError):
pass
try:
del new_data["title"]
except KeyError:
pass
finished_data[entry.name].update(new_data)
output.update(finished_data)
if not output:
output = {
"error": True,
"message": "No Categories Found"
}
return output
def get_entries(entry_path):
output = {}
for entry in os.scandir(os.path.join(CWD, "exploits", entry_path)):
if entry.is_dir(follow_symlinks=False):
new_data = {}
finished_data = {
entry.name: {
"title": entry.name,
"version": "",
"updated": "2001-01-01T00:00:00Z",
"device": "",
"firmware": "",
"description": {
"default": ""
},
"author": "",
"url": "",
"redirect": True,
"reload": False,
"offline": False
}
}
try:
with open(os.path.join(CWD, "exploits", entry_path, entry.name, "meta.json"), encoding="utf-8") as buf:
new_data = json.loads(buf.read())
except (IOError, PermissionError, json.decoder.JSONDecodeError):
pass
try:
del new_data["title"]
except KeyError:
pass
finished_data[entry.name].update(new_data)
output.update(finished_data)
if not output:
output = {
"error": True,
"message": "No Entries Found"
}
return output
def get_menu():
categories = get_categories()
if categories == {"error": True, "message": "No Categories Found"}:
return categories
for key, value in categories.items():
UNUSED(value)
categories[key]["entries"] = get_entries(key)
return categories
def get_theme_settings(settings_file):
output = {}
with open(settings_file, "rb") as buf:
data = json.loads(buf.read())
output["languages"] = data["Languages"]
output["themes"] = []
for entry in os.scandir(os.path.join(CWD, "themes")):
if entry.is_dir(follow_symlinks=False):
output["themes"].append(entry.name)
return output
def get_themes_manifest():
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
manifest += "./\n"
manifest += "./index.html\n"
manifest += "./blank.html\n"
manifest += "./api/theme_settings.json\n"
manifest += "./api/menu.json\n"
for path, subdirs, files in os.walk(os.path.join(CWD, "themes")):
UNUSED(subdirs)
for filename in files:
if not filename.endswith(".es6"): # Maybe exclued dotfiles and delete them in the clean up phase
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += ".{}\n".format(quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += "\nSETTINGS:\n"
manifest += "prefer-online\n"
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
return manifest
def get_all_manifest():
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
for path, subdirs, files in os.walk(os.path.join(CWD, "exploits")):
UNUSED(subdirs)
for filename in files:
if filename not in ("meta.json", "PUT EXPLOITS HERE"):
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += "../..{}\n".format(quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
return manifest
def get_category_manifest(category):
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
for path, subdirs, files in os.walk(os.path.join(CWD, "exploits", category)):
UNUSED(subdirs)
for filename in files:
if filename != "meta.json":
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += "../../..{}\n".format(quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
return manifest
def get_entry_manifest(category, entry):
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
for path, subdirs, files in os.walk(os.path.join(CWD, "exploits", category, entry)):
UNUSED(subdirs)
for filename in files:
if filename != "meta.json":
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += "../../../..{}\n".format(quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
return manifest
def main():
parser = argparse.ArgumentParser(description="PS4 Exploit Host Static Builder")
parser.add_argument("--output", dest="output", action="store",
default=os.path.join(CWD, "output"),
required=False, help="Specify a output location")
parser.add_argument("--settings", dest="settings", action="store",
default=os.path.join(CWD, "settings.json"),
required=False, help="Specify a settings file")
args = parser.parse_args()
try:
shutil.rmtree(args.output)
except NotADirectoryError:
print("Error, specified location already exists as a file")
sys.exit(1)
except FileNotFoundError:
pass
while os.path.exists(args.output):
pass
os.makedirs(args.output)
# --- Add APIs --------------------------------------------------------------
os.makedirs(os.path.join(args.output, "api"))
# Generate Menu
menu = get_menu()
# Add /api/menu
with open(os.path.join(args.output, "api", "menu.json"), "w+", encoding="utf-8") as buf:
buf.write(json.dumps(menu, sort_keys=True))
# Add /api/settings
with open(os.path.join(args.output, "api", "theme_settings.json"), "w+", encoding="utf-8") as buf:
buf.write(json.dumps(get_theme_settings(args.settings), sort_keys=True))
# --- Add theme redirector --------------------------------------------------
with open(os.path.join(args.output, "index.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Theme Loader</title></head><body><script>"use strict";window.addEventListener("load",function(){var a=new Date;a.setTime(a.getTime()+3153600000000);var b=a.toUTCString();2!=="; ".concat(document.cookie).split("; theme=").length&&(document.cookie="theme=Default; expires=".concat(b,"; domain=").concat(window.location.hostname,"; path=").concat(window.location.pathname,";"));var c=new XMLHttpRequest;c.open("GET","./themes/".concat("; ".concat(document.cookie).split("; theme=").pop().split(";").shift(),"/index.html"),!0),c.onload=function(){200<=c.status&&400>c.status?(window.history.replaceState({location:decodeURIComponent(window.location.hash.substr(1)),modal:!1},null,window.location.hash?window.location.hash:" "),document.open(),document.write(c.responseText),document.close()):"Default"==="; ".concat(document.cookie).split("; theme=").pop().split(";").shift()?alert("Error retrieving default theme data. Check your setup."):(document.cookie="theme=Default; expires=".concat(b,"; domain=").concat(window.location.hostname,"; path=").concat(window.location.pathname,";"),navigator.onLine?alert("Error retrieving theme data, resetting theme to default and reloading."):alert("Error retrieving theme data, you are currently offline, it is likely you switched to a theme that you have yet to use while online (So it is not cached). Resetting theme to default and reloading."),window.location.reload())},c.onerror=function(){"Default"==="; ".concat(document.cookie).split("; theme=").pop().split(";").shift()?alert("Error retrieving default theme data. Check your setup."):(document.cookie="theme=Default; expires=".concat(b,"; domain=").concat(window.location.hostname,"; path=").concat(window.location.pathname,";"),navigator.onLine?alert("Error retrieving theme data, resetting theme to default and reloading."):alert("Error retrieving theme data, you are currently offline, it is likely you switched to a theme that you have yet to use while online (So it is not cached). Resetting theme to default and reloading."),window.location.reload())},c.send()});</script></body></html>')
# --- Add blank.html --------------------------------------------------------
with open(os.path.join(args.output, "blank.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Deus Machina</title></head><body><pre>ZmzJCgLnJ43j2FK4NUR/EmFc7hJRN7Ub4adlqCRLfsXoswDsjyvn5vGwLj2FZdOlVLNmi/l0mjiuHgCYSZqPSndVhg6U8ODSl1+/aDxQLZE=</pre></body></html>')
# --- Copy News -------------------------------------------------------------
shutil.copy(os.path.join(CWD, "news.json"), os.path.join(args.output, "news.json"))
# --- Copy Themes------------------------------------------------------------
shutil.copytree(os.path.join(CWD, "themes"), os.path.join(args.output, "themes"))
# --- Copy Exploits ---------------------------------------------------------
shutil.copytree(os.path.join(CWD, "exploits"), os.path.join(args.output, "exploits"))
# --- Add Cachers -----------------------------------------------------------
os.makedirs(os.path.join(args.output, "cache", "theme"))
os.makedirs(os.path.join(args.output, "cache", "all"))
os.makedirs(os.path.join(args.output, "cache", "category"))
os.makedirs(os.path.join(args.output, "cache", "entry"))
# Theme Cacher
with open(os.path.join(args.output, "cache", "theme", "index.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html manifest="./../../themes.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading-theme")},window.applicationCache.onprogress=function(a){parent.cacheProgress(Math.round(100*(a.loaded/a.total)))},window.applicationCache.oncached=function(){parent.cacheInterface("oncached-theme")},window.applicationCache.onupdateready=function(){parent.cacheInterface("onupdateready-theme")},window.applicationCache.onnoupdate=function(){parent.cacheInterface("onnoupdate-theme")},window.applicationCache.onerror=function(){parent.cacheInterface("onerror-theme")},window.applicationCache.onobsolete=function(){parent.cacheInterface("onobsolete-theme")}}catch(a){parent.cacheInterface("onerror-appcache")}</script></body></html>')
# All Cacher
with open(os.path.join(args.output, "cache", "all", "index.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html manifest="./offline.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading")},window.applicationCache.onprogress=function(a){parent.cacheProgress(Math.round(100*(a.loaded/a.total)))},window.applicationCache.oncached=function(){parent.cacheInterface("oncached")},window.applicationCache.onupdateready=function(){parent.cacheInterface("onupdateready")},window.applicationCache.onnoupdate=function(){parent.cacheInterface("onnoupdate")},window.applicationCache.onerror=function(){parent.cacheInterface("onerror")},window.applicationCache.onobsolete=function(){parent.cacheInterface("onobsolete")}}catch(a){parent.cacheInterface("onerror-appcache")}</script></body></html>')
# Category Cachers
for category in menu:
os.makedirs(os.path.join(args.output, "cache", "category", category))
with open(os.path.join(args.output, "cache", "category", category, "index.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html manifest="./offline.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading")},window.applicationCache.onprogress=function(a){parent.cacheProgress(Math.round(100*(a.loaded/a.total)))},window.applicationCache.oncached=function(){parent.cacheInterface("oncached")},window.applicationCache.onupdateready=function(){parent.cacheInterface("onupdateready")},window.applicationCache.onnoupdate=function(){parent.cacheInterface("onnoupdate")},window.applicationCache.onerror=function(){parent.cacheInterface("onerror")},window.applicationCache.onobsolete=function(){parent.cacheInterface("onobsolete")}}catch(a){parent.cacheInterface("onerror-appcache")}</script></body></html>')
# Entry Cachers
for entry in menu[category]["entries"]:
os.makedirs(os.path.join(args.output, "cache", "entry", category, entry))
with open(os.path.join(args.output, "cache", "entry", category, entry, "index.html"), "w+", encoding="utf-8") as buf:
buf.write('<!DOCTYPE html><html manifest="./offline.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading")},window.applicationCache.onprogress=function(a){parent.cacheProgress(Math.round(100*(a.loaded/a.total)))},window.applicationCache.oncached=function(){parent.cacheInterface("oncached")},window.applicationCache.onupdateready=function(){parent.cacheInterface("onupdateready")},window.applicationCache.onnoupdate=function(){parent.cacheInterface("onnoupdate")},window.applicationCache.onerror=function(){parent.cacheInterface("onerror")},window.applicationCache.onobsolete=function(){parent.cacheInterface("onobsolete")}}catch(a){parent.cacheInterface("onerror-appcache")}</script></body></html>')
# --- Add Manifests ---------------------------------------------------------
# Theme Manifest
with open(os.path.join(args.output, "themes.manifest"), "w+", encoding="utf-8") as buf:
buf.write(get_themes_manifest())
# All Manifest
with open(os.path.join(args.output, "cache", "all", "offline.manifest"), "w+", encoding="utf-8") as buf:
buf.write(get_all_manifest())
# Category Manifests
for category in menu:
with open(os.path.join(args.output, "cache", "category", category, "offline.manifest"), "w+", encoding="utf-8") as buf:
buf.write(get_category_manifest(category))
# Entry Manifests
for entry in menu[category]["entries"]:
with open(os.path.join(args.output, "cache", "entry", category, entry, "offline.manifest"), "w+", encoding="utf-8") as buf:
buf.write(get_entry_manifest(category, entry))
# --- Cleanup ---------------------------------------------------------------
# Delete all meta.json files
for path, subdirs, files in os.walk(os.path.join(args.output, "exploits")):
UNUSED(subdirs)
for filename in files:
if filename == "meta.json":
os.remove(os.path.join(path, filename))
# Delete all *.es6 files from theme's folder
for path, subdirs, files in os.walk(os.path.join(args.output, "themes")):
for filename in files:
if filename.endswith(".es6"):
os.remove(os.path.join(path, filename))
# Delete "PUT EXPLOITS HERE" file
try:
os.remove(os.path.join(args.output, "exploits", "PUT EXPLOITS HERE"))
except FileNotFoundError:
pass
# TODO: Minify HTML, JS, and CSS
print("\nDone!")
if __name__ == "__main__":
main()
# Copyright (c) 2017-2024 Al Azif, https://github.com/Al-Azif/ps4-exploit-host
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.