forked from iGio90/Dwarf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpanel_log.py
152 lines (124 loc) · 4.9 KB
/
panel_log.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
"""
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/>
"""
from PyQt5.QtCore import Qt, QMargins
from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QWidget, QLineEdit, QHBoxLayout, QPushButton, \
QSplitter, QVBoxLayout, QScrollBar
from ui.dialog_js_editor import JsEditorDialog
from ui.widget_item_not_editable import NotEditableListWidgetItem
class JsInput(QLineEdit):
def __init__(self, log_panel, *__args):
super().__init__(*__args)
self.log_panel = log_panel
self.cmds = []
self.cmd_index = 0
def keyPressEvent(self, event):
if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
cmd = self.text()
l = len(self.cmds)
if l > 0:
if l > 100:
self.cmds.pop(0)
if cmd != self.cmds[l - 1]:
self.cmds.append(cmd)
else:
self.cmds.append(cmd)
self.cmd_index = 0
self.log_panel.app.dwarf_api('evaluate', self.text())
self.setText('')
elif event.key() == Qt.Key_Up:
l = len(self.cmds)
try:
self.setText(self.cmds[l - 1 - self.cmd_index])
if self.cmd_index < l - 1:
self.cmd_index += 1
except:
pass
elif event.key() == Qt.Key_Down:
try:
if self.cmd_index >= 0:
self.cmd_index -= 1
self.setText(self.cmds[len(self.cmds) - 1 - self.cmd_index])
except:
self.setText('')
self.cmd_index = 0
else:
return super().keyPressEvent(event)
def clear_history(self):
self.cmds.clear()
class LogPanel(QWidget):
def __init__(self, app, flags=None, *args, **kwargs):
super().__init__(flags, *args, **kwargs)
layout = QVBoxLayout()
self.app = app
self.js_script = ''
self.setContentsMargins(QMargins(0, 0, 0, 0))
layout.setContentsMargins(QMargins(0, 0, 0, 0))
self.list = QListWidget()
self.list.setStyleSheet('''
QListWidget::item:hover {
color: white;
background-color:
transparent;
}
QListWidget::item:selected {
color: white;
background-color:
transparent;
}
''')
bar = QScrollBar()
bar.setMaximumHeight(0)
bar.setMaximumWidth(0)
self.list.setHorizontalScrollBar(bar)
self.list.model().rowsInserted.connect(self.on_row_inserted)
layout.addWidget(self.list)
js_box = QHBoxLayout()
js_box.setContentsMargins(QMargins(3, 3, 3, 3))
self.input = JsInput(self)
self.input.setPlaceholderText('$>')
js_box.addWidget(self.input)
function_btn = QPushButton('ƒ')
function_btn.setMinimumWidth(25)
function_btn.clicked.connect(self.js_function_box)
js_box.addWidget(function_btn)
js_box_widget = QWidget()
js_box_widget.setLayout(js_box)
layout.addWidget(js_box_widget)
self.setLayout(layout)
def on_row_inserted(self, qindex, a, b):
self.list.scrollToBottom()
def log(self, what, clear=False):
if clear:
self.clear()
if isinstance(what, QListWidgetItem):
self.list.addItem(what)
else:
self.list.addItem(NotEditableListWidgetItem(what))
def clear(self):
self.list.clear()
def js_function_box(self):
accept, what = JsEditorDialog(
self.app, def_text=self.js_script,
placeholder_text='// js script with both frida and dwarf api.\n'
'// note that it\'s evaluated. Which means, if you define a variable\n'
'// or attach an Interceptor, it won\'t be removed by '
'just deleting the script content').show()
if accept:
self.js_script = what
if len(what) > 0:
self.app.dwarf_api('evaluateFunction', what)
def get_js_script_text(self):
return self.js_script
def set_js_script_text(self, script):
self.js_script = script