-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_trace.py
More file actions
78 lines (70 loc) · 2.18 KB
/
Copy pathprocess_trace.py
File metadata and controls
78 lines (70 loc) · 2.18 KB
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
import io
import sys
import collections
import typing
class CoverageItem(collections.OrderedDict):
timestamp: int
rip: int
rflags: int
target: typing.Optional[int] = None
def __repr__(self):
if self.target:
after = f" -> {self.target:x}"
else:
after = ""
return f"{self.timestamp:x} item {self.rip:x} {self.rflags:x}" + after
def process_trace(path):
log = dict()
ring = {}
dictionary = set()
draining = True
drain_index = 0
def finalize_ring():
nonlocal ring
nonlocal drain_index
# done draining the trace log
for i,v in sorted(ring.items()):
#print(i, v)
log[v.timestamp] = v
ring = {}
drain_index = 0
with io.open(path, "r") as f:
while line := f.readline():
line = line.strip()
was_draining = draining
#print(line)
words = line.split(" ")
if words[0] == "drain":
# draining precise buffer
draining = True
item = ring.setdefault(drain_index, CoverageItem())
item.timestamp = int(words[1], 16)
item.rip = int(words[2], 16)
item.rflags = int(words[3], 16)
drain_index = drain_index + 0x20
continue
else:
if draining:
finalize_ring()
draining = False
item = ring.setdefault(int(words[0], 16), CoverageItem())
if words[1] == "cmpcov":
# cmpcov dictionary item
item.rip = int(words[2], 16)
item.rflags = 0
pass
elif words[1] == "dyncall":
# dynamic call item
item.rip = int(words[2], 16)
item.rflags = 0
item.target = int(words[4], 16)
pass
else:
# normal coverage
item.rip = int(words[1], 16)
item.rflags = int(words[2], 16)
finalize_ring()
for i,v in sorted(log.items()):
print(v)
if __name__=="__main__":
process_trace(sys.argv[1])