-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
368 lines (293 loc) · 11 KB
/
gui.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
from easygui import *
from Tkinter import *
import sys
PROPORTIONAL_FONT_FAMILY = ("MS", "Sans", "Serif")
MONOSPACE_FONT_FAMILY = ("Courier")
PROPORTIONAL_FONT_SIZE = 10
MONOSPACE_FONT_SIZE = 9
TEXT_ENTRY_FONT_SIZE = 12
def _fileopenbox():
msg = "APK"
title = "Open files"
default="*.apk"
apkpath = fileopenbox(msg,title,default=default)
return apkpath
def _fuzzmethod():
fmethods = [
"Byte Changing",
"Instruction Swapping"
]
m = "Please select your desired fuzzing method: "
t = "Fuzzing Method Selection"
fuzzmethod = buttonbox(msg=m, title=t,choices=fmethods)
return fuzzmethod
def dq(s):
return '"%s"' % s
def _fuzzpercentage(msg="Please enter your desired fuzz percentage (0.1 - 100)"
, title="Fuzzing Percentage"
, default=""
, lowerbound=0.1
, upperbound=100
, image = None
, root = None
, **invalidKeywordArguments
):
if "argLowerBound" in invalidKeywordArguments:
raise AssertionError(
"\nintegerbox no longer supports the 'argLowerBound' argument.\n"
+ "Use 'lowerbound' instead.\n\n")
if "argUpperBound" in invalidKeywordArguments:
raise AssertionError(
"\nintegerbox no longer supports the 'argUpperBound' argument.\n"
+ "Use 'upperbound' instead.\n\n")
if default != "":
if type(default) != type(1):
raise AssertionError(
"What you have typed is not an acceptable value.", "Error")
if msg == "":
msg = ("Enter an integer between " + str(lowerbound)
+ " and "
+ str(upperbound)
)
while 1:
reply = enterbox(msg, title, str(default), image=image, root=root)
if reply == None: return None
try:
reply = float(reply)
except:
msgbox ("The value that you entered:\n\t%s\nis not an integer." % dq(str(reply))
, "Error")
continue
if reply < lowerbound:
msgbox ("The value that you entered is less than the minimum value: "
+ str(lowerbound) + ".", "Error")
continue
if reply > upperbound:
msgbox ("The value that you entered is greater than the maximum value: "
+ str(upperbound) + ".", "Error")
continue
# reply has passed all validation checks.
# It is an integer between the specified bounds.
reply = reply/100
return reply
def _looptimes(msg="Please enter your desired number of times to loop."
, title="Number of Loops"
, default=""
, lowerbound=1
, upperbound=1000
, image = None
, root = None
, **invalidKeywordArguments
):
if "argLowerBound" in invalidKeywordArguments:
raise AssertionError(
"\nintegerbox no longer supports the 'argLowerBound' argument.\n"
+ "Use 'lowerbound' instead.\n\n")
if "argUpperBound" in invalidKeywordArguments:
raise AssertionError(
"\nintegerbox no longer supports the 'argUpperBound' argument.\n"
+ "Use 'upperbound' instead.\n\n")
if default != "":
if type(default) != type(1):
raise AssertionError(
"What you have typed is not an acceptable value.", "Error")
if msg == "":
msg = ("Enter an integer between " + str(lowerbound)
+ " and "
+ str(upperbound)
)
while 1:
reply = enterbox(msg, title, str(default), image=image, root=root)
if reply == None: return None
try:
reply = int(reply)
except:
msgbox ("The value that you entered:\n\t%s\nis not an integer." % dq(str(reply))
, "Error")
continue
if reply < lowerbound:
msgbox ("The value that you entered is less than the minimum value: "
+ str(lowerbound) + ".", "Error")
continue
if reply > upperbound:
msgbox ("The value that you entered is greater than the maximum value: "
+ str(upperbound) + ".", "Error")
continue
# reply has passed all validation checks.
# It is an integer between the specified bounds.
return reply
def _setup():
while 1:
choices = [
"1. Load APK",
"2. Select Fuzzing Method",
"3. Select Fuzz Percent",
"4. Select Number of Loops",
"Begin Fuzzing",
"Quit"
]
choice = choicebox(msg = "This is the setup page before the fuzzing begins.", title = "Android DVM Fuzzer - Main Menu", choices = choices)
if not choice: return
reply = choice
if reply == "1. Load APK":
apkpath = _fileopenbox()
msgbox("APK Loaded:\n" + str(apkpath), "Result")
elif reply =="2. Select Fuzzing Method":
fuzzmethod = _fuzzmethod()
msgbox("Fuzzing method chosen is:\n" + str(fuzzmethod), "Result")
elif reply == "3. Select Fuzz Percent":
fuzzpercent = _fuzzpercentage()
msgbox("Percentage is:\n" + str(fuzzpercent), "Result")
elif reply == "4. Select Number of Loops":
looptimes = _looptimes()
msgbox("Number of loops:\n" + str(looptimes), "Result")
elif reply == "Begin Fuzzing":
_process()
elif reply == "Quit":
sys.exit()
else:
print(reply)
msgbox("Choice:\n\n" + choice + "\n\nis not recognized", "Program Logic Error")
return
def _process(msg="Fuzzing is in progress...", title="Android DVM Fuzzer - Fuzzing", text="print out whatever you want here"):
return textbox(msg, title, text, codebox=1 )
def denyWindowManagerClose():
""" don't allow WindowManager close
"""
x = Tk()
x.withdraw()
x.bell()
x.destroy()
def textbox(msg=""
, title=""
, text=""
, codebox=0
):
if msg == "": msg = "Fuzzing in progress"
if title == "": title = "Android DVM Fuzzer - Fuzzing"
global boxRoot, __replyButtonText, __widgetTexts, buttonsFrame
global rootWindowPosition
choices = ["Stop"]
__replyButtonText = choices[0]
boxRoot = Tk()
boxRoot.protocol('WM_DELETE_WINDOW', denyWindowManagerClose )
screen_width = boxRoot.winfo_screenwidth()
screen_height = boxRoot.winfo_screenheight()
root_width = int((screen_width * 0.8))
root_height = int((screen_height * 0.5))
root_xpos = int((screen_width * 0.1))
root_ypos = int((screen_height * 0.05))
boxRoot.title(title)
boxRoot.iconname('Dialog')
rootWindowPosition = "+0+0"
boxRoot.geometry(rootWindowPosition)
boxRoot.expand=NO
boxRoot.minsize(root_width, root_height)
rootWindowPosition = "+" + str(root_xpos) + "+" + str(root_ypos)
boxRoot.geometry(rootWindowPosition)
mainframe = Frame(master=boxRoot)
mainframe.pack(side=TOP, fill=BOTH, expand=YES)
# ---- put frames in the window -----------------------------------
# we pack the textboxFrame first, so it will expand first
textboxFrame = Frame(mainframe, borderwidth=3)
textboxFrame.pack(side=BOTTOM , fill=BOTH, expand=YES)
message_and_buttonsFrame = Frame(mainframe)
message_and_buttonsFrame.pack(side=TOP, fill=X, expand=NO)
messageFrame = Frame(message_and_buttonsFrame)
messageFrame.pack(side=LEFT, fill=X, expand=YES)
buttonsFrame = Frame(message_and_buttonsFrame)
buttonsFrame.pack(side=RIGHT, expand=NO)
# -------------------- put widgets in the frames --------------------
# put a textArea in the top frame
if codebox:
character_width = int((root_width * 0.6) / MONOSPACE_FONT_SIZE)
textArea = Text(textboxFrame,height=25,width=character_width, padx="2m", pady="1m")
textArea.configure(wrap=NONE)
textArea.configure(font=(MONOSPACE_FONT_FAMILY, MONOSPACE_FONT_SIZE))
else:
character_width = int((root_width * 0.6) / MONOSPACE_FONT_SIZE)
textArea = Text(
textboxFrame
, height=25
, width=character_width
, padx="2m"
, pady="1m"
)
textArea.configure(wrap=WORD)
textArea.configure(font=(PROPORTIONAL_FONT_FAMILY,PROPORTIONAL_FONT_SIZE))
# some simple keybindings for scrolling
mainframe.bind("<Next>" , textArea.yview_scroll( 1,PAGES))
mainframe.bind("<Prior>", textArea.yview_scroll(-1,PAGES))
mainframe.bind("<Right>", textArea.xview_scroll( 1,PAGES))
mainframe.bind("<Left>" , textArea.xview_scroll(-1,PAGES))
mainframe.bind("<Down>", textArea.yview_scroll( 1,UNITS))
mainframe.bind("<Up>" , textArea.yview_scroll(-1,UNITS))
# add a vertical scrollbar to the frame
rightScrollbar = Scrollbar(textboxFrame, orient=VERTICAL, command=textArea.yview)
textArea.configure(yscrollcommand = rightScrollbar.set)
# add a horizontal scrollbar to the frame
bottomScrollbar = Scrollbar(textboxFrame, orient=HORIZONTAL, command=textArea.xview)
textArea.configure(xscrollcommand = bottomScrollbar.set)
# pack the textArea and the scrollbars. Note that although we must define
# the textArea first, we must pack it last, so that the bottomScrollbar will
# be located properly.
# Note that we need a bottom scrollbar only for code.
# Text will be displayed with wordwrap, so we don't need to have a horizontal
# scroll for it.
if codebox:
bottomScrollbar.pack(side=BOTTOM, fill=X)
rightScrollbar.pack(side=RIGHT, fill=Y)
textArea.pack(side=LEFT, fill=BOTH, expand=YES)
# ---------- put a msg widget in the msg frame-------------------
messageWidget = Message(messageFrame, anchor=NW, text=msg, width=int(root_width * 0.9))
messageWidget.configure(font=(PROPORTIONAL_FONT_FAMILY,PROPORTIONAL_FONT_SIZE))
messageWidget.pack(side=LEFT, expand=YES, fill=BOTH, padx='1m', pady='1m')
# put the buttons in the buttonsFrame
okButton = Button(buttonsFrame, takefocus=YES, text="Stop", height=1, width=6)
okButton.pack(expand=NO, side=TOP, padx='2m', pady='1m', ipady="1m", ipadx="2m")
# for the commandButton, bind activation events to the activation event handler
commandButton = okButton
handler = __textboxOK
for selectionEvent in ["Return","Button-1","Escape"]:
commandButton.bind("<%s>" % selectionEvent, handler)
# ----------------- the action begins ----------------------------------------
try:
# load the text into the textArea
if type(text) == type("abc"): pass
else:
try:
text = "".join(text) # convert a list or a tuple to a string
except:
msgbox("Exception when trying to convert "+ str(type(text)) + " to text in textArea")
sys.exit(16)
textArea.insert(END,text, "normal")
except:
msgbox("Exception when trying to load the textArea.")
sys.exit(16)
try:
okButton.focus_force()
except:
msgbox("Exception when trying to put focus on okButton.")
sys.exit(16)
"""_autoscroll()""" # Unused function for auto scrolling
boxRoot.mainloop()
# this line MUST go before the line that destroys boxRoot
areaText = textArea.get(0.0,END)
boxRoot.destroy()
return areaText # return __replyButtonText
#-------------------------------------------------------------------
# __textboxOK
#-------------------------------------------------------------------
def __textboxOK(event):
global boxRoot
boxRoot.quit()
"""
def _autoscroll(self): #Additional fuction unused
self.listbox_log.select_set(END) #Select the new item
self.listbox_log.yview(END) #Set the scrollbar to the end of the listbox
"""
def main():
_setup()
if __name__ == '__main__':
if True:
main()