Skip to content

Commit

Permalink
Minor state/platform refactor (#1320)
Browse files Browse the repository at this point in the history
The `StateBase` class had two properties that are only used in native
engines: `cpu` and `mem`.

Those two used `self._platform.current` and that `current` is a
property in linux and decree platforms that returns current process
platfrom (?).
  • Loading branch information
disconnect3d committed Jan 2, 2019
1 parent b7626fc commit 23199f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
24 changes: 0 additions & 24 deletions manticore/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ def __init__(self, constraints, platform, **kwargs):
# Events are lost in serialization and fork !!
self.forward_events_from(platform)

# FIXME(felipe) This should go into some event callback in a plugin (start_run?)
self._init_context()

def __getstate__(self):
state = super().__getstate__()
state['platform'] = self._platform
Expand Down Expand Up @@ -418,24 +415,3 @@ def symbolicate_buffer(self, data, label='INPUT', wildcard='+', string=False, ta
else:
assert b != 0
return data

@property
def cpu(self):
return self._platform.current

@property
def mem(self):
return self._platform.current.memory

# FIXME(felipe) Remove this
def _init_context(self):
self.context['branches'] = dict()

# FIXME(felipe) Remove this
def record_branch(self, target):
branches = self.context['branches']
branch = (self.cpu._last_pc, target)
if branch in branches:
branches[branch] += 1
else:
branches[branch] = 1
7 changes: 7 additions & 0 deletions manticore/native/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@


class State(StateBase):
@property
def cpu(self):
return self._platform.current

@property
def mem(self):
return self._platform.current.memory

def execute(self):
from .cpu.abstractcpu import ConcretizeRegister # must be here, otherwise we get circular imports
Expand Down
13 changes: 7 additions & 6 deletions manticore/platforms/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class OSException(Exception):


class SyscallNotImplemented(OSException):
''' Exception raised when you try to call an unimplemented
system call. Go to linux.py and add it!
'''
"""
Exception raised when you try to call an unimplemented system call.
Go to linux.py and add it!
"""

def __init__(self, idx, name):
msg = f'Syscall index "{idx}" ({name}) not implemented.'
Expand All @@ -24,9 +25,9 @@ def __init__(self, reg_num, message='Concretizing syscall argument', policy='SAM


class Platform(Eventful):
'''
Base class for all operating system platforms.
'''
"""
Base class for all platforms e.g. operating systems or virtual machines.
"""

def __init__(self, path, **kwargs):
super().__init__(**kwargs)
Expand Down

0 comments on commit 23199f2

Please sign in to comment.