-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindLLOC.py
More file actions
69 lines (59 loc) · 2.64 KB
/
findLLOC.py
File metadata and controls
69 lines (59 loc) · 2.64 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
import delegator
from tqdm import tqdm
import json
GHIDRAFUNCTIONPATH = './decomp_funcs_GHIDRA/'
ANGRFUNCTIONPATH = './decomp_funcs_angr/'
angrfunc_file = './function-file angr.json'
GHIDRAfunc_file = './function-file GHIDRA.json'
GHIDRAOutputPath = './GHIDRALLOC.json'
angrOutputPath = './angrLLOC.json'
commonfunctionspath = './commonfunctions'
GHIDRAdict = {}
angrdict = {}
with open(angrfunc_file, 'r') as angrff, open(GHIDRAfunc_file, 'r') as GHIDRAff:
angrffdict =json.load(angrff)
GHIDRAffdict = json.load(GHIDRAff)
def findLLOC():
for filename in tqdm(GHIDRAffdict.values()):
GHIDRAFUNCTIONFILE = GHIDRAFUNCTIONPATH + filename
c = delegator.run('cat ' + GHIDRAFUNCTIONFILE + "| ./easysloc")
lloc = c.out.split()[0]
GHIDRAdict[filename] = int(lloc)
for filename in tqdm(angrffdict.values()):
ANGRFUNCTIONFILE = ANGRFUNCTIONPATH + filename
c = delegator.run('cat ' + ANGRFUNCTIONFILE + "| ./easysloc")
lloc = c.out.split()[0]
angrdict[filename] = int(lloc)
with open(GHIDRAOutputPath, "w") as outfile:
json.dump(GHIDRAdict, outfile)
with open(angrOutputPath, "w") as outfile:
json.dump(angrdict, outfile)
def process_all():
with open(GHIDRAOutputPath, "r") as GHIDRALLOC, open(angrOutputPath, "r") as angrLLOC:
GHIDRALLOCdict = json.load(GHIDRALLOC)
angrLLOCdict = json.load(angrLLOC)
angrLLOCtotal = sum(angrLLOCdict.values())
GHIDRALLOCtotal = sum(GHIDRALLOCdict.values())
print("GHIDRA length: " + str(len(GHIDRALLOCdict)))
print("GHIDRA total LLOC: " + str(GHIDRALLOCtotal))
print("angr total: " + str(len(angrLLOCdict)))
print("angr total LLOC: " + str(angrLLOCtotal))
def process_common():
GHIDRALLOCcounter = 0
angrLLOCcounter = 0
with open(GHIDRAOutputPath, "r") as GHIDRALLOC, open(angrOutputPath, "r") as angrLLOC:
GHIDRALLOCdict = json.load(GHIDRALLOC)
angrLLOCdict = json.load(angrLLOC)
with open(angrfunc_file, 'r') as angrff, open(GHIDRAfunc_file, 'r') as GHIDRAff:
angrffdict =json.load(angrff)
GHIDRAffdict = json.load(GHIDRAff)
with open(commonfunctionspath, "r") as commonfunctions:
commonlist = commonfunctions.read().splitlines()
for filename in tqdm(commonlist):
filepathangr = angrffdict[filename]
filepathGHIDRA = GHIDRAffdict[filename]
GHIDRALLOCcounter += GHIDRALLOCdict[filepathGHIDRA]
angrLLOCcounter += angrLLOCdict[filepathangr]
print("GHIDRA total LLOC: " + str(GHIDRALLOCcounter))
print("angr total LLOC: " + str(angrLLOCcounter))
process_common()