-
Notifications
You must be signed in to change notification settings - Fork 2
/
recolour_calls.py
47 lines (37 loc) · 1.12 KB
/
recolour_calls.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
import idaapi
import idc
from collections import defaultdict
# COLOR_CALL = 0xffffd0
# BGR
DEFAULT_COLOR_CALL = 0x505000
def iterate_all_instructions():
next_instr = 0
next_instr = idc.next_head(next_instr)
while next_instr != idaapi.BADADDR:
yield next_instr
next_instr = idc.next_head(next_instr)
def iterate_all_calls():
for instr_ea in iterate_all_instructions():
insn = idaapi.insn_t()
idaapi.decode_insn(insn, instr_ea)
if idaapi.is_call_insn(insn):
yield instr_ea
def iterate_all_noncalls():
for instr_ea in iterate_all_instructions():
insn = idaapi.insn_t()
idaapi.decode_insn(insn, instr_ea)
if not idaapi.is_call_insn(insn):
yield instr_ea
def recolour_calls(item_color=DEFAULT_COLOR_CALL):
for call_ea in iterate_all_calls():
idaapi.set_item_color(call_ea, item_color)
idaapi.refresh_idaview_anyway()
def undo_recolour_calls():
colors = defaultdict(int)
for instr_ea in iterate_all_noncalls():
color = idaapi.get_item_color(instr_ea)
colors[color] += 1
max_color = max((k for k in colors), key=colors.__getitem__)
recolour_calls(max_color)
if __name__ == "__main__":
recolour_calls()