-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangrlabel.py
More file actions
116 lines (98 loc) · 4.09 KB
/
angrlabel.py
File metadata and controls
116 lines (98 loc) · 4.09 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import os
import json
from tqdm import tqdm
ANGRFUNCTIONPATH = './decomp_funcs_angr' #path to folder containing angr decompiled functions
angrfunctionfilepath = './function-file angr.json' #path to output of filefunctioncorrangr.py
angrlabelpath = './function-file GHIDRA.json' #JSON file where you want the output label file to be generated
commonfunctionpath = './commonfunctions' #path to file which containes names of common functions
angrdict = {}
'''
The purpose of this script is to create json file labelling if each unique angr function is empty or only containes abort statements
'''
def label():
with open(angrfunctionfilepath, 'r') as angrff:
angrffdict =json.load(angrff)
for filename in tqdm(angrffdict.values()):
file_size = os.path.getsize(ANGRFUNCTIONPATH + filename)
with open(ANGRFUNCTIONPATH + filename, 'r') as readfile:
if file_size <= 37:
angrdict[filename] = "empty"
elif "abort()" in readfile.read():
angrdict[filename] = "abort_statement"
elif "return" not in readfile.read():
angrdict[filename] = "no return"
else:
angrdict[filename] = ""
with open(angrlabelpath, "w") as angr:
json.dump(angrdict, angr)
def process_all():
emptycounter = 0
abortcounter = 0
noreturncounter = 0
sub_counter = 0
sub_emptycounter = 0
sub_abortcounter= 0
sub_noreturncounter = 0
with open(angrlabelpath, "r") as angr:
angrloaddict = json.load(angr)
for (key, value) in angrloaddict.items():
if "sub_" in key:
sub_counter += 1
if value == "empty":
emptycounter += 1
if "sub_" in key:
sub_emptycounter += 1
elif value == "abort_statement":
abortcounter += 1
if "sub_" in key:
sub_abortcounter += 1
elif value == "no return":
noreturncounter += 1
if "sub_" in key:
sub_noreturncounter += 1
print("total empty: " + str(emptycounter))
print("total aborted: " + str(abortcounter))
print("total no return: " + str(noreturncounter))
print("total sub_ functions: " + str(sub_counter))
print("total empty sub functions: " + str(sub_emptycounter))
print("total aborted sub functions: " + str(sub_abortcounter))
print("total no return sub_ functions: " + str(sub_noreturncounter))
def process_common():
emptycounter = 0
abortcounter = 0
noreturncounter = 0
sub_counter = 0
sub_emptycounter = 0
sub_abortcounter= 0
sub_noreturncounter = 0
with open(angrfunctionfilepath, 'r') as angrff:
angrffdict = json.load(angrff)
with open(commonfunctionpath, "r") as commonfunctions:
commonlist = commonfunctions.read().splitlines()
with open(angrlabelpath, "r") as angr:
angrlabeldict = json.load(angr)
commonangrffdict = {i : angrffdict[i] for i in commonlist}
commonangrlabeldict = {filepath: angrlabeldict[filepath] for filepath in commonangrffdict.values()}
for (key, value) in tqdm(commonangrlabeldict.items()):
if "sub_" in key:
sub_counter += 1
if value == "empty":
emptycounter += 1
if "sub_" in key:
sub_emptycounter += 1
elif value == "abort_statement":
abortcounter += 1
if "sub_" in key:
sub_abortcounter += 1
elif value == "no return":
noreturncounter += 1
if "sub_" in key:
sub_noreturncounter += 1
print("total empty: " + str(emptycounter))
print("total aborted: " + str(abortcounter))
print("total no return: " + str(noreturncounter))
print("total sub_ functions: " + str(sub_counter))
print("total empty sub functions: " + str(sub_emptycounter))
print("total aborted sub functions: " + str(sub_abortcounter))
print("total no return sub_ functions: " + str(sub_noreturncounter))
process_all()