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

Minor state/platform refactor #1320

Merged
merged 1 commit into from
Jan 2, 2019
Merged
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
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