forked from hunter-ht-2018/ptfuzzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_fup.py
executable file
·79 lines (74 loc) · 2.49 KB
/
filter_fup.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
import os
import argparse
num_round = 10
def is_fup(line):
return line.startswith("tip_fup: ")
def is_tip(line):
return line.startswith("tip: ")
def is_tip_pgd(line):
return line.startswith("tip_pgd: 0")
def is_tip_pge(line):
return line.startswith("tip_pge: ")
def filter_fup(log_file, out_file):
fup = None
fup_pgd = None
f = open(log_file)
out_f = open(out_file, 'w')
lines = f.readlines()
for l in lines:
line = l.strip()
words = line.split()
tip_type = words[0]
addr = words[1]
if is_fup(line):
fup = line
continue
elif is_tip_pgd(line):
if fup != None:
fup_pgd = line
else:
out_f.write(line + "\n")
elif is_tip_pge(line):
if fup_pgd != None:
if line.split()[1] == fup.split()[1]:
#print line.split()[1], fup_addr
fup = None # clear the state
fup_pgd = None
else:
out_f.write(fup_pgd + '\n')
out_f.write(line + '\n')
fup = None
fup_pgd = None
else:
out_f.write(line + "\n")
fup = None
else:
out_f.write(line + "\n")
fup = None
f.close()
out_f.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = 'Process arguements and bin name.')
#parser.add_argument('app_bin', type = str, help = 'the target application')
parser.add_argument('-c', '--cmd-line', dest = "cmd", type = str, help = 'application arguments')
args = parser.parse_args()
for i in range(0, num_round):
print "run %d..." % i
#cmd = "python build/bin/run_with_pt.py ./build/ptest/readelf -a ./build/ptest/readelf > debug_output.txt"
cmd = "python build/bin/run_with_pt.py %s > debug_output.txt" % args.cmd
print cmd
if args.cmd != None:
os.system(cmd)
pt_log_file = "pt%d.log" % i
cmd = "python trim_log.py debug_output.txt > %s" % pt_log_file
print cmd
if args.cmd != None:
os.system(cmd)
pt_filter_file = "fpt%d.log" % i
filter_fup(pt_log_file, pt_filter_file)
print "check file differences:"
for i in range(1, num_round):
pt_filter_file = "fpt%d.log" % i
cmd = "diff %s fpt0.log" % pt_filter_file
print cmd
os.system(cmd)