Renaming from McTest to DeepState.
This commit is contained in:
@@ -28,7 +28,7 @@ LOG_LEVEL_ERROR = 3
|
||||
LOG_LEVEL_FATAL = 4
|
||||
|
||||
|
||||
LOGGER = logging.getLogger("mctest")
|
||||
LOGGER = logging.getLogger("deepstate")
|
||||
LOGGER.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ class Stream(object):
|
||||
self.entries = entries
|
||||
|
||||
|
||||
class McTest(object):
|
||||
"""Wrapper around a symbolic executor for making it easy to do common McTest-
|
||||
class DeepState(object):
|
||||
"""Wrapper around a symbolic executor for making it easy to do common DeepState-
|
||||
specific things."""
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -120,7 +120,7 @@ class McTest(object):
|
||||
return chars, next_ea
|
||||
|
||||
def read_test_info(self, ea):
|
||||
"""Read in a `McTest_TestInfo` info structure from memory."""
|
||||
"""Read in a `DeepState_TestInfo` info structure from memory."""
|
||||
prev_test_ea, ea = self.read_uintptr_t(ea)
|
||||
test_func_ea, ea = self.read_uintptr_t(ea)
|
||||
test_name_ea, ea = self.read_uintptr_t(ea)
|
||||
@@ -249,7 +249,7 @@ class McTest(object):
|
||||
self.context['abandoned'] = True
|
||||
|
||||
def api_is_symbolic_uint(self, arg):
|
||||
"""Implements the `McTest_IsSymbolicUInt` API, which returns whether or
|
||||
"""Implements the `DeepState_IsSymbolicUInt` API, which returns whether or
|
||||
not a given value is symbolic."""
|
||||
solutions = self.concretize_many(arg, 2)
|
||||
if not solutions:
|
||||
@@ -262,7 +262,7 @@ class McTest(object):
|
||||
return 1
|
||||
|
||||
def api_assume(self, arg):
|
||||
"""Implements the `McTest_Assume` API function, which injects a constraint
|
||||
"""Implements the `DeepState_Assume` API function, which injects a constraint
|
||||
into the solver."""
|
||||
constraint = arg != 0
|
||||
if not self.add_constraint(constraint):
|
||||
@@ -271,7 +271,7 @@ class McTest(object):
|
||||
self.abandon_test()
|
||||
|
||||
def api_pass(self):
|
||||
"""Implements the `McTest_Pass` API function, which marks this test as
|
||||
"""Implements the `DeepState_Pass` API function, which marks this test as
|
||||
having passed, and stops further execution."""
|
||||
if self.context['failed']:
|
||||
self.api_fail()
|
||||
@@ -281,7 +281,7 @@ class McTest(object):
|
||||
self.pass_test()
|
||||
|
||||
def api_fail(self):
|
||||
"""Implements the `McTest_Fail` API function, which marks this test as
|
||||
"""Implements the `DeepState_Fail` API function, which marks this test as
|
||||
having failed, and stops further execution."""
|
||||
self.context['failed'] = True
|
||||
info = self.context['info']
|
||||
@@ -289,12 +289,12 @@ class McTest(object):
|
||||
self.fail_test()
|
||||
|
||||
def api_soft_fail(self):
|
||||
"""Implements the `McTest_SoftFail` API function, which marks this test
|
||||
"""Implements the `DeepState_SoftFail` API function, which marks this test
|
||||
as having failed, but lets execution continue."""
|
||||
self.context['failed'] = True
|
||||
|
||||
def api_abandon(self, arg):
|
||||
"""Implements the `McTest_Abandon` API function, which marks this test
|
||||
"""Implements the `DeepState_Abandon` API function, which marks this test
|
||||
as having aborted due to some unrecoverable error."""
|
||||
info = self.context['info']
|
||||
ea = self.concretize(arg, constrain=True)
|
||||
@@ -303,7 +303,7 @@ class McTest(object):
|
||||
self.abandon_test()
|
||||
|
||||
def api_log(self, level, ea):
|
||||
"""Implements the `McTest_Log` API function, which prints a C string
|
||||
"""Implements the `DeepState_Log` API function, which prints a C string
|
||||
to a specific log level."""
|
||||
self.api_log_stream(level)
|
||||
|
||||
@@ -339,19 +339,19 @@ class McTest(object):
|
||||
self.context[stream_id] = stream
|
||||
|
||||
def api_stream_int(self, level, format_ea, unpack_ea, uint64_ea):
|
||||
"""Implements the `_McTest_StreamInt`, which streams an integer into a
|
||||
"""Implements the `_DeepState_StreamInt`, which streams an integer into a
|
||||
holding buffer for the log."""
|
||||
return self._api_stream_int_float(level, format_ea, unpack_ea,
|
||||
uint64_ea, int)
|
||||
|
||||
def api_stream_float(self, level, format_ea, unpack_ea, double_ea):
|
||||
"""Implements the `_McTest_StreamFloat`, which streams an integer into a
|
||||
"""Implements the `_DeepState_StreamFloat`, which streams an integer into a
|
||||
holding buffer for the log."""
|
||||
return self._api_stream_int_float(level, format_ea, unpack_ea,
|
||||
double_ea, float)
|
||||
|
||||
def api_stream_string(self, level, format_ea, str_ea):
|
||||
"""Implements the `_McTest_StreamString`, which streams a C-string into a
|
||||
"""Implements the `_DeepState_StreamString`, which streams a C-string into a
|
||||
holding buffer for the log."""
|
||||
level = self.concretize(level, constrain=True)
|
||||
assert level in LOG_LEVEL_TO_LOGGER
|
||||
@@ -20,13 +20,13 @@ import logging
|
||||
import multiprocessing
|
||||
import sys
|
||||
import traceback
|
||||
from .common import McTest
|
||||
from .common import DeepState
|
||||
|
||||
L = logging.getLogger("mctest.angr")
|
||||
L = logging.getLogger("deepstate.angr")
|
||||
L.setLevel(logging.INFO)
|
||||
|
||||
|
||||
class AngrTest(McTest):
|
||||
class AngrTest(DeepState):
|
||||
def __init__(self, state=None, procedure=None):
|
||||
super(AngrTest, self).__init__()
|
||||
if procedure:
|
||||
@@ -131,57 +131,57 @@ def hook_function(project, ea, cls):
|
||||
def make_symbolic_input(state, input_begin_ea, input_end_ea):
|
||||
"""Fill in the input data array with symbolic data."""
|
||||
input_size = input_end_ea - input_begin_ea
|
||||
data = state.se.Unconstrained('MCTEST_INPUT', input_size * 8)
|
||||
data = state.se.Unconstrained('DEEPSTATE_INPUT', input_size * 8)
|
||||
state.memory.store(input_begin_ea, data)
|
||||
return data
|
||||
|
||||
|
||||
class IsSymbolicUInt(angr.SimProcedure):
|
||||
"""Implements McTest_IsSymblicUInt, which returns 1 if its input argument
|
||||
"""Implements DeepState_IsSymblicUInt, which returns 1 if its input argument
|
||||
has more then one solutions, and zero otherwise."""
|
||||
def run(self, arg):
|
||||
return AngrTest(procedure=self).api_is_symbolic_uint(arg)
|
||||
|
||||
|
||||
class Assume(angr.SimProcedure):
|
||||
"""Implements _McTest_Assume, which tries to inject a constraint."""
|
||||
"""Implements _DeepState_Assume, which tries to inject a constraint."""
|
||||
def run(self, arg):
|
||||
AngrTest(procedure=self).api_assume(arg)
|
||||
|
||||
|
||||
class Pass(angr.SimProcedure):
|
||||
"""Implements McTest_Pass, which notifies us of a passing test."""
|
||||
"""Implements DeepState_Pass, which notifies us of a passing test."""
|
||||
def run(self):
|
||||
AngrTest(procedure=self).api_pass()
|
||||
|
||||
|
||||
class Fail(angr.SimProcedure):
|
||||
"""Implements McTest_Fail, which notifies us of a failing test."""
|
||||
"""Implements DeepState_Fail, which notifies us of a failing test."""
|
||||
def run(self):
|
||||
AngrTest(procedure=self).api_fail()
|
||||
|
||||
|
||||
class Abandon(angr.SimProcedure):
|
||||
"""Implements McTest_Fail, which notifies us of a failing test."""
|
||||
"""Implements DeepState_Fail, which notifies us of a failing test."""
|
||||
def run(self, reason):
|
||||
AngrTest(procedure=self).api_abandon(reason)
|
||||
|
||||
|
||||
class SoftFail(angr.SimProcedure):
|
||||
"""Implements McTest_SoftFail, which notifies us of a failing test."""
|
||||
"""Implements DeepState_SoftFail, which notifies us of a failing test."""
|
||||
def run(self):
|
||||
AngrTest(procedure=self).api_soft_fail()
|
||||
|
||||
|
||||
class StreamInt(angr.SimProcedure):
|
||||
"""Implements _McTest_StreamInt, which gives us an integer to stream, and
|
||||
"""Implements _DeepState_StreamInt, which gives us an integer to stream, and
|
||||
the format to use for streaming."""
|
||||
def run(self, level, format_ea, unpack_ea, uint64_ea):
|
||||
AngrTest(procedure=self).api_stream_int(level, format_ea, unpack_ea,
|
||||
uint64_ea)
|
||||
|
||||
class StreamFloat(angr.SimProcedure):
|
||||
"""Implements _McTest_StreamFloat, which gives us an double to stream, and
|
||||
"""Implements _DeepState_StreamFloat, which gives us an double to stream, and
|
||||
the format to use for streaming."""
|
||||
def run(self, level, format_ea, unpack_ea, double_ea):
|
||||
AngrTest(procedure=self).api_stream_float(level, format_ea, unpack_ea,
|
||||
@@ -189,21 +189,21 @@ class StreamFloat(angr.SimProcedure):
|
||||
|
||||
|
||||
class StreamString(angr.SimProcedure):
|
||||
"""Implements _McTest_StreamString, which gives us an double to stream, and
|
||||
"""Implements _DeepState_StreamString, which gives us an double to stream, and
|
||||
the format to use for streaming."""
|
||||
def run(self, level, format_ea, str_ea):
|
||||
AngrTest(procedure=self).api_stream_string(level, format_ea, str_ea)
|
||||
|
||||
|
||||
class LogStream(angr.SimProcedure):
|
||||
"""Implements McTest_LogStream, which converts the contents of a stream for
|
||||
"""Implements DeepState_LogStream, which converts the contents of a stream for
|
||||
level `level` into a log for level `level`."""
|
||||
def run(self, level):
|
||||
AngrTest(procedure=self).api_log_stream(level)
|
||||
|
||||
|
||||
class Log(angr.SimProcedure):
|
||||
"""Implements McTest_Log, which lets Angr intercept and handle the
|
||||
"""Implements DeepState_Log, which lets Angr intercept and handle the
|
||||
printing of log messages from the simulated tests."""
|
||||
def run(self, level, ea):
|
||||
AngrTest(procedure=self).api_log(level, ea)
|
||||
@@ -250,7 +250,7 @@ def run_test(project, test, apis, run_state):
|
||||
|
||||
|
||||
def main():
|
||||
"""Run McTest."""
|
||||
"""Run DeepState."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Symbolically execute unit tests with Angr")
|
||||
|
||||
@@ -277,11 +277,11 @@ def main():
|
||||
|
||||
addr_size_bits = entry_state.arch.bits
|
||||
|
||||
# Concretely execute up until `McTest_InjectAngr`.
|
||||
# Concretely execute up until `DeepState_InjectAngr`.
|
||||
concrete_manager = angr.SimulationManager(
|
||||
project=project,
|
||||
active_states=[entry_state])
|
||||
setup_ea = project.kb.labels.lookup('McTest_Setup')
|
||||
setup_ea = project.kb.labels.lookup('DeepState_Setup')
|
||||
concrete_manager.explore(find=setup_ea)
|
||||
run_state = concrete_manager.found[0]
|
||||
|
||||
@@ -289,7 +289,7 @@ def main():
|
||||
# symbols. Technically we can look these up with the `labels.lookup` API,
|
||||
# but we have the API table for Manticore-compatibility, so we may as well
|
||||
# use it.
|
||||
ea_of_api_table = project.kb.labels.lookup('McTest_API')
|
||||
ea_of_api_table = project.kb.labels.lookup('DeepState_API')
|
||||
|
||||
mc = AngrTest(state=run_state)
|
||||
apis = mc.read_api_table(ea_of_api_table)
|
||||
@@ -20,18 +20,18 @@ import manticore
|
||||
import multiprocessing
|
||||
import sys
|
||||
import traceback
|
||||
from .common import McTest
|
||||
from .common import DeepState
|
||||
|
||||
from manticore.core.state import TerminateState
|
||||
from manticore.utils.helpers import issymbolic
|
||||
|
||||
|
||||
L = logging.getLogger("mctest.mcore")
|
||||
L = logging.getLogger("deepstate.mcore")
|
||||
L.setLevel(logging.INFO)
|
||||
|
||||
OUR_TERMINATION_REASON = "I McTest'd it"
|
||||
OUR_TERMINATION_REASON = "I DeepState'd it"
|
||||
|
||||
class MCoreTest(McTest):
|
||||
class MCoreTest(DeepState):
|
||||
def __init__(self, state):
|
||||
super(MCoreTest, self).__init__()
|
||||
self.state = state
|
||||
@@ -128,7 +128,7 @@ def make_symbolic_input(state, input_begin_ea, input_end_ea):
|
||||
input_size = input_end_ea - input_begin_ea
|
||||
data = []
|
||||
for i in xrange(input_end_ea - input_begin_ea):
|
||||
input_byte = state.new_symbolic_value(8, "MCTEST_INPUT_{}".format(i))
|
||||
input_byte = state.new_symbolic_value(8, "DEEPSTATE_INPUT_{}".format(i))
|
||||
data.append(input_byte)
|
||||
state.cpu.write_int(input_begin_ea + i, input_byte, 8)
|
||||
|
||||
@@ -136,63 +136,63 @@ def make_symbolic_input(state, input_begin_ea, input_end_ea):
|
||||
|
||||
|
||||
def hook_IsSymbolicUInt(state, arg):
|
||||
"""Implements McTest_IsSymblicUInt, which returns 1 if its input argument
|
||||
"""Implements DeepState_IsSymblicUInt, which returns 1 if its input argument
|
||||
has more then one solutions, and zero otherwise."""
|
||||
return MCoreTest(state).api_is_symbolic_uint(arg)
|
||||
|
||||
|
||||
def hook_Assume(state, arg):
|
||||
"""Implements _McTest_Assume, which tries to inject a constraint."""
|
||||
"""Implements _DeepState_Assume, which tries to inject a constraint."""
|
||||
MCoreTest(state).api_assume(arg)
|
||||
|
||||
|
||||
def hook_StreamInt(state, level, format_ea, unpack_ea, uint64_ea):
|
||||
"""Implements _McTest_StreamInt, which gives us an integer to stream, and
|
||||
"""Implements _DeepState_StreamInt, which gives us an integer to stream, and
|
||||
the format to use for streaming."""
|
||||
MCoreTest(state).api_stream_int(level, format_ea, unpack_ea, uint64_ea)
|
||||
|
||||
|
||||
def hook_StreamFloat(state, level, format_ea, unpack_ea, double_ea):
|
||||
"""Implements _McTest_StreamFloat, which gives us an double to stream, and
|
||||
"""Implements _DeepState_StreamFloat, which gives us an double to stream, and
|
||||
the format to use for streaming."""
|
||||
MCoreTest(state).api_stream_float(level, format_ea, unpack_ea, double_ea)
|
||||
|
||||
|
||||
def hook_StreamString(state, level, format_ea, str_ea):
|
||||
"""Implements _McTest_StreamString, which gives us an double to stream, and
|
||||
"""Implements _DeepState_StreamString, which gives us an double to stream, and
|
||||
the format to use for streaming."""
|
||||
MCoreTest(state).api_stream_string(level, format_ea, str_ea)
|
||||
|
||||
|
||||
def hook_LogStream(state, level):
|
||||
"""Implements McTest_LogStream, which converts the contents of a stream for
|
||||
"""Implements DeepState_LogStream, which converts the contents of a stream for
|
||||
level `level` into a log for level `level`."""
|
||||
MCoreTest(state).api_log_stream(level)
|
||||
|
||||
|
||||
def hook_Pass(state):
|
||||
"""Implements McTest_Pass, which notifies us of a passing test."""
|
||||
"""Implements DeepState_Pass, which notifies us of a passing test."""
|
||||
MCoreTest(state).api_pass()
|
||||
|
||||
|
||||
def hook_Fail(state):
|
||||
"""Implements McTest_Fail, which notifies us of a passing test."""
|
||||
"""Implements DeepState_Fail, which notifies us of a passing test."""
|
||||
MCoreTest(state).api_fail()
|
||||
|
||||
|
||||
def hook_Abandon(state, reason):
|
||||
"""Implements McTest_Abandon, which notifies us that a problem happened
|
||||
in McTest."""
|
||||
"""Implements DeepState_Abandon, which notifies us that a problem happened
|
||||
in DeepState."""
|
||||
MCoreTest(state).api_abandon(reason)
|
||||
|
||||
|
||||
def hook_SoftFail(state):
|
||||
"""Implements McTest_Fail, which notifies us of a passing test."""
|
||||
"""Implements DeepState_Fail, which notifies us of a passing test."""
|
||||
MCoreTest(state).api_soft_fail()
|
||||
|
||||
|
||||
def hook_Log(state, level, ea):
|
||||
"""Implements McTest_Log, which lets Manticore intercept and handle the
|
||||
"""Implements DeepState_Log, which lets Manticore intercept and handle the
|
||||
printing of log messages from the simulated tests."""
|
||||
MCoreTest(state).api_log(level, ea)
|
||||
|
||||
@@ -288,12 +288,12 @@ def main():
|
||||
m._binary_type = 'not elf'
|
||||
m._binary_obj = m._initial_state.platform.elf
|
||||
|
||||
setup_ea = m._get_symbol_address('McTest_Setup')
|
||||
setup_ea = m._get_symbol_address('DeepState_Setup')
|
||||
setup_state = m._initial_state
|
||||
|
||||
mc = MCoreTest(setup_state)
|
||||
|
||||
ea_of_api_table = m._get_symbol_address('McTest_API')
|
||||
ea_of_api_table = m._get_symbol_address('DeepState_API')
|
||||
apis = mc.read_api_table(ea_of_api_table)
|
||||
del mc
|
||||
m.add_hook(setup_ea, lambda state: run_tests(args, state, apis))
|
||||
@@ -17,15 +17,15 @@ import distutils.core
|
||||
import os
|
||||
import setuptools
|
||||
|
||||
MCTEST_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
DEEPSTATE_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
setuptools.setup(
|
||||
name="mctest",
|
||||
name="deepstate",
|
||||
version="0.1",
|
||||
package_dir={"": "${CMAKE_SOURCE_DIR}/bin"},
|
||||
packages=['mctest'],
|
||||
description="McTest augments C/C++ Test-Driven Development with Symbolic Execution",
|
||||
url="https://github.com/trailofbits/mctest",
|
||||
packages=['deepstate'],
|
||||
description="DeepState augments C/C++ Test-Driven Development with Symbolic Execution",
|
||||
url="https://github.com/trailofbits/deepstate",
|
||||
author="Peter Goodman",
|
||||
author_email="peter@trailofbits.com",
|
||||
license="Apache-2.0",
|
||||
@@ -33,7 +33,7 @@ setuptools.setup(
|
||||
install_requires=['angr', 'manticore'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'mctest = mctest.__main__:main',
|
||||
'mctest-angr = mctest.main_angr:main'
|
||||
'deepstate = deepstate.main_manticore:main',
|
||||
'deepstate-angr = deepstate.main_angr:main'
|
||||
]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user