initialize executor at manticore initialization (#471)

This commit is contained in:
JP Smith 2017-08-31 10:16:52 -05:00 committed by GitHub
parent ca0d7b60d2
commit c6f8fd1291
2 changed files with 39 additions and 36 deletions

View File

@ -154,10 +154,6 @@ class Executor(Eventful):
if self.load_workspace():
if initial is not None:
logger.error("Ignoring initial state")
else:
if initial is not None:
self.add(initial)
self.forward_events_from(initial, True)
@contextmanager
def locked_context(self):
@ -369,6 +365,7 @@ class Executor(Eventful):
#load selected state from secondary storage
if current_state_id is not None:
current_state = self._workspace.load_state(current_state_id)
self.forward_events_from(current_state, True)
self.publish('will_load_state', current_state, current_state_id)
#notify siblings we have a state to play with
self._start_run()

View File

@ -20,7 +20,7 @@ from .core.executor import Executor
from .core.parser import parse
from .core.state import State, TerminateState
from .core.smtlib import solver, ConstraintSet
from .core.workspace import ManticoreOutput
from .core.workspace import ManticoreOutput, Workspace
from .platforms import linux, decree, windows
from .utils.helpers import issymbolic, is_binja_disassembler
from .utils.nointerrupt import WithKeyboardInterruptAs
@ -187,8 +187,30 @@ class Manticore(object):
self._dumpafter = 0
self._maxstates = 0
self._maxstorage = 0
self._workspace = getattr(args, 'workspace', None)
self._symbolic_files = [] # list of string
self._executor = None
if isinstance(self._workspace, str):
if ':' not in self._workspace:
self._workspace = 'fs:' + self._workspace
self._output = ManticoreOutput(self._workspace)
self._executor = Executor(workspace=self._output.descriptor)
#Link Executor events to default callbacks in manticore object
self._executor.subscribe('did_read_register', self._read_register_callback)
self._executor.subscribe('will_write_register', self._write_register_callback)
self._executor.subscribe('did_read_memory', self._read_memory_callback)
self._executor.subscribe('will_write_memory', self._write_memory_callback)
self._executor.subscribe('will_execute_instruction', self._execute_instruction_callback)
self._executor.subscribe('will_decode_instruction', self._decode_instruction_callback)
self._executor.subscribe('will_store_state', self._store_state_callback)
self._executor.subscribe('will_load_state', self._load_state_callback)
self._executor.subscribe('will_fork_state', self._fork_state_callback)
self._executor.subscribe('forking_state', self._forking_state_callback)
self._executor.subscribe('will_terminate_state', self._terminate_state_callback)
self._executor.subscribe('will_generate_testcase', self._generate_testcase_callback)
#Executor wide shared context
self._context = {}
@ -315,6 +337,18 @@ class Manticore(object):
def maxstorage(self, max_storage):
self._maxstorage = max_storage
@property
def workspace(self):
return self._workspace
@workspace.setter
def workspace(self, ws):
assert not self._running, "Can't set workspace if Manticore is running."
if ':' not in ws:
ws = "fs:" + ws
self._output = ManticoreOutput(ws)
self._executor._workspace = Workspace(self._executor._lock, self._output._descriptor)
def hook(self, pc):
'''
A decorator used to register a hook function for a given instruction address.
@ -688,36 +722,8 @@ class Manticore(object):
replay = map(lambda x: int(x, 16), freplay.readlines())
initial_state = self._make_state(self._binary)
if args is not None and hasattr(args, 'workspace') and isinstance(args.workspace, str):
if ':' not in args.workspace:
ws_path = 'fs:' + args.workspace
else:
ws_path = args.workspace
else:
ws_path = None
self._output = ManticoreOutput(ws_path)
self._executor = Executor(initial_state,
workspace=self._output.descriptor,
policy=self._policy,
context=self.context)
#Link Executor events to default callbacks in manticore object
self._executor.subscribe('did_read_register', self._read_register_callback)
self._executor.subscribe('will_write_register', self._write_register_callback)
self._executor.subscribe('did_read_memory', self._read_memory_callback)
self._executor.subscribe('will_write_memory', self._write_memory_callback)
self._executor.subscribe('will_execute_instruction', self._execute_instruction_callback)
self._executor.subscribe('will_decode_instruction', self._decode_instruction_callback)
self._executor.subscribe('will_store_state', self._store_state_callback)
self._executor.subscribe('will_load_state', self._load_state_callback)
self._executor.subscribe('will_fork_state', self._fork_state_callback)
self._executor.subscribe('forking_state', self._forking_state_callback)
self._executor.subscribe('will_terminate_state', self._terminate_state_callback)
self._executor.subscribe('will_generate_testcase', self._generate_testcase_callback)
self._executor.policy = self.policy
self._executor.add(initial_state)
if self._hooks:
self._executor.subscribe('will_execute_instruction', self._hook_callback)