/
category_form_widget.py
230 lines (193 loc) · 8.16 KB
/
category_form_widget.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
# -*- coding: utf-8 -*-
import sys
import os
import platform
import time
import json
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from module_list import modules
from category_list import categories
from functools import partial
from categories import Cagtegories
from category_list import categories
from output_widget import OutPutWidget
os_name = platform.system()
class CategoryFormWidget(QWidget):
def __init__(self, parent, text_edit):
super(CategoryFormWidget, self).__init__(parent)
self.all = False
self.text_edit = text_edit.text_edit
self.init_UI()
def init_UI(self):
# Main layout
main_layout = QGridLayout()
main_layout.setSpacing(0)
# Top layout
top_layout = QVBoxLayout()
top_layout.setAlignment(Qt.AlignRight)
top_layout.setContentsMargins(5, 0, 0, 0)
# self.b1 = QRadioButton(u"ماژول های انتخابی")
# self.b1.setChecked(True)
# self.b1.setFont(QFont('SansSerif', 15))
# self.b1.clicked.connect(
# partial(self.change_all, False)
# )
path_layout = QVBoxLayout()
path_layout.setSpacing(5)
lable = QLabel(u"دایرکتوری برای بارگذاری ماژول ها:")
self.location = QLabel("chipsec/modules/common")
additional_path = QPushButton(u"تغییر دایرکتوری")
additional_path.clicked.connect(self.path)
path_layout.addWidget(lable, alignment=Qt.AlignRight)
path_layout.addWidget(self.location, alignment=Qt.AlignRight)
path_layout.addWidget(additional_path, alignment=Qt.AlignRight)
# self.b2 = QRadioButton(u"همه ماژول ها")
# self.b2.setFont(QFont('SansSerif', 15))
# self.b2.clicked.connect(
# partial(self.change_all, True)
# )
# top_layout.addWidget(self.b1, alignment=Qt.AlignRight)
# top_layout.addWidget(self.b2, alignment=Qt.AlignRight)
top_layout.addLayout(path_layout)
# Middle layout
middle_layout = QVBoxLayout()
middle_layout.setAlignment(Qt.AlignRight)
m = Cagtegories(self)
btn_layout = QHBoxLayout()
btn_layout.setAlignment(Qt.AlignRight)
run_btn = QPushButton("Run")
run_btn.clicked.connect(
partial(self.call_run, m)
)
btn_layout.addWidget(run_btn, alignment=Qt.AlignRight)
middle_layout.addWidget(m, alignment=Qt.AlignLeft)
middle_layout.addLayout(btn_layout)
main_layout.addLayout(top_layout, 0, 0)
main_layout.addLayout(middle_layout, 1, 0)
self.setLayout(main_layout)
def change_all(self, state):
self.all = state
def path(self):
directory = str(
QFileDialog.getExistingDirectory(
self,
"Open a folder",
".",
QFileDialog.ShowDirsOnly
)
)
self.location.setText(directory)
def call_run(self, c_obj):
import chipsec_main
custom_categories = c_obj.checked_exec()
# for c in custom_categories:
# print json.dumps(
# categories[c['index']], indent=1
# )
result = str()
if os.path.exists("log.txt"):
if os_name.lower() != 'linux':
f = open("log.txt", 'w')
f.write("")
f.close()
else:
os.remove("log.txt")
for custom_category in custom_categories:
for module in categories[custom_category['index']]['modules']:
command = list()
print module
command.append('-m')
command.append(module)
command.append('-l')
command.append('log.txt')
chipsec_main.main(command)
f = open('log.txt', 'r+')
t = f.read()
s = t.split('running module')
# r = s[1].split('[CHIPSEC] *************************** SUMMARY ***************************')
try:
result += "[*] running module" + s[1] # r[0]
except:
result = "Operation not permitted! Please make sure you are admin"
self.text_edit.setText(result)
return
if os_name.lower() != 'linux':
f.write("")
f.close()
else:
f.close()
os.remove('log.txt')
self.text_edit.setText(result)
# if self.all:
# try:
# chipsec_main.main(['-l', 'log.txt'])
# except:
# result = "Operation not permitted! Please make sure you are admin"
# self.text_edit.setText(result)
# return
# f = open('log.txt', 'r+')
# self.text_edit.setText(f.read())
# if os_name.lower() != 'linux':
# f.write("")
# f.close()
# else:
# f.close()
# os.remove("log.txt")
# else:
# for custom_module in custom_categories:
# command = list()
# for module in modules:
# if custom_module['name'] == module['name']:
# command.append('-m')
# command.append(module['cmd'])
# if custom_module['has_arg']:
# command.append('-a')
# command.append(custom_module['args'])
# command.append('-l')
# command.append('log.txt')
# if custom_module['xml']:
# command.append('-x')
# command.append(custom_module['xml_file'])
# if custom_module['ignore_platform']:
# command.append('-i')
# if custom_module['no_time']:
# command.append('--no_time')
# if custom_module['verbose']:
# command.append('-v')
# if custom_module['driver']:
# command.append('-n')
# if custom_module['fail_fast']:
# command.append('--failfast')
# if custom_module['platform']:
# command.append('-p')
# command.append(custom_module['platform_type'])
# if custom_module['module_type']:
# command.append('-t')
# # Moonde
# if custom_module['debug']:
# command.append('-d')
# if custom_module['list_tags']:
# command.append('--list_tags')
# if custom_module['include']:
# command.append('-I')
# command.append(str(self.location.text()))
# print "Command: chipsec_main.main(%s)" %str(command)
# chipsec_main.main(command)
# f = open('log.txt', 'r+')
# t = f.read()
# s = t.split('running module')
# # r = s[1].split('[CHIPSEC] *************************** SUMMARY ***************************')
# try:
# result += "[*] running module" + s[1] # r[0]
# except:
# result = "Operation not permitted! Please make sure you are admin"
# self.text_edit.setText(result)
# return
# if os_name.lower() != 'linux':
# f.write("")
# f.close()
# else:
# f.close()
# os.remove('log.txt')
# self.text_edit.setText(result)