manticore/examples/script/count_instructions.py
Yan 7679773088 Update examples (#477)
* Use locked_context() in count_instructions example

 * We use this example on the front page, and it currently generates
   a flood of warnings.

* Update example indeces

* Remove dump_stats()

* Remove extra comments

* Remove redundant comments
2017-09-01 17:05:43 -04:00

31 lines
770 B
Python
Executable File

#!/usr/bin/env python
import sys
from manticore import Manticore
'''
Count the number of emulated instructions.
This example uses the context property of the Manticore object to store data
that's updated by the hook function. Manticore.context is needed to properly
share data when running with multiple worker processes.
'''
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.stderr.write("Usage: %s [binary]\n"%(sys.argv[0],))
sys.exit(2)
m = Manticore(sys.argv[1])
with m.locked_context() as context:
context['count'] = 0
@m.hook(None)
def explore(state):
with m.locked_context() as context:
context['count'] += 1
m.run(procs=3)
print "Executed ", m.context['count'], " instructions."