Datasets:
Edward J. Schwartz
commited on
Commit
•
c21998d
1
Parent(s):
702e074
Pass function addresses to bat-ana
Browse files- scripts/gen-training.py +32 -16
scripts/gen-training.py
CHANGED
@@ -18,11 +18,17 @@ linere = re.compile(r"symbol\(([^,]+), (func|method), '([^)]+)'\)\.")
|
|
18 |
anafile = NamedTemporaryFile(prefix=os.path.basename(bname) + "_", suffix=".bat_ana")
|
19 |
ananame = anafile.name
|
20 |
|
21 |
-
subprocess.check_output("/data/research/rose/install-latest/bin/bat-ana --no-post-analysis -o %s %s 2>/dev/null" % (ananame, bname), shell=True)
|
22 |
|
23 |
-
def get_all_dis():
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
output = re.sub(b' +', b' ', output)
|
27 |
|
28 |
func_dis = {}
|
@@ -62,10 +68,11 @@ def get_dis(addr):
|
|
62 |
except subprocess.CalledProcessError:
|
63 |
return None
|
64 |
|
65 |
-
all_dis = get_all_dis()
|
66 |
#objs = []
|
67 |
df = pandas.DataFrame(columns=['Binary', 'Addr', 'Name', 'Type', 'Disassembly'])
|
68 |
|
|
|
|
|
69 |
with open(gname, "r") as f:
|
70 |
for l in f:
|
71 |
|
@@ -76,19 +83,28 @@ with open(gname, "r") as f:
|
|
76 |
name = m.group(3)
|
77 |
#print([addr, typ, name])
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
if dis is None:
|
82 |
-
dis = ""
|
83 |
-
typ = "notfound"
|
84 |
-
else:
|
85 |
-
dis = dis.decode("utf8")
|
86 |
-
|
87 |
-
df = df.append({'Binary': bname, 'Addr': addr, 'Name': name, 'Type': typ, 'Disassembly': dis}, ignore_index=True)
|
88 |
-
|
89 |
-
if False:
|
90 |
-
df.to_csv(oname, index=False)
|
91 |
#print(df.head())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
df.to_csv(oname, index=False)
|
94 |
|
|
|
18 |
anafile = NamedTemporaryFile(prefix=os.path.basename(bname) + "_", suffix=".bat_ana")
|
19 |
ananame = anafile.name
|
20 |
|
|
|
21 |
|
22 |
+
def get_all_dis(addrs=None):
|
23 |
|
24 |
+
addrstr = ""
|
25 |
+
if addrs is not None:
|
26 |
+
addrstr = " ".join([f"--function-at {x}" for x in addrs])
|
27 |
+
|
28 |
+
subprocess.check_output(f"/data/research/rose/install-latest/bin/bat-ana {addrstr} --no-post-analysis -o {ananame} {bname} 2>/dev/null", shell=True)
|
29 |
+
|
30 |
+
|
31 |
+
output = subprocess.check_output(f"/data/research/rose/install-latest/bin/bat-dis --no-insn-address --no-bb-cfg-arrows --color=off {ananame} 2>/dev/null", shell=True)
|
32 |
output = re.sub(b' +', b' ', output)
|
33 |
|
34 |
func_dis = {}
|
|
|
68 |
except subprocess.CalledProcessError:
|
69 |
return None
|
70 |
|
|
|
71 |
#objs = []
|
72 |
df = pandas.DataFrame(columns=['Binary', 'Addr', 'Name', 'Type', 'Disassembly'])
|
73 |
|
74 |
+
parsed_data = []
|
75 |
+
|
76 |
with open(gname, "r") as f:
|
77 |
for l in f:
|
78 |
|
|
|
83 |
name = m.group(3)
|
84 |
#print([addr, typ, name])
|
85 |
|
86 |
+
parsed_data.append((addr,typ,name))
|
87 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
#print(df.head())
|
89 |
+
|
90 |
+
all_addrs = set(x[0] for x in parsed_data)
|
91 |
+
|
92 |
+
all_dis = get_all_dis(all_addrs)
|
93 |
+
|
94 |
+
for addr, typ, name in parsed_data:
|
95 |
+
|
96 |
+
dis = get_dis_from_all_dis(int(addr, 16))
|
97 |
+
#objs.append((addr, typ, name, dis))
|
98 |
+
if dis is None:
|
99 |
+
dis = ""
|
100 |
+
typ = "notfound"
|
101 |
+
else:
|
102 |
+
dis = dis.decode("utf8")
|
103 |
+
|
104 |
+
df = df.append({'Binary': bname, 'Addr': addr, 'Name': name, 'Type': typ, 'Disassembly': dis}, ignore_index=True)
|
105 |
+
|
106 |
+
if False:
|
107 |
+
df.to_csv(oname, index=False)
|
108 |
|
109 |
df.to_csv(oname, index=False)
|
110 |
|