-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkivyapp.py
118 lines (97 loc) · 4.15 KB
/
kivyapp.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
import kivy
import os
import os.path
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.popup import Popup
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from functools import partial
from kivy.config import Config
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
class MyPopup(Popup):
def scroll_change(self, scrlv, instance, value):
scrlv.scroll_y = value
def slider_change(self, s, instance, value):
if value >= 0:
s.value = value
def __init__(self, input, **kwargs):
super().__init__(**kwargs)
self.size_hint = (0.9, 0.9)
self.title = "Malware Detection Results"
label = Label(text=input,
size_hint_y=None, height=ScrollView().height, valign="center")
scrollview = ScrollView(size_hint=(0.9, 0.95))
scrollview.add_widget(label)
s = Slider(min=-0.5, max=2.5, value=25, orientation="vertical",
step=0.01, size_hint=(0.1, 0.95))
scrollview.bind(scroll_y=partial(self.slider_change, s))
s.bind(value=partial(self.scroll_change, scrollview))
self.content = BoxLayout(orientation="vertical")
innerLayout = BoxLayout(orientation="horizontal")
innerLayout.add_widget(scrollview)
innerLayout.add_widget(s)
close_button = Button(text="Close", size_hint=(1, 0.2))
close_button.bind(on_press=self.dismiss)
self.content.add_widget(innerLayout)
self.content.add_widget(close_button)
class MyGridLayout(GridLayout):
# Initialize infinite keywords
def __init__(self, **kwargs):
# Call grid layout constructor
super(MyGridLayout, self).__init__(**kwargs)
self.cols = 1
self.inside = GridLayout()
self.inside.cols = 2
Window.clearcolor = (142/255, 157/255, 204/255)
# Add widgets
self.inside.add_widget(Label(
text="Source Input (file, folder, URL): ", font_size=30, bold=True, color=(0, 0, 0)))
# Add Input Box
self.input = TextInput(multiline=True, font_size=30,
background_color=(217/255, 219/255, 241/255))
self.inside.add_widget(self.input)
self.inside.add_widget(Label(
text="Zip Archive Password (if applicable): ", font_size=30, bold=True, color=(0, 0, 0)))
# Add Input Box
self.zippass = TextInput(
multiline=False, font_size=30, background_color=(217/255, 219/255, 241/255))
self.inside.add_widget(self.zippass)
self.add_widget(self.inside)
# Create a Scan Button
self.scan = Button(
text="Scan",
font_size=32,
background_color=(203/255, 247/255, 237/255),
size_hint=(0.25, 0.25))
# Bind the button
self.scan.bind(on_press=self.press)
self.add_widget(self.scan)
def press(self, instance):
input = self.input.text.strip() # Retrieves source input and removes trailing white spaces
input = input.replace('"', '\\"') # Escapes quotes to avoid code injection
input = os.path.expanduser(input) # Expands path to full path, removing any shortcuts like ~
zippass = self.zippass.text
zippass = zippass.replace('"', '\\"') # Escapes quotes to avoid code injection
cmd = 'python3 run.py run "' + input + '"' # Surrounded user input in quotes to sanitize data
if len(zippass) > 0:
cmd = cmd + ' --password "' + zippass + '"' # Surrounded user input in quotes to sanitize data
cmd = cmd + ' -l quiet'
output = os.popen(cmd).read()
popup = MyPopup(output)
popup.open()
# Clear the input boxes
self.input.text = ""
self.zippass.text = ""
class MalwareDetection(App):
def build(self):
return MyGridLayout()
if __name__ == '__main__':
MalwareDetection().run()