-
Notifications
You must be signed in to change notification settings - Fork 1
/
binary_cfg_extractor.py
executable file
·46 lines (33 loc) · 1.23 KB
/
binary_cfg_extractor.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
import os
from binary_extractor.analysis.graph import CFGGraph
from binary_extractor.platforms.ETH.cfg import EthereumCFG
from shutil import copyfile
def main():
fileList1 = os.listdir("./bytecode/integeroverflow/")
fileList = []
for file_name in fileList1:
if '.txt' in file_name:
fileList.append(file_name)
currentpath = os.getcwd()
for file_name in fileList:
f = open('./bytecode/integeroverflow/' + file_name, 'r')
# global bytecode_hex
bytecode_hex = f.read()
f.close()
# create the CFG
cfg = EthereumCFG(bytecode_hex)
# generic visualization api
graph = CFGGraph(cfg)
graph.view()
print(file_name + " is done!")
os.chdir(currentpath)
cfgList = os.listdir("./binary_cfg_code/integeroverflow/")
cfgList.sort(key=lambda x: int(x[:-4]))
if (str(file_name)[0:-4] + '.' + 'txt') not in cfgList:
copyfile('./graph.cfg.gv',
'./binary_cfg_code/integeroverflow/' + str(file_name)[0:-4] + '.' + 'txt')
os.chdir("./binary_cfg_code/integeroverflow/")
print(str(file_name)[0:-4])
os.chdir(currentpath)
if __name__ == '__main__':
main()