forked from iGio90/Dwarf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu_bar.py
342 lines (278 loc) · 13.9 KB
/
menu_bar.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
"""
Dwarf - Copyright (C) 2019 Giovanni Rocca (iGio90)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
import json
import webbrowser
from PyQt5.QtWidgets import QAction, QFileDialog
from lib import prefs
from ui.dialog_input import InputDialog
from ui.dialog_list import ListDialog
from ui.panel_search import SearchPanel
from ui.ui_session import SessionUi
from ui.widget_android_package import AndroidPackageWidget
class MenuBar(object):
def __init__(self, app_window):
self.git_available = False
self.app_window = app_window
self.menu = app_window.menuBar()
# actions
self.menu_actions = []
self.action_enumerate_java_classes = None
self.action_find_bytes = None
self.build_device_menu()
self.build_process_menu()
self.build_hooks_menu()
self.build_find_menu()
self.build_session_menu()
self.build_view_menu()
self.build_about_menu()
def add_menu_action(self, menu, action,
require_script=False,
require_java=False):
self.menu_actions.append({
'action': action,
'require_script': require_script,
'require_java': require_java
})
if self.app_window.get_dwarf().script is None:
action.setEnabled(not require_script)
menu.addAction(action)
def build_device_menu(self):
save_apk = QAction("&Save APK", self.app_window)
save_apk.triggered.connect(self.handler_save_apk)
device_menu = self.menu.addMenu('&Device')
self.add_menu_action(device_menu, save_apk, False)
def build_process_menu(self):
ranges = QAction("&Ranges", self.app_window)
ranges.triggered.connect(self.handler_view_ranges)
modules = QAction("&Modules", self.app_window)
modules.triggered.connect(self.handler_view_modules)
self.action_enumerate_java_classes = QAction("&Java classes", self.app_window)
self.action_enumerate_java_classes.triggered.connect(self.handler_enumerate_java_classes)
dump_memory = QAction("&Dump memory", self.app_window)
dump_memory.triggered.connect(self.handler_dump_memory)
resume = QAction("&Resume", self.app_window)
resume.setShortcut("Ctrl+T")
resume.setStatusTip('Resume process')
resume.triggered.connect(self.handler_resume)
restart = QAction("&Restart", self.app_window)
restart.setShortcut("Ctrl+R")
restart.setStatusTip('Restart process')
restart.triggered.connect(self.handler_restart)
detach = QAction("&Detach", self.app_window)
detach.setStatusTip('Deatch process')
detach.triggered.connect(self.handler_detach)
process_menu = self.menu.addMenu('&Process')
self.add_menu_action(process_menu, ranges, True)
self.add_menu_action(process_menu, modules, True)
self.add_menu_action(process_menu, self.action_enumerate_java_classes, True, True)
process_menu.addSeparator()
self.add_menu_action(process_menu, dump_memory, True)
process_menu.addSeparator()
self.add_menu_action(process_menu, resume, True)
self.add_menu_action(process_menu, restart, True)
self.add_menu_action(process_menu, detach, True)
def build_hooks_menu(self):
hook_native = QAction("&Native", self.app_window)
hook_native.setShortcut("Ctrl+N")
hook_native.triggered.connect(self.app_window.get_dwarf().hook_native)
hook_java = QAction("&Java", self.app_window)
hook_java.setShortcut("Ctrl+J")
hook_java.triggered.connect(self.app_window.get_dwarf().hook_java)
hook_onload = QAction("&Module load", self.app_window)
hook_onload.setShortcut("Ctrl+M")
hook_onload.triggered.connect(self.app_window.get_dwarf().hook_onload)
hooks_menu = self.menu.addMenu('&Hooks')
self.add_menu_action(hooks_menu, hook_native, True)
self.add_menu_action(hooks_menu, hook_java, True, True)
self.add_menu_action(hooks_menu, hook_onload, True, True)
def build_find_menu(self):
self.action_find_bytes = QAction("&Bytes", self.app_window)
self.action_find_bytes.triggered.connect(self.handler_find_bytes)
symbol = QAction("&Symbol", self.app_window)
symbol.triggered.connect(self.handler_find_symbol)
find_menu = self.menu.addMenu('&Find')
self.add_menu_action(find_menu, self.action_find_bytes, True)
self.add_menu_action(find_menu, symbol, True)
def build_session_menu(self):
session_load = QAction("&Load", self.app_window)
session_load.setShortcut("Ctrl+O")
session_load.setStatusTip('Load a session from file')
session_load.triggered.connect(self.handler_session_load)
session_save = QAction("&Save", self.app_window)
session_save.setShortcut("Ctrl+P")
session_save.setStatusTip('Load a session from file')
session_save.triggered.connect(self.handler_session_save)
session_menu = self.menu.addMenu('&Session')
self.add_menu_action(session_menu, session_load, False)
self.add_menu_action(session_menu, session_save, False)
def build_view_menu(self):
data = QAction("&Data", self.app_window)
data.triggered.connect(self.handler_view_data)
hooks = QAction("&Hooks", self.app_window)
hooks.triggered.connect(self.handler_view_hooks)
watchers = QAction("&Watchers", self.app_window)
watchers.triggered.connect(self.handler_view_watchers)
backtrace = QAction("&Backtrace", self.app_window)
backtrace.triggered.connect(self.handler_view_backtrace)
context = QAction("&Context", self.app_window)
context.triggered.connect(self.handler_view_context)
view_menu = self.menu.addMenu('&View')
self.add_menu_action(view_menu, data, True)
view_menu.addSeparator()
self.add_menu_action(view_menu, backtrace, True)
def build_about_menu(self):
slack = QAction('&Slack', self.app_window)
slack.triggered.connect(self.handler_slack)
author = QAction('&Author', self.app_window)
author.triggered.connect(self.handler_author)
about_menu = self.menu.addMenu('&About')
self.add_menu_action(about_menu, slack, False)
self.add_menu_action(about_menu, author, False)
def _set_panel_visibility(self, panel, pref):
if panel is None:
return
visible = panel.isVisible()
self.app_window.get_dwarf().get_prefs().put(pref, not visible)
panel.setVisible(not visible)
def handler_author(self):
webbrowser.open_new_tab('http://www.giovanni-rocca.com')
def handler_find_bytes(self):
accept, input = InputDialog().input(self.app_window, 'find bytes', placeholder='ff b3 ac 9d 0f ...')
if accept:
self.action_find_bytes.setEnabled(False)
SearchPanel.bytes_search_panel(self.app_window.get_app_instance(), input)
def handler_detach(self):
self.app_window.get_dwarf().detach()
def handler_dump_memory(self):
self.app_window.get_dwarf().dump_memory()
def handler_enumerate_java_classes(self, should_update_java_classes=False):
if not should_update_java_classes:
should_update_java_classes = self.app_window.get_app_instance().get_java_classes_panel() is None
self.action_enumerate_java_classes.setEnabled(False)
self.app_window.get_app_instance().get_session_ui().add_dwarf_tab(
SessionUi.TAB_JAVA_CLASSES, request_focus=True)
if should_update_java_classes:
self.app_window.get_dwarf().dwarf_api('enumerateJavaClasses')
def handler_find_symbol(self):
accept, input = InputDialog().input(self.app_window, 'find symbol by pattern', placeholder='*_open*')
if accept:
SearchPanel.debug_symbol_search_panel(self.app_window.get_app_instance(), input)
def handler_restart(self):
self.app_window.get_app_instance().restart()
def handler_resume(self):
self.app_window.get_app_instance().resume()
def handler_save_apk(self):
packages = self.app_window.get_adb().list_packages()
if packages:
accept, items = ListDialog.build_and_show(
self.build_packages_list, packages, double_click_to_accept=True)
if accept:
if len(items) > 0:
path = items[0].get_package_name().path
r = QFileDialog.getSaveFileName()
if len(r) > 0 and len(r[0]) > 0:
self.app_window.get_adb().pull(path, r[0])
def handler_session_load(self):
r = QFileDialog.getOpenFileName()
if len(r) > 0 and len(r[0]) > 0:
with open(r[0], 'r') as f:
session = json.load(f)
self.app_window.get_app_instance().get_hooks_panel()
for hook in session['natives']:
self.app_window.get_dwarf().hook_native(hook['input'], hook)
for hook in session['java']:
self.app_window.get_dwarf().hook_java(hook['input'], hook)
for hook in session['onloads']:
self.app_window.get_dwarf().hook_onload(hook)
self.app_window.get_app_instance().get_log_panel().set_js_script_text(session['script'])
def handler_session_save(self):
r = QFileDialog.getSaveFileName()
if len(r) > 0 and len(r[0]) > 0:
hooks = []
for hook in self.app_window.get_dwarf().hooks:
h = self.app_window.get_dwarf().hooks[hook]
if h.get_input is None or len(h.get_input) == 0:
continue
hooks.append({
'input': h.get_input(),
'condition': h.get_condition(),
'logic': h.get_logic(),
})
java_hooks = []
for hook in self.app_window.get_dwarf().java_hooks:
h = self.app_window.get_dwarf().java_hooks[hook]
java_hooks.append({
'input': h.get_input(),
'condition': h.get_condition(),
'logic': h.get_logic()
})
onload_hooks = []
for hook in self.app_window.get_dwarf().on_loads:
onload_hooks.append(
self.app_window.get_dwarf().on_loads[hook].get_input())
session = {
'natives': hooks,
'java': java_hooks,
'onloads': onload_hooks,
'script': self.app_window.get_app_instance().get_log_panel().get_js_script_text()
}
with open(r[0], 'w') as f:
f.write(json.dumps(session))
def handler_slack(self):
webbrowser.open_new_tab('https://join.slack.com/t/resecret/shared_invite'
'/enQtMzc1NTg4MzE3NjA1LTlkNzYxNTIwYTc2ZTYyOWY1MT'
'Q1NzBiN2ZhYjQwYmY0ZmRhODQ0NDE3NmRmZjFiMmE1MDYwN'
'WJlNDVjZDcwNGE')
def handler_view_data(self):
self.app_window.get_app_instance().get_session_ui().add_dwarf_tab(SessionUi.TAB_DATA, request_focus=True)
def handler_view_backtrace(self):
self._set_panel_visibility(self.app_window.get_app_instance().get_backtrace_panel(), prefs.VIEW_BACKTRACE)
def handler_view_context(self):
self._set_panel_visibility(self.app_window.get_app_instance().get_contexts_panel(), prefs.VIEW_CONTEXT)
def handler_view_hooks(self):
self._set_panel_visibility(self.app_window.get_app_instance().get_hooks_panel(), prefs.VIEW_HOOKS)
def handler_view_modules(self):
self.app_window.get_app_instance().get_session_ui().add_dwarf_tab(SessionUi.TAB_MODULES, request_focus=True)
def handler_view_ranges(self):
self.app_window.get_app_instance().get_session_ui().add_dwarf_tab(SessionUi.TAB_RANGES, request_focus=True)
def handler_view_watchers(self):
self._set_panel_visibility(self.app_window.get_app_instance().get_watchers_panel(), prefs.VIEW_WATCHERS)
#
#
# Just a separator
#
#
def build_packages_list(self, list, data):
list.setMinimumWidth(int(self.app_window.get_app_instance().width() / 4))
for ap in sorted(data, key=lambda x: x.package):
list.addItem(AndroidPackageWidget(ap['name'], ap['identifier'], 0))
def on_bytes_search_complete(self):
if self.app_window.get_dwarf().script is not None:
self.action_find_bytes.setEnabled(True)
def on_context_info(self):
for action in self.menu_actions:
if action['require_java'] and not self.app_window.get_dwarf().java_available:
action['action'].setEnabled(False)
def on_java_classes_enumeration_complete(self):
if self.app_window.get_dwarf().script is not None:
self.action_enumerate_java_classes.setEnabled(True)
def on_script_destroyed(self):
for action in self.menu_actions:
action['action'].setEnabled(not action['require_script'])
def on_script_loaded(self):
for action in self.menu_actions:
if action['require_java'] and not self.app_window.get_dwarf().java_available:
action['action'].setEnabled(False)
continue
action['action'].setEnabled(True)