def test_daemon(self): self.fired = False m = Manticore(ms_file, stdin_size=17) m.register_daemon(self.daemon) m.run() self.assertTrue(self.fired)
def test_introspect_daemon(self): self.history = [] m = Manticore(ms_file, stdin_size=17) m.register_daemon(self.introspect_loop) m.run() sleep(1) # Leave time for the callback to fire after we've finished self.assertGreater(len(self.history), 0) progression = [] for hist in self.history: hist = hist.values() progression.append(( sum(1 if (st.state_list == StateLists.ready) else 0 for st in hist), sum(1 if (st.state_list == StateLists.busy) else 0 for st in hist), sum(1 if (st.state_list == StateLists.terminated) else 0 for st in hist), )) self.assertEqual(progression[-1][0], 0) # Once finished, we have no ready states self.assertEqual(progression[-1][1], 0) # Once finished, we have no busy states # Once finished, we have only terminated states. self.assertGreater(progression[-1][2], 0) f = io.StringIO() with contextlib.redirect_stdout(f): m.pretty_print_states() self.assertIn("Terminated States: {}".format(progression[-1][2]), f.getvalue())
def test_custom_introspector(self): self.history = [] m = Manticore(ms_file, introspection_plugin_type=MyIntrospector, stdin_size=17) m.register_daemon(self.introspect_loop) m.run() self.assertGreater(len(self.history), 0) self.assertTrue( any( getattr(st, "i_am_custom", False) for st in self.history[-1].values()))
# Only works if all states fork from the initial state df_print(0) print() def run_every(callee: typing.Callable, duration: int = 3) -> typing.Callable: """ Returns a function that calls <callee> every <duration> seconds """ def inner( thread ): # Takes `thread` as argument, which is provided by the daemon thread API while True: # Pass Manticore's state descriptor dict to the callee callee(thread.manticore.introspect()) sleep(duration) return inner m = Manticore(args.binary) # Tell Manticore to run `print_fork_tree` every second m.register_daemon(run_every(print_fork_tree, 1)) m.run() sleep(1) print("Final fork tree:") print_fork_tree(m.introspect())