-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.py
151 lines (107 loc) · 5.26 KB
/
main.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
TODO: clean this
"""
import os
# CD to script path
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
import sys
import time
from PIL import ImageFont
from core.utils import config
from core.plugin import *
from core.pil_simplify import tinyPillow
if __name__ == "__main__":
#region run usb gadget
print("[USB] initializing usb gadget...")
os.system("/bin/SteinarUSB")
#endregion
#region setup display driver
screenType = config["menu"]["screenType"]
menus = pwnhyveMenuLoader()
selectedMenu = menus.modules[screenType]["module"]
driverLoader = pwnhyveScreenLoader(config["display"]["driver"])
if driverLoader.driver == None:
driverLoader = pwnhyveScreenLoader("headless")
dispDriver = driverLoader.driver
print("[DISPLAY] initalizing display driver...", end="")
disp = driverLoader.driver.DisplayDriver(selectedMenu)
image, draw = disp.image, disp.draw
tinypil = tinyPillow(draw, disp, image)
print("initalized.\n")
#endregion end of display setup
#region load plugins
print('[PLUGINS] initializing plugins and menus...', end="")
plugPath = config["plugins"]["pluginsPath"]
plugins = pwnhyvePluginLoader(folder=plugPath.replace("./", ""))
plugins.moduleList += ["/"+x for x in os.listdir(plugPath) if os.path.isdir(plugPath+x) and not x.startswith("_")]
currentDirectory = ""
print("initalized.")
#endregion end of plugin load
print("[MENU] READY. HACK THE PLANET!")
pluginsAndDirectories = plugins.moduleList
previousModuleLoaded = None
while 1:
selection = 0
disp.fullClear(draw)
# button stuff
fontSize = round(disp.height / 8)
while True:
key = disp.gui.menu(
pluginsAndDirectories,
disableBack=currentDirectory=="",
icons=plugins.icons
)
if key == None: # user entered back, so go back 1 directory
a = currentDirectory.split("/")
currentDirectory = '/'.join(a[:len(a)-1])
if currentDirectory == "": # at main menu
for module, modulePtr in plugins.loadedPluginModules.copy().items(): # unload modules to save memory
del sys.modules[module]
del plugins.loadedPluginModules[module]
del modulePtr
try:
modulePtr.__dir__()
except Exception as e:
print("[UNLOADER] unloaded plugin \"{}\": {}".format(module, e))
dire = (plugPath.replace("./", "")+currentDirectory).replace("//", "/") # what the fuck am i doin
plugins = pwnhyvePluginLoader(folder=dire)
pluginsAndDirectories = plugins.moduleList + ["/"+x for x in os.listdir(dire) if os.path.isdir("./"+dire) and not x.startswith("_") and ".py" not in x]
#print("LDIR: {}".format(currentDirectory))
continue
# user selected a directory, so open the directory and load any plugins in it
pluginPath = (plugPath+currentDirectory).replace("//", "/")
if key in ['/'+pluginPathFolders for pluginPathFolders in os.listdir(pluginPath) if os.path.isdir(os.path.join(pluginPath, pluginPathFolders))]:
# example directory structure
# |- plugins
# |- test
# | \ a.py
# |- test2
# | \ b.py
# | c.py
currentDirectory += key
print("[MENU] loading "+currentDirectory)
disp.fullClear(draw)
disp.draw.text((round(disp.width/3), round(disp.height/4)), "loading...", font=ImageFont.truetype('core/fonts/tahoma.ttf', fontSize))
disp.screenShow()
dire = (plugPath.replace("./", "")+currentDirectory+"/").replace("//", "/") # what the fuck am i doin
plugins = pwnhyvePluginLoader(folder=dire) # "test"
pluginsAndDirectories = plugins.moduleList + ["/"+x for x in os.listdir(dire) if os.path.isdir("./"+dire+"/"+x) and not x.startswith("_") and ".py" not in x]
print('[MENU] finished loading')
break
else: # user selected a plugin module, so run the plugin module
print("[MENU] running plugin \"{}\"".format(currentDirectory+"/"+key))
print("[MENU] DISCLAIMER: unless this is an official pwnhyve plugin, any errors that come up after this message are NOT ASSOCIATED WITH PWNHYVE. CONTACT THE PLUGIN'S DEVELOPER TO FIX IT.")
print("\n" + "/\\"*30)
startPluginTime = time.time()
plugins.run(
plugins.getOriginModule(key),
key,
tinypil
)
print("/\\"*30)
print("\n[MENU] ran plugin \"{}\" - took {} seconds".format(currentDirectory+"/"+key, round(time.time()-startPluginTime, 3)))
break