-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangrtestparallel.py
More file actions
100 lines (90 loc) · 4.02 KB
/
angrtestparallel.py
File metadata and controls
100 lines (90 loc) · 4.02 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
import angr
from angr.errors import UnsupportedNodeTypeError
from angr.analyses import (
CFGFast,
Decompiler
)
from claripy import ClaripyOperationError
import os
import joblib
from joblib import Parallel, delayed
import timeout_decorator
import time
from datetime import datetime
from timeout_decorator.timeout_decorator import TimeoutError as time_error
from tqdm import tqdm
import contextlib
@contextlib.contextmanager
def tqdm_joblib(tqdm_object):
class TqdmBatchCompletionCallback(joblib.parallel.BatchCompletionCallBack):
def __call__(self, *args, **kwargs):
tqdm_object.update(n=self.batch_size)
return super().__call__(*args, **kwargs)
old_batch_callback = joblib.parallel.BatchCompletionCallBack
joblib.parallel.BatchCompletionCallBack = TqdmBatchCompletionCallback
try:
yield tqdm_object
finally:
joblib.parallel.BatchCompletionCallBack = old_batch_callback
tqdm_object.close()
#import ipdb
#ipdb.set_trace()
timeoutduration = 900 #timeout value
Path_To_Coreutil_Binaries = #"/path/to/binary/" #Enter path to folder with coreutil binaries in question
Path_To_Output_Folder = #"/path/to/output/folder/" #specify output folder
Num_Cores_In_Use = #specify number of cores to be used
Error_Path = #"/path/to/error/folder/" #specify folder where error files will be written
@timeout_decorator.timeout(timeoutduration)
def decompile_func(f, filename, p, cfg):
now = datetime.now()
start_time=time.time()
name = f.name + " " + filename
#print(f.name + " " + filename + " " + "total tasks:" + str(len(cfg.functions.values()))+ " binary " + str(binarycounter) + " of " + str(totalbinaries) )
filepath = os.path.join(Path_To_Output_Folder+ name)
try:
dec = p.analyses[Decompiler].prep()(f, cfg=cfg.model)
with open(filepath, "w") as a:
a.write(dec.codegen.text)
#print("START_TIME " + now.strftime("%H:%M:%S"))
#print("--- %s seconds ---" % (time.time() - start_time) + name)
#print("CURRENT_TIME " + datetime.now().strftime("%H:%M:%S"))
except AttributeError:
with open(Error_Path + 'AttributeError', "a") as a:
a.write(name + "\n")
except ValueError:
with open(Error_Path + 'ValueError', "a") as a:
a.write(name + "\n")
except ClaripyOperationError:
with open(Error_Path + 'ClaripyOperationError', "a") as a:
a.write(name + "\n")
except TypeError:
with open(Error_Path + 'TypeError', "a") as a:
a.write(name + "\n")
except UnsupportedNodeTypeError:
with open(Error_Path + 'UnsupportedNodeTypeError', "a") as a:
a.write(name + "\n")
except NotImplementedError:
with open(Error_Path + 'NotImplementedError', "a") as a:
a.write(name + "\n")
except time_error:
with open(Error_Path + 'TimeoutError', "a") as a:
a.write(name + "\n" )
print("*********TIMEDOUT**********")
print("START_TIME " + now.strftime("%H:%M:%S"))
print("--- %s seconds ---" % (time.time() - start_time) + " " + name)
print("CURRENT_TIME " + datetime.now().strftime("%H:%M:%S"))
except Exception:
with open(Error_Path + 'UnkownError', "a") as a:
a.write(name + "\n" )
def decompile():
binarycounter = 1
totalbinaries = len(os.listdir(Path_To_Coreutil_Binaries))
for filename in os.listdir(Path_To_Coreutil_Binaries):
print("binary " + str(binarycounter) + " of " + str(totalbinaries))
p = angr.Project(Path_To_Coreutil_Binaries + filename, auto_load_libs=False, load_debug_info=True)
cfg = p.analyses[CFGFast].prep()(data_references=True, normalize=True)
if __name__ == '__main__':
with tqdm_joblib(tqdm(desc="Functions", total=len(cfg.functions.values()))) as progress_bar:
Parallel(n_jobs=Num_Cores_In_Use)(delayed(decompile_func)(f,filename,p, cfg) for f in cfg.functions.values() )
binarycounter +=1
decompile()