manticore/examples/script/run_hook.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

30 lines
606 B
Python
Executable File

#!/usr/bin/env python
import sys
from manticore import Manticore
'''
Demonstrates the ability to set a basic hook on a specific program counter and
the ability to read from memory.
'''
if __name__ == '__main__':
path = sys.argv[1]
pc = int(sys.argv[2], 0)
m = Manticore(path)
# Trigger an event when PC reaches a certain value
@m.hook(pc)
def reached_goal(state):
cpu = state.cpu
assert cpu.PC == pc
instruction = cpu.read_int(cpu.PC)
print "Execution goal reached."
print "Instruction bytes: {:08x}".format(instruction)
m.run()