Skip to content

Commit 3273510

Browse files
Add files via upload
1 parent 1dc32b3 commit 3273510

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9538
-0
lines changed

analysis/CFGPartAnalysis.py

Lines changed: 1783 additions & 0 deletions
Large diffs are not rendered by default.

analysis/Cover.py

Lines changed: 815 additions & 0 deletions
Large diffs are not rendered by default.

analysis/InitRun.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Mon Dec 21 18:14:17 2020
5+
6+
@author: Sara Baradaran, Mahdi Heidari, Ali Kamali
7+
"""
8+
9+
from analysis.MCSimulation import MCSimulation
10+
from analysis.MallocExtractParam import mallocEx
11+
from analysis.TypeUtils import *
12+
13+
class InitRun:
14+
def __init__(self,project,mc_config,cfg_analyses,target_func=None):
15+
self.project=project
16+
self.project.hook_symbol('malloc',mallocEx(num_args=1))
17+
self.target_func=target_func
18+
self.cfg_analyses=cfg_analyses
19+
self.malloc_points=[]
20+
self.mc=MCSimulation(config_file=mc_config)
21+
for addr,func in self.cfg_analyses.getAddressOfFunctionCall('malloc'):
22+
if self.cfg_analyses.isReachableFromMain(func.name):
23+
self.malloc_points.append((addr,func))
24+
25+
26+
27+
def run(self,args_index=[]):
28+
flag=True
29+
res=None
30+
while flag:
31+
inSample = self.mc.generate(count=1)[0]
32+
inputs=[]
33+
34+
for i in range(len(inSample)):
35+
tp=self.mc.getVarTypes(i)
36+
if 'int' in tp:
37+
inputs.append(getIntConcreteBV(int(inSample[i])))
38+
elif isinstance(tp,tuple) and 'char*' in tp[0]:
39+
inputs.append(getCharStringConcreteBV(inSample[i][0:20]))
40+
else:
41+
inputs.append(getCharStringConcreteBV(inSample[i]))
42+
argss=[]
43+
if len(args_index) > 0:
44+
argss.append(self.project.filename)
45+
for indx in args_index:
46+
argss.append(inputs.pop(indx-1))
47+
state=self.project.factory.entry_state(args=argss,stdin=angr.SimPacketsStream(name='stdin', content=inputs,),add_options=angr.options.unicorn)
48+
else:
49+
state=self.project.factory.entry_state(stdin=angr.SimPacketsStream(name='stdin', content=inputs,),add_options=angr.options.unicorn)
50+
state.libc.buf_symbolic_bytes=100
51+
simgr=self.project.factory.simulation_manager(state)
52+
simgr.explore(find=self._explore_states)
53+
54+
res=dict(simgr.deadended[0].globals)
55+
if len(self.malloc_points) == len(res):
56+
flag=False
57+
return res
58+
59+
60+
def _explore_states(self,state):
61+
for addr,func in self.malloc_points:
62+
if addr in state.block().instruction_addrs:
63+
state.globals[addr]=None
64+
return False
65+
66+
67+
68+

0 commit comments

Comments
 (0)