def test_resume(self): m = Manticore(ms_file, stdin_size=17) # First instruction of `main` @m.hook(0x4009AE) def serialize(state): with m.locked_context() as context: if context.get("kill", False): raise TerminateState("Abandoning...") context["kill"] = True raise SerializeState("/tmp/ms_checkpoint.pkl") m.run() self.assertEqual(m.count_terminated_states(), 1) for state in m.terminated_states: self.assertEqual(state.cpu.PC, 0x4009AE) m = Manticore.from_saved_state("/tmp/ms_checkpoint.pkl") self.assertEqual(m.count_ready_states(), 1) for st in m.ready_states: self.assertEqual(state.cpu.PC, 0x4009AE) m.run() self.assertEqual(m.count_terminated_states(), 18) self.assertTrue( any("exit status: 0" in str(st._terminated_by) for st in m.terminated_states) ) m.finalize() for st in m.terminated_states: if "exit status: 0" in str(st._terminated_by): self.assertEqual(st.solve_one(st.input_symbols[0]), b"coldlikeminisodas")
class StateMergeTest(unittest.TestCase): # Need to add a plugin that counts the number of states in did_fork_state, and records the max # Then, when we hit class StateCounter(Plugin): def did_fork_state_callback(self, *_args, **_kwargs): self.max_states = max( self.max_states, self.manticore.count_busy_states() + self.manticore.count_ready_states() + self.manticore.count_killed_states() + self.manticore.count_terminated_states(), ) @property def max_states(self): with self.manticore.locked_context() as ctx: return ctx.setdefault("max_states", 0) @max_states.setter def max_states(self, new_val): with self.manticore.locked_context() as ctx: ctx["max_states"] = new_val def setUp(self): core = config.get_group("core") core.seed = 61 core.mprocessing = core.mprocessing.single dirname = os.path.dirname(__file__) self.m = Manticore( os.path.join(dirname, "binaries", "basic_state_merging"), policy="random" ) self.plugin = self.StateCounter() self.m.register_plugin(Merger()) self.m.register_plugin(self.plugin) def test_state_merging(self): @self.m.hook(0x40065D) def hook_post_merge(*_args, **_kwargs): with self.m.locked_context() as ctx: ctx["state_count"] = ( self.m.count_busy_states() + self.m.count_ready_states() + self.m.count_killed_states() + self.m.count_terminated_states() ) self.m.run() s = config.get_group("core").seed self.assertLess( self.m.context["state_count"], self.plugin.max_states, f"State merging failed with seed: {s}", )