forked from whatotter/pwnhyve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
190 lines (135 loc) · 6.71 KB
/
main.py
File metadata and controls
190 lines (135 loc) · 6.71 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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
TODO: clean this
"""
import os
import threading
# 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/pwnhyveUSB")
#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
finishedLoading = False
extraLoadingText = ""
while 1:
selection = 0
disp.fullClear(draw)
# button stuff
fontSize = round(disp.height / 8)
folders = ["/"+x for x in os.listdir(plugPath) if os.path.isdir("./"+plugPath) and not x.startswith("_") and ".py" not in x]
while True:
for folder in folders:
plugins.icons[folder] = "./core/icons/folder.bmp"
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
def threadedLoading(disp):
global finishedLoading
global extraLoadingText
loadings = [
"|", "/", "---", "\\", "|", "/", "---", "\\"
]
loadingIndex = 0
while not finishedLoading:
if loadingIndex == len(loadings):
loadingIndex = 0
disp.fullClear(draw)
disp.draw.text((round(disp.width/2), round(disp.height/2)), loadings[loadingIndex],
font=ImageFont.truetype('core/fonts/roboto.ttf', 24), anchor="mm")
disp.draw.text((2, 2), extraLoadingText,
font=ImageFont.truetype('core/fonts/roboto.ttf', 12))
disp.screenShow()
loadingIndex += 1
time.sleep(0.25)
finishedLoading = False
extraLoadingText = ""
loadingThread = threading.Thread(target=threadedLoading, args=(disp,), daemon=True)
loadingThread.start()
currentDirectory += key
print("[MENU] loading "+currentDirectory)
extraLoadingText = "Loading {}".format(currentDirectory)
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]
finishedLoading = True
loadingThread.join()
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