Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EXPLICIT fork policy #2514

Merged
merged 7 commits into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions manticore/core/manticore.py
Expand Up @@ -480,7 +480,7 @@ def from_saved_state(cls, filename: str, *args, **kwargs):

return cls(deserialized, *args, **kwargs)

def _fork(self, state, expression, policy="ALL", setstate=None):
def _fork(self, state, expression, policy="ALL", setstate=None, values=None):
Boyan-MILANOV marked this conversation as resolved.
Show resolved Hide resolved
"""
Fork state on expression concretizations.
Using policy build a list of solutions for expression.
Expand Down Expand Up @@ -510,7 +510,7 @@ def setstate(x, y):
pass

# Find a set of solutions for expression
solutions = state.concretize(expression, policy)
solutions = state.concretize(expression, policy, explicit_values=values)

if not solutions:
raise ManticoreError("Forking on unfeasible constraint set")
Expand Down
25 changes: 19 additions & 6 deletions manticore/core/state.py
Expand Up @@ -21,11 +21,11 @@


class StateException(Exception):
""" All state related exceptions """
"""All state related exceptions"""


class TerminateState(StateException):
""" Terminates current state exploration """
"""Terminates current state exploration"""

def __init__(self, message, testcase=False):
super().__init__(message)
Expand All @@ -51,9 +51,19 @@ class Concretize(StateException):

"""

_ValidPolicies = ["MIN", "MAX", "MINMAX", "ALL", "SAMPLED", "ONE", "PESSIMISTIC", "OPTIMISTIC"]

def __init__(self, message, expression, setstate=None, policy=None, **kwargs):
_ValidPolicies = [
"MIN",
"MAX",
"MINMAX",
"ALL",
"SAMPLED",
"ONE",
"PESSIMISTIC",
"OPTIMISTIC",
"EXPLICIT",
]

def __init__(self, message, expression, setstate=None, policy=None, values=None, **kwargs):
if policy is None:
policy = "ALL"
if policy not in self._ValidPolicies:
Expand All @@ -63,6 +73,7 @@ def __init__(self, message, expression, setstate=None, policy=None, **kwargs):
self.expression = expression
self.setstate = setstate
self.policy = policy
self.values = values
self.message = f"Concretize: {message} (Policy: {policy})"
super().__init__(**kwargs)

Expand Down Expand Up @@ -365,7 +376,7 @@ def new_symbolic_value(self, nbits, label=None, taint=frozenset()):
self._input_symbols.append(expr)
return expr

def concretize(self, symbolic, policy, maxcount=7):
def concretize(self, symbolic, policy, maxcount=7, explicit_values=None):
"""This finds a set of solutions for symbolic using policy.

This limits the number of solutions returned to `maxcount` to avoid
Expand Down Expand Up @@ -415,6 +426,8 @@ def concretize(self, symbolic, policy, maxcount=7):
else:
# We assume the path constraint was feasible to begin with
vals = (True,)
elif policy == "EXPLICIT":
vals = explicit_values[:maxcount]
Boyan-MILANOV marked this conversation as resolved.
Show resolved Hide resolved
else:
assert policy == "ALL"
vals = self._solver.get_all_values(
Expand Down
2 changes: 1 addition & 1 deletion manticore/core/worker.py
Expand Up @@ -155,7 +155,7 @@ def run(self, *args):
# Though, normally fork() saves the spawned childs,
# returns a None and let _get_state choose what to explore
# next
m._fork(current_state, exc.expression, exc.policy, exc.setstate)
m._fork(current_state, exc.expression, exc.policy, exc.setstate, exc.values)
current_state = None

except TerminateState as exc:
Expand Down