-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindgoto.py
More file actions
80 lines (72 loc) · 3.19 KB
/
findgoto.py
File metadata and controls
80 lines (72 loc) · 3.19 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
79
import json
import re
from tqdm import tqdm
def countgoto_all():
FuncPathAngr = './decomp_funcs_angr/'
FuncPathGHIDRA = './decomp_funcs_GHIDRA/'
angrfunc_file = './function-file angr.json'
GHIDRAfunc_file = './function-file GHIDRA.json'
OutputFileangr = './gotosangr.json'
OutputFileGHIDRA = './gotosGHIDRA.json'
angrdict = {}
GHIDRAdict = {}
GHIDRAffdict = {}
angrffdict = {}
pattern = rb"(goto ([a-zA-Z0-9_-]+);)"
with open(angrfunc_file, 'r') as angrff, open(GHIDRAfunc_file, 'r') as GHIDRAff:
angrffdict =json.load(angrff)
GHIDRAffdict = json.load(GHIDRAff)
with open(OutputFileangr, "w") as angr, open(OutputFileGHIDRA, "w") as GHIDRA:
for filename in angrffdict.values():
angrfunctionfile = open(FuncPathAngr + filename, 'rb')
angrcontent = angrfunctionfile.read()
angrfunctionfile.close()
matchesangr = re.findall(pattern, angrcontent)
angrdict[filename] = len(matchesangr)
totalgotosangr += len(matchesangr)
for filename in GHIDRAffdict.values():
GHIDRAfunctionfile = open(FuncPathGHIDRA + filename, 'rb')
GHIDRAcontent = GHIDRAfunctionfile.read()
GHIDRAfunctionfile.close()
matchesGHIDRA = re.findall(pattern, GHIDRAcontent)
GHIDRAdict[filename] = len(matchesGHIDRA)
totalgotosGHIDRA += len(matchesGHIDRA)
json.dump(angrdict, angr)
json.dump(GHIDRAdict, GHIDRA)
def process_all():
angrgotofile = './gotosangr.json'
GHIDRAgotofile = './gotosGHIDRA.json'
gotosangr = 0
gotosGHIDRA = 0
with open(angrgotofile, 'r') as angrgotofile, open(GHIDRAgotofile, 'r') as GHIDRAgotofile:
angrgotodict =json.load(angrgotofile)
GHIDRAgotodict = json.load(GHIDRAgotofile)
gotosangr = sum(angrgotodict.values())
gotosGHIDRA = sum(GHIDRAgotodict.values())
print("GHIDRA Length: " + str(len(GHIDRAgotodict)))
print("GHIDRA gotos: " + str(gotosGHIDRA))
print("angr Length: " + str(len(angrgotodict)))
print("angr gotos: " + str(gotosangr))
def process_common():
angrgotofile = './gotosangr.json'
GHIDRAgotofile = './gotosGHIDRA.json'
gotosangr = 0
gotosGHIDRA = 0
angrfunc_file = './function-file angr.json'
GHIDRAfunc_file = './function-file GHIDRA.json'
commonfunctionspath = './commonfunctions'
with open(angrfunc_file, 'r') as angrff, open(GHIDRAfunc_file, 'r') as GHIDRAff:
angrffdict =json.load(angrff)
GHIDRAffdict = json.load(GHIDRAff)
with open(angrgotofile, 'r') as angrgotofile, open(GHIDRAgotofile, 'r') as GHIDRAgotofile:
angrgotodict =json.load(angrgotofile)
GHIDRAgotodict = json.load(GHIDRAgotofile)
with open(commonfunctionspath, "r") as commonfunctions:
commonlist = commonfunctions.read().splitlines()
for filename in tqdm(commonlist):
filepathangr = angrffdict[filename]
filepathGHIDRA = GHIDRAffdict[filename]
gotosangr += angrgotodict[filepathangr]
gotosGHIDRA += GHIDRAgotodict[filepathGHIDRA]
print("GHIDRA gotos: " + str(gotosGHIDRA))
print("angr gotos: " + str(gotosangr))