-
Notifications
You must be signed in to change notification settings - Fork 2
/
request_handler.py
123 lines (100 loc) · 3.58 KB
/
request_handler.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
import logging
import pandas as pd
class DataHandler():
uuid: str
model_name: str
json_dict: dict
bin_dictionary: dict
data: pd.DataFrame
status: str
def __init__(self, uuid: str, data: dict, model_name: str):
self.uuid = uuid
self.model_name = model_name
self.json_dict = data
self.status = "starting"
self._clean_dict()
def _clean_dict(self):
functions: list = []
functions_temp: list = list(
self.get_functions())
for function in functions_temp:
if function not in functions:
functions.append(function)
self.json_dict["functionsMap"]["functions"] = functions
def _load_data(self):
pass
def get_functions(self) -> list:
return self.json_dict["functionsMap"]["functions"]
class TrainingRequest(DataHandler):
bin_name: str
def __init__(self, uuid: str, model_name: str, data: dict):
super().__init__(uuid, data, model_name)
self._load_data()
def _load_data(self):
try:
self.bin_name = self.json_dict["binaryName"]
functions: list = []
functions_temp: list = list(
self.get_functions())
for function in functions_temp:
if function not in functions:
functions.append(function)
for function in functions:
token_list = function['tokenList']
tokens = " ".join(token_list)
function["tokens"] = tokens
self.data = pd.DataFrame(functions)
except Exception as tr_exception:
raise Exception("invalid dataset") from tr_exception
class PredictionRequest(DataHandler):
task_name: str
uuid: str
json_dict: dict
data: pd.DataFrame
status: str
def __init__(self, uuid: str, model_name: str, data: dict):
super().__init__(uuid, data, model_name)
self.task_name = data["taskName"]
self._load_data()
def _load_data(self):
try:
functions: list = []
functions_temp: list = list(
self.get_functions())
for function in functions_temp:
if function not in functions:
functions.append(function)
for function in functions:
token_list = function['tokenList']
tokens = " ".join(token_list)
function["tokens"] = tokens
self.data = pd.DataFrame(functions)
except Exception as unknown_exception:
logging.error(unknown_exception)
raise Exception("invalid dataset") from unknown_exception
def set_prediction_values(self, labels: list[str]):
functions = self.get_functions()
for ctr, function in enumerate(functions):
function["functionName"] = labels[ctr]
class GhidraRequest():
file_name: str
is_training: bool
model_name: str
task_name: str
ml_class_type: str
uuid: str
def __init__(self, filename: str, is_training: bool, model_name: str, task_name: str, mlclasstype: str) -> None:
self.file_name = filename
self.is_training = is_training
self.model_name = model_name
self.task_name = task_name
self.ml_class_type = mlclasstype
self.uuid = filename
class Prediction():
model_name: str
task_name: str
predictions: dict
def __init__(self, task_name: str, model_name: str, pred: dict) -> None:
self.task_name = task_name
self.model_name = model_name
self.predictions = pred