forked from 4shadoww/hakkuframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
123 lines (98 loc) · 2.83 KB
/
api.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
# Copyright (C) 2015 – 2021 Noa-Emil Nissinen (4shadoww)
# Import python modules
import sys
import os
import traceback
# Append
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
# Import core modules
from core import command_handler
from core.module_manager import ModuleManager
from core.apistatus import *
api.enabled = True
# Exceptions
import core.exceptions
class Hakkuapi:
mm = None
ch = None
allowPrint = False
ModuleError = False
def disablePrint(self):
if self.allowPrint == False:
f = open(os.devnull, 'w')
sys.stdout = f
def enablePrint(self):
if self.allowPrint == False:
sys.stdout = sys.__stdout__
def __init__(self, allowPrint):
self.allowPrint = allowPrint
self.mm = ModuleManager
self.ch = command_handler.Commandhandler(self.mm, True)
def load_module(self, module):
self.disablePrint()
try:
self.ch.handle("use "+module)
modadd = sys.modules["modules."+module]
if modadd.conf['apisupport'] == False:
raise ApiNotSupported("this module doesn't support api")
except core.exceptions.ModuleNotFound:
self.enablePrint()
raise ModuleNotFound("error: module not found")
except:
self.enablePrint()
raise
self.enablePrint()
def unload_module(self):
self.disablePrint()
try:
self.ch.handle("back")
except:
self.enablePrint()
raise
self.enablePrint()
def setVariable(self, target, value):
self.disablePrint()
try:
self.ch.handle("set "+target+" "+value)
except core.exceptions.VariableError:
self.enablePrint()
raise VariableError("error: variable not found")
except:
self.enablePrint()
raise
self.enablePrint()
def runModule(self):
self.ModuleError = False
self.disablePrint()
try:
answer = self.ch.handle("run")
except:
self.enablePrint()
raise
self.enablePrint()
if type(answer) is core.exceptions.ModuleError:
self.ModuleError = True
return answer
def customCommand(self, command):
self.disablePrint()
try:
answer = self.ch.handle(command)
except:
self.enablePrint()
raise
self.enablePrint()
return answer
def runCommand(self, command):
self.disablePrint()
try:
self.ch.handle(command)
except:
self.enablePrint()
raise
self.enablePrint()
class ModuleNotFound(Exception):
pass
class VariableError(Exception):
pass
class ApiNotSupported(Exception):
pass