manticore/examples/script/run_callback.py
Mark Mossberg d6393cc8a6 Add hook decorator (#28)
* Add m.add_hook test

* Add @m.hook test

* Add `hook` decorator for convenience

* Update readme and examples

* Update run_callback

* Improve `add_hook` docstring

expound on callback structure

* Rm debug print

* Improve docstring
2017-02-27 15:44:33 -05:00

29 lines
617 B
Python
Executable File

#!/usr/bin/env python
import sys
from manticore import Manticore
# This example demonstrates a basic hook (PC register)
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)
# Start path exploration. m.run() returns when Manticore
# finishes
m.run()