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
This commit is contained in:
Mark Mossberg
2017-02-27 15:44:33 -05:00
committed by GitHub
parent 98567efeaa
commit d6393cc8a6
7 changed files with 44 additions and 24 deletions
+7 -17
View File
@@ -5,34 +5,24 @@ from manticore import Manticore
# This example demonstrates a basic hook (PC register)
def get_args():
class Args(object): pass
args = Args()
args.replay = None; args.data = ''; args.dumpafter = 0; args.maxstates = 0;
args.maxstorage = 0; args.stats = True; args.verbose = False; args.log = '-';
return args
if __name__ == '__main__':
path = sys.argv[1]
args = get_args()
pc = int(sys.argv[2], 0)
args.programs = sys.argv[1:]
# Create a new Manticore object
m = Manticore(None, path, args)
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 == 0x10858
assert cpu.PC == pc
instruction = cpu.read(cpu.PC, 4)
instruction = cpu.read_int(cpu.PC)
print "Execution goal reached."
print "Instruction bytes: {:08x}".format(cpu.pc)
print "Instruction bytes: {:08x}".format(instruction)
m.add_pc_hook(0x10858, reached_goal)
# Start path exploration. start() returns when Manticore
# Start path exploration. m.run() returns when Manticore
# finishes
m.run()