8000 Remove old compatibility code from SimulationManager by twizmwazin · Pull Request #5156 · angr/angr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove old compatibility code from SimulationManager #5156

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 2 additions & 53 deletions angr/sim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import claripy
import mulpyplexer

from .exploration_techniques import ExplorationTechnique, Veritesting, Threading, Explorer, Suggestions
from .exploration_techniques import ExplorationTechnique, Veritesting, Explorer, Suggestions
from .misc.hookset import HookSet
from .misc.ux import once
from .misc.picklable_lock import PicklableLock
from .errors import SimError, SimMergeError
from .sim_state import SimState
Expand Down Expand Up @@ -83,7 +82,6 @@ def __init__(
completion_mode=any,
techniques=None,
suggestions=True,
**kwargs,
):
super().__init__()

Expand Down Expand Up @@ -124,23 +122,6 @@ def __init__(
if suggestions:
self.use_technique(Suggestions())

# 8<----------------- Compatibility layer -----------------

if auto_drop is None and not kwargs.pop("save_unconstrained", True):
self._auto_drop |= {"unconstrained"}

if kwargs.pop("veritesting", False):
self.use_technique(Veritesting(**kwargs.get("veritesting_options", {})))
kwargs.pop("veritesting_options", {})

threads = kwargs.pop("threads", None)
if threads is not None:
self.use_technique(Threading(threads))

if kwargs:
raise TypeError("Unexpected keyword arguments: " + " ".join(kwargs))
# ------------------ Compatibility layer ---------------->8

if auto_drop:
self._auto_drop |= set(auto_drop)

Expand Down Expand Up @@ -267,7 +248,7 @@ def remove_technique(self, tech):
def _is_overridden(name):
return getattr(tech, name).__code__ is not getattr(ExplorationTechnique, name).__code__

overridden = filter(_is_overridden, ("step", "filter", "selector", "step_state", "successors"))
overridden = {m for m in ("step", "filter", "selector", "step_state", "successors") if _is_overridden(m)}
hooks = {name: getattr(tech, name) for name in overridden}
HookSet.remove_hooks(self, **hooks)

Expand Down Expand Up @@ -382,12 +363,10 @@ def step(
self,
stash="active",
target_stash=None,
n=None,
selector_func=None,
step_func=None,
error_list=None,
successor_func=None,
until=None,
filter_func=None,
**run_args,
):
Expand All @@ -411,9 +390,6 @@ def step(
Otherwise, project.factory.successors will be used.
:param filter_func: If provided, should be a function that takes a state and return the name
of the stash, to which the state should be moved.
:param until: (DEPRECATED) If provided, should be a function that takes a SimulationManager and
returns True or False. Stepping will terminate when it is True.
:param n: (DEPRECATED) The number of times to step (default: 1 if "until" is not provided)

Additionally, you can pass in any of the following keyword args for project.factory.successors:

Expand All @@ -433,25 +409,6 @@ def step(
:rtype: SimulationManager
"""
l.info("Stepping %s of %s", stash, self)
# 8<----------------- Compatibility layer -----------------
if n is not None or until is not None:
if once("simgr_step_n_until"):
print(
"\x1b[31;1mDeprecation warning: the use of `n` and `until` arguments is deprecated. "
"Consider using simgr.run() with the same arguments if you want to specify "
"a number of steps or an additional condition on when to stop the execution.\x1b[0m"
)
return self.run(
stash,
n,
until,
selector_func=selector_func,
step_func=step_func,
successor_func=successor_func,
filter_func=filter_func,
**run_args,
)
# ------------------ Compatibility layer ---------------->8
bucket = defaultdict(list)
target_stash = target_stash or stash
error_list = error_list if error_list is not None else self._errored
Expand Down Expand Up @@ -759,8 +716,6 @@ def split(
else:
keep, split = states[:limit], states[limit:]

keep, split = map(list, (keep, split))

self._clear_states(from_stash)
self._store_states(from_stash, keep)
self._store_states(to_stash, split)
Expand Down Expand Up @@ -929,12 +884,6 @@ def __setstate__(self, s):
if self._hierarchy is None:
self._hierarchy = StateHierarchy()

# 8<----------------- Compatibility layer -----------------
def _one_step(self, stash, selector_func=None, successor_func=None, **kwargs):
return self.step(stash=stash, selector_func=selector_func, successor_func=successor_func, **kwargs)

# ------------------- Compatibility layer --------------->8


class ErrorRecord:
"""
Expand Down
24 changes: 12 additions & 12 deletions tests/sim/test_simulation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@


class TestSimulationManager(unittest.TestCase):
def _run_fauxware(self, arch, threads):
def _run_fauxware(self, arch):
p = angr.Project(os.path.join(test_location, arch, "fauxware"), load_options={"auto_load_libs": False})

pg = p.factory.simulation_manager(threads=threads)
pg = p.factory.simulation_manager()
assert len(pg.active) == 1
assert pg.active[0].history.depth == 0

# step until the backdoor split occurs
pg2 = pg.step(until=lambda lpg: len(lpg.active) > 1, step_func=lambda lpg: lpg.prune())
pg2 = pg.run(until=lambda lpg: len(lpg.active) > 1, step_func=lambda lpg: lpg.prune())
assert len(pg2.active) == 2
assert any(b"SOSNEAKY" in s for s in pg2.mp_active.posix.dumps(0).mp_items)
assert not all(b"SOSNEAKY" in s for s in pg2.mp_active.posix.dumps(0).mp_items)
Expand All @@ -46,7 +46,7 @@ def _run_fauxware(self, arch, threads):
assert len(pg3.auth) == 1

# step the backdoor path until it returns to main
pg4 = pg3.step(until=lambda lpg: lpg.backdoor[0].history.jumpkinds[-1] == "Ijk_Ret", stash="backdoor")
pg4 = pg3.run(until=lambda lpg: lpg.backdoor[0].history.jumpkinds[-1] == "Ijk_Ret", stash="backdoor")
main_addr = pg4.backdoor[0].addr

assert len(pg4.active) == 0
Expand Down Expand Up @@ -76,7 +76,7 @@ def _run_fauxware(self, arch, threads):

# test selecting paths to step
pg8 = p.factory.simulation_manager()
pg8.step(until=lambda lpg: len(lpg.active) > 1, step_func=lambda lpg: lpg.prune().drop(stash="pruned"))
pg8.run(until=lambda lpg: len(lpg.active) > 1, step_func=lambda lpg: lpg.prune().drop(stash="pruned"))
st1, st2 = pg8.active
pg8.step(selector_func=lambda p: p is st1, step_func=lambda lpg: lpg.prune().drop(stash="pruned"))
assert st2 is pg8.active[1]
Expand All @@ -98,25 +98,25 @@ def _run_fauxware(self, arch, threads):
assert all(len(s) == 0 for s in pg8.stashes.values())

def test_fauxware_armel(self):
self._run_fauxware("armel", None)
self._run_fauxware("armel")

def test_fauxware_armhf(self):
self._run_fauxware("armhf", None)
self._run_fauxware("armhf")

def test_fauxware_mips(self):
self._run_fauxware("mips", None)
self._run_fauxware("mips")

def test_fauxware_mipsel(self):
self._run_fauxware("mipsel", None)
self._run_fauxware("mipsel")

def test_fauxware_ppc(self):
self._run_fauxware("ppc", None)
self._run_fauxware("ppc")

def test_fauxware_ppc64(self):
self._run_fauxware("ppc64", None)
self._run_fauxware("ppc64")

def test_fauxware_x86_64(self):
self._run_fauxware("x86_64", None)
self._run_fauxware("x86_64")

def test_find_to_middle(self):
# Test the ability of PathGroup to execute until an instruction in the middle of a basic block
Expand Down
Loading
0