improved python3 support
This commit is contained in:
parent
b473726781
commit
bb9e02834d
@ -242,7 +242,7 @@ class DeepState(object):
|
||||
|
||||
# Create the symbols that feed API functions like `DeepState_Int`.
|
||||
symbols = []
|
||||
for i, ea in enumerate(xrange(apis['InputBegin'], apis['InputEnd'])):
|
||||
for i, ea in enumerate(range(apis['InputBegin'], apis['InputEnd'])):
|
||||
symbol = self.create_symbol('DEEP_INPUT_{}'.format(i), 8)
|
||||
self.write_uint8_t(ea, symbol)
|
||||
symbols.append(symbol)
|
||||
@ -334,7 +334,9 @@ class DeepState(object):
|
||||
return
|
||||
|
||||
test_dir = self.context['test_dir']
|
||||
test_name = hashlib.md5.new(input_bytes).hexdigest()
|
||||
md5 = hashlib.md5()
|
||||
md5.update(input_bytes)
|
||||
test_name = md5.hexdigest()
|
||||
|
||||
if self.context['failed']:
|
||||
test_name += ".fail"
|
||||
@ -368,7 +370,7 @@ class DeepState(object):
|
||||
# likely to get the same concrete byte values across different tools (e.g.
|
||||
# Manticore, Angr).
|
||||
input_bytes = bytearray()
|
||||
for i in xrange(input_length):
|
||||
for i in range(input_length):
|
||||
b = self.concretize_min(symbols[i], constrain=True)
|
||||
input_bytes.append(b)
|
||||
|
||||
@ -464,7 +466,7 @@ class DeepState(object):
|
||||
begin_ea, end_ea))
|
||||
self.abandon_test()
|
||||
|
||||
for i in xrange(end_ea - begin_ea):
|
||||
for i in range(end_ea - begin_ea):
|
||||
val, _ = self.read_uint8_t(begin_ea + i, concretize=True, constrain=True)
|
||||
self.write_uint8_t(begin_ea + i, val)
|
||||
|
||||
@ -551,7 +553,7 @@ class DeepState(object):
|
||||
format_str = self.read_c_string(format_ea)[0]
|
||||
unpack_str = self.read_c_string(unpack_ea)[0]
|
||||
uint64_bytes = []
|
||||
for i in xrange(8):
|
||||
for i in range(8):
|
||||
b, _ = self.read_uint8_t(uint64_ea + i, concretize=False)
|
||||
uint64_bytes.append(b)
|
||||
|
||||
|
||||
@ -18,7 +18,8 @@ logging.basicConfig()
|
||||
|
||||
import sys
|
||||
try:
|
||||
import manticore
|
||||
import manticore
|
||||
import manticore.native
|
||||
except Exception as e:
|
||||
if "Z3NotFoundError" in repr(type(e)):
|
||||
print("Manticore requires Z3 to be installed.")
|
||||
@ -52,7 +53,7 @@ class DeepManticore(DeepState):
|
||||
return manticore.issymbolic(val)
|
||||
|
||||
def create_symbol(self, name, size_in_bits):
|
||||
return self.state.new_symbolic_value(size_in_bits, name)
|
||||
return self.state.new_symbolic_value(size_in_bits)
|
||||
|
||||
def read_uintptr_t(self, ea, concretize=True, constrain=False):
|
||||
addr_size_bits = self.state.cpu.address_bit_size
|
||||
@ -285,7 +286,10 @@ def done_test(_, state, state_id, reason):
|
||||
# DeepState API, so we can just report it as is. Otherwise, we check to see if
|
||||
# it was due to behavior that would typically crash the program being analyzed.
|
||||
# If so, we save it as a crash. If not, we abandon it.
|
||||
if OUR_TERMINATION_REASON not in reason:
|
||||
if type(reason) is not str:
|
||||
reason = str(reason)
|
||||
|
||||
if OUR_TERMINATION_REASON != reason:
|
||||
if _is_program_crash(reason):
|
||||
L.info("State {} terminated due to crashing program behavior: {}".format(
|
||||
state_id, reason))
|
||||
@ -326,7 +330,8 @@ def find_symbol_ea(m, name):
|
||||
def do_run_test(state, apis, test, hook_test=False):
|
||||
"""Run an individual test case."""
|
||||
state.cpu.PC = test.ea
|
||||
m = manticore.Manticore(state, sys.argv[1:])
|
||||
m = manticore.native.Manticore(state, sys.argv[1:])
|
||||
#m = MainThreadWrapper(m, _CONTROLLER)
|
||||
m.verbosity(1)
|
||||
|
||||
state = m.initial_state
|
||||
@ -356,7 +361,7 @@ def do_run_test(state, apis, test, hook_test=False):
|
||||
m.add_hook(test.ea, hook(hook_TakeOver))
|
||||
|
||||
m.subscribe('will_terminate_state', done_test)
|
||||
m.run()
|
||||
m.run(procs=1)
|
||||
|
||||
|
||||
def run_test(state, apis, test, hook_test=False):
|
||||
@ -369,7 +374,7 @@ def run_test(state, apis, test, hook_test=False):
|
||||
|
||||
def run_tests(args, state, apis):
|
||||
"""Run all of the test cases."""
|
||||
pool = multiprocessing.Pool(processes=max(1, args.num_workers))
|
||||
#pool = multiprocessing.Pool(processes=max(1, args.num_workers))
|
||||
results = []
|
||||
mc = DeepManticore(state)
|
||||
tests = mc.find_test_cases()
|
||||
@ -378,11 +383,11 @@ def run_tests(args, state, apis):
|
||||
len(tests), args.num_workers))
|
||||
|
||||
for test in tests:
|
||||
res = pool.apply_async(run_test, (state, apis, test))
|
||||
res = run_test(state, apis, test)
|
||||
results.append(res)
|
||||
|
||||
pool.close()
|
||||
pool.join()
|
||||
#pool.close()
|
||||
#pool.join()
|
||||
|
||||
exit(0)
|
||||
|
||||
@ -426,7 +431,7 @@ def main_takeover(m, args, takeover_symbol):
|
||||
takeover_hook = lambda state: run_test(state, apis, fake_test, hook_test)
|
||||
m.add_hook(takeover_ea, takeover_hook)
|
||||
|
||||
m.run()
|
||||
m.run(procs=1)
|
||||
|
||||
|
||||
def main_unit_test(m, args):
|
||||
@ -450,14 +455,14 @@ def main_unit_test(m, args):
|
||||
del mc
|
||||
|
||||
m.add_hook(setup_ea, lambda state: run_tests(args, state, apis))
|
||||
m.run()
|
||||
m.run(procs=1)
|
||||
|
||||
|
||||
def main():
|
||||
args = DeepManticore.parse_args()
|
||||
|
||||
try:
|
||||
m = manticore.Manticore(args.binary)
|
||||
m = manticore.native.Manticore(args.binary)
|
||||
except Exception as e:
|
||||
L.critical("Cannot create Manticore instance on binary {}: {}".format(
|
||||
args.binary, e))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user