-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLOaBIS.py
257 lines (228 loc) · 8.54 KB
/
LOaBIS.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
import sys, time, os, subprocess, csv, importlib, threading
from datetime import datetime
from tkinter import *
from tkinter.ttk import *
def execute(func=[],glob=[]):
for x in glob:
if x not in globals():
globals()[x]=glob[x]
for x in func:
try:
globals()[str(x)]()
except Exception as e:
elog(e)
def log(txt="",sy=0):
with open("log.txt","a") as y:
y.write("["+str(datetime.now())+"] - "+txt[0].upper()+txt[1:]+"\n")
if sy:
say(txt,console=1)
def elog(err="",sy=1):
log("Error: "+str(type(err))+"; "+str(err))
if sy:
say("Software encountered an error, consider submitting log to developers","Error",1)
def elapsed(start=datetime.now(),text=""):
_time=divmod((datetime.now()-start).total_seconds(),60)
log(text+" complete, took "+str(_time[0]*60+_time[1])+" seconds")
def getcom(text=""):
say(cli="",di="")
x=getdat(module.cwords,text,"null")
y=module.funcs[module.cwords.index(x)]
log("Function "+y+" called")
if y=="closesoftware":
return True
try:
globals()[y](text.replace(y,"").replace(x,""))
except Exception as e:
elog(e,0)
say("'"+text.split(" ")[0]+"' not executable\n")
return False
def listen(txt="",cli="System",console=0,di=": "):
say(txt,cli,console)
try:
if not console:
a=text.get("1.0",END)
b=a
while b==a:
b=text.get("1.0",END)
c=b.replace(a[:-2],"")[1:-2].replace(str(username)+di,"")
else:
int("")
except:
c=input(str(username)+di)
return c
def say(txt="",cli="System",console=0,di=": "):
try:
if not console:
text["state"]="normal"
text.insert(END,str(cli+di+txt+"\n"))
text.yview_pickplace("end")
text["state"]="disabled"
else:
int("")
except:
for x in str(cli+di+txt)+"\n":
sys.stdout.write(x)
time.sleep(0.003)
def gettext(event=""):
m=mtxt.get()
if len(m)>0:
mtxt.set("")
say(str(m),str(username))
def interface():
width,height,x,y=getgeometry()
wwidth=350
ui=genwindow(str(core[0])+" v"+str(core[1])+" - "+str(core[3]),wwidth,height-75,310,200,width-wwidth-10)
module.ui=True
scrollbar = Scrollbar(ui)
globals()["text"]=Text(ui,state=DISABLED,width=36,height=8)
scrollbar.grid(row=0,column=1,sticky=N+S+E)
text.grid(row=0,columnspan=1,sticky=N+S+W+E,padx=5)
scrollbar.config(command=text.yview)
ui.grid_columnconfigure(0,weight=1)
ui.grid_rowconfigure(0,weight=1)
globals()["mtxt"] = StringVar()
textenter = Entry(ui,textvariable=mtxt)
textenter.bind("<Return>",gettext)
textenter.grid(row=1,column=0,sticky=W+E,padx=5)
b = Button(ui,text="Enter",width=5,command=gettext)
b.grid(row=1,column=1,columnspan=2)
ui.after(1000,lambda: checkclose(ui))
mainloop()
def checkclose(self):
if module.ui:
self.after(1000,lambda: checkclose(self))
else:
self.destroy()
if __name__=="__main__":
try:
globals()["shutdown"]=False
start_time=datetime.now()
log("Initialising software",1)
from _core import *
from _core import module
avoid=["__pycache__",".git"]
modules=getexcept(next(os.walk(os.getcwd()))[1],avoid)
modules.sort()
log(str(len(modules))+" Modules located: "+str(modules))
log("Loading module data",1)
modinfo,_mods=[],[]
for x in modules:
modinfo.append(getinfo(x))
_mods.append(getinfo(x))
core,_mods=getdat(modinfo,"LOaBIS Core"),getexcept(_mods,"LOaBIS Core")
log(str(core[0])+" v"+str(core[1])+" Loaded",1)
subprocess.call("title "+str(core[0])+" v"+str(core[1])+" - "+str(core[3]),shell=True)
stype=[0,0,0,[],[],[],"prevented","unstable","stable"]
log("Fetching pip modules",1)
pipmods=getpip()
log("Fetching dependancies",1)
for x in _mods:
tmp,tma=[],[]
if x[6]:
for y in x[6]:
if getdat(getexcept(modinfo,x[0]),y):
tma.append(modinfo.index(getdat(modinfo,y)))
else:
stype[0]+=1
tmp.append(y)
for y in x[7]:
if not getdat(pipmods,y):
tmp+=module.inst(y)
b=simver(core[1],x[2])
if b:
stype[b]+=1
stype[5-b].append(x[0]+" v"+x[1])
else:
tmp.append(1)
if tmp:
log(str(x[0])+" missing "+str(len(tmp))+" dependancies: "+str(tmp))
stype[5].append(x[0]+" v"+x[1])
modinfo.remove(x)
elif tma:
modinfo.insert(1+max(tma),x)
for x in range(3):
log(str(stype[2-x])+" "+str(stype[8-x])+" modules: "+str(stype[3+x]))
say(str(sum(stype[1:3]))+" modules loaded, "+str(stype[0])+" prevented from loading")
import_start=datetime.now()
fn=[["sta",0,0],["shu",0,0],["per",0,0],["pst",0,0],["rep",0,0]]
log("Importing module functions",1)
for x in modinfo:
a,b,d=0,[],[0,0,0,0,0]
try:
if x != core:
exec("from "+str(x[0])+" import *")
try:
with open(str(x[0])+sep+"commands.txt","r") as f:
for row in csv.reader(f):
c=row[0].split(":")[1]
module.funcs.append(c)
module.cwords.append(str(row[0].split(":")[0]+" ").replace(" "," "))
module.desc.append(row[1])
b.append(c)
log("Imported functions from "+str(x[0])+"; "+str(b))
a=1
except Exception as e:
elog(e)
except Exception as e:
log("unknown error, "+str(x[0])+" not loaded",1)
elog(e,0)
modinfo.pop(modinfo.index(x))
if a:
for y in x[8]:
module.stafunc.append(y)
d[0]+=1
for y in x[9]:
module.endfunc.append(y)
d[1]+=1
for y in x[10]:
module.perfunc.append(y)
d[2]+=1
for y in x[11]:
module.pstfunc.append(y)
d[3]+=1
for y in x[12]:
try:
globals()[y[0]]=globals()[y[1]]
d[4]+=1
except:
pass
for x in range(len(d)):
fn[x][1:3]=fn[x][1]+d[x],fn[x][2]+int(bool(d[x]))
for x in fn:
if x[1]:
log(str(x[1])+" "+str(x[0])+" functions loaded from "+str(x[2])+" modules")
module.funcs.append("null")
module.cwords.append("null")
module.desc.append("null")
for x in modules:
importlib.reload(sys.modules[x])
elapsed(import_start,"Function initialisation")
log("Executing final procedures",1)
if module.stafunc:
log("Running startup functions",1)
execute(module.stafunc,globals())
if (module.perfunc or module.pstfunc) and getelse(module.settings,"persist",False):
log("Running persistence handler")
pers=threading.Thread(name="Persistence",target=lambda:subprocess.call(["python","persistent.py",repr(modinfo)],creationflags=subprocess.CREATE_NEW_CONSOLE))
pers.start()
server,client=startsock()
elapsed(start_time,"Startup")
log("Initialisation complete, loading interface",1)
if getelse(module.settings,"gui",False):
_ui=threading.Thread(target=interface,name="Ui",daemon=True)
_ui.start()
time.sleep(1)
while not globals()["shutdown"]:
globals()["shutdown"]=getcom(listen("What would you like to do?"))
module.ui=False
end_time=datetime.now()
if (module.perfunc or module.pstfunc) and module.settings["persist"]:
msg(client,"shutdown")
server.close()
if module.endfunc:
log("Running shutdown functions",1)
execute(module.endfunc)
elapsed(end_time,"Shutdown")
log("Software shutdown successfully\n",1)
except Exception as e:
elog(e)