Skip to content

Commit 5d2132b

Browse files
unknownunknown
authored andcommitted
Adding IDAPython script. Does about same thing as C++ version but was too slow
1 parent 6e273a3 commit 5d2132b

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

AnnotatedTracing.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from idautils import *
2+
from idaapi import *
3+
from sys import exit
4+
import re
5+
6+
# Get current ea
7+
#ea = ScreenEA()
8+
9+
#MakeComm(ea, "Current Address")
10+
11+
#Open the input trace file
12+
filename = AskFile(0, "*.trace", "Select the instruction trace file")
13+
14+
if not filename:
15+
exit()
16+
17+
#open the file and parse the data
18+
trace_file = open(filename)
19+
#trace_data = trace_file.read()
20+
#trace_file.close()
21+
22+
#create table for storing line comments
23+
cmt_tbl = {}
24+
25+
for line in trace_file: #('\n'):
26+
#print "line: " + line
27+
if not re.search("((?:\d|\w)+)\: \w+\s+.+\# ((?:\w+: (?:\w|\d)+(?:\s,\s)*)*)", line):
28+
continue
29+
try:
30+
(instr_str, annotations) = line.split(" # ")
31+
except ValueError:
32+
print "Error with line: " + line
33+
continue
34+
instruction = re.match("((?:[0-9]|[a-f])+)", instr_str).groups()[0]
35+
36+
for annotation in annotations.split(", "):
37+
if len(annotation.split("ptr_val[]:")) == 2:
38+
if cmt_tbl.has_key(instruction):
39+
cmt_tbl[instruction] += ', ' + annotation.split("ptr_val[]:")[1].strip()#annotation.split("ptr_val[]:")[0].strip() + ' "' + annotation.split("ptr_val[]:")[1].strip() + '"'
40+
else:
41+
cmt_tbl[instruction] = annotation.split("ptr_val[]:")[1].strip()#annotation.split("ptr_val[]:")[0].strip() + ' "' + annotation.split("ptr_val[]:")[1].strip() + '"'
42+
43+
original_cmt = GetCommentEx(int(instruction,16), 0)
44+
if original_cmt == None:
45+
original_cmt = ''
46+
MakeComm(int(instruction, 16), str(original_cmt) + annotation.split("ptr_val[]:")[1].strip())
47+
48+
'''else:
49+
if cmt_tbl.has_key(instruction):
50+
cmt_tbl[instruction] += annotation.strip()
51+
else:
52+
cmt_tbl[instruction] = annotation.strip()'''
53+
54+
'''if match and len(match.groups()[1]) > 0:
55+
instruction = match.groups()[0]
56+
comments = match.groups()[1]
57+
annotation = comments.split(" , ")
58+
59+
if cmt_tbl.has_key(instruction):
60+
cmt_tbl[instruction] = cmt_tbl[instruction] + comments.split(' , ')
61+
else:
62+
cmt_tbl[instruction] = comments.split(' , ')'''
63+
64+
#MakeCode(int(instruction, 16))
65+
#code coverage: color all executed lines a light green
66+
SetColor(int(instruction, 16), CIC_ITEM, 0x32CD32)
67+
68+
trace_file.close()
69+
70+
'''for entry in cmt_tbl:
71+
#print entry + " >> " + str(list(set(cmt_tbl[entry])))
72+
original_cmt = ''#GetCommentEx(int(entry,16))
73+
MakeComm(int(entry, 16), original_cmt + str(list(set(cmt_tbl[entry].split(', ')))))#str(list(set(cmt_tbl[entry]))))'''

0 commit comments

Comments
 (0)