-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathea_cmd.py
155 lines (110 loc) · 3.44 KB
/
ea_cmd.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
# -*- coding: utf-8 -*-
from api_funcs import *
from copy import copy
from ea_UI import Cmd_UI
from ea_utils import QtWidgets, ea_warning, get_bits, get_mem_recursive, parse_mem, style
from idaapi import *
from idautils import *
from idc import *
from re import match
from time import sleep, time
def get(addr, int_size, n=20):
string = copy(style[0])
string += "<p>"
for x in range(n):
regions = []
get_mem_recursive(addr + x * 4, regions, int_size=int_size)
string += parse_mem(regions) + "<br>"
string += "</p>"
form.textEdit.append(string)
form.textEdit.verticalScrollBar().setValue(form.textEdit.verticalScrollBar().maximum())
def find(arg, int_size):
matches = []
addr = 0
for x in range(100):
newAddr = FindText(addr, SEARCH_DOWN, 0, 0, arg)
if newAddr != 0xffffffffffffffffL:
if newAddr > addr:
addr = newAddr
matches.append(addr)
else:
addr += 0x4
else:
break
string = copy(style[0])
string += "<p>"
for addr in matches:
regions = []
get_mem_recursive(addr, regions, int_size=int_size)
string += parse_mem(regions) + "<br>"
string += "</p>"
form.textEdit.append(string)
form.textEdit.verticalScrollBar().setValue(form.textEdit.verticalScrollBar().maximum())
def do_cmd():
int_size = 4 if get_bits() else 8
cmd = form.lineEdit.text()
form.textEdit.append(copy(style) + "<span>▶ " + cmd +"</span><br>")
match_read = match(r"(x\\|x)([0-9]*) *(.*)", cmd)
match_search = match(r"searchmem *(.*)", cmd)
match_step = match(r"step|si", cmd)
match_continue = match(r"continue|c", cmd)
match_run = match(r"run|r", cmd)
match_finish = match(r"finish|fini", cmd)
match_break = match(r"(break|b) *(.*)", cmd)
match_delete = match(r"(delete|delet|del) *(.*)", cmd)
if match_read:
length = to_int(match_read.group(2))
addr = to_int(match_read.group(3))
get(addr, int_size, length)
elif match_search:
cmd = match_search.group(1)
if cmd[0] == "\"" and cmd[-1] == "\"":
cmd = cmd[1:-1]
find(str(cmd), int_size)
elif match_step:
step_into()
elif match_finish:
step_until_ret()
elif match_continue:
continue_process()
elif match_break:
add_bp(to_int(match_break.group(2)))
elif match_delete:
del_bpt(to_int(match_delete.group(2)))
elif match_run:
if get_process_state() != 0:
StopDebugger()
# TODO: find way to asynchronously restart debugger without crashing IDA
# a_sync(restart)
else:
ProcessUiAction("ProcessStart")
def restart():
start = time()
timeout = False
while get_process_state() != 0:
sleep(0.5)
if start - time() > 4:
timeout = True
ea_warning("Restart operation timed out")
break
runDebugger(get_input_file_path())
def to_int(i):
if "0x" in i or "0X" in i:
return int(i[2:],16)
else:
return int(i)
def ea_cmd():
global a
global form
a = QtWidgets.QFrame()
form = Cmd_UI()
form.setupUi(a)
form.textEdit.setReadOnly(True)
form.lineEdit.returnPressed.connect(do_cmd)
form.pushButton.clicked.connect(do_cmd)
a.show()
addresses = 0
max_iterations = 10
iterations = 0
a = None
form = None