(state, stmts_to_instrument, regs_to_initialize)
Hook statements as specified in stmts_to_instrument and overwrite values loaded in those statements.

        :param SimState state:              The program state to insert hooks to.
        :param list stmts_to_instrument:    A list of statements to instrument.
        :param list regs_to_initialize:     A list of registers to initialize.
        :return:                            None
Hook statements as specified in stmts_to_instrument and overwrite values loaded in those statements.
Hook statements as specified in stmts_to_instrument and overwrite values loaded in those statements .
def _instrument_statements(state, stmts_to_instrument, regs_to_initialize):
        """
        Hook statements as specified in stmts_to_instrument and overwrite values loaded in those statements.

        :param SimState state:              The program state to insert hooks to.
        :param list stmts_to_instrument:    A list of statements to instrument.
        :param list regs_to_initialize:     A list of registers to initialize.
        :return:                            None
        """

        for sort, block_addr, stmt_idx in stmts_to_instrument:
            l.debug("Add a %s hook to overwrite memory/register values at %#x:%d.", sort, block_addr, stmt_idx)
            if sort == 'mem_write':
                bp = BP(when=BP_BEFORE, enabled=True, action=StoreHook.hook,
                        condition=lambda _s, a=block_addr, idx=stmt_idx:
                            _s.scratch.bbl_addr == a and _s.scratch.stmt_idx == idx
                        )
                state.inspect.add_breakpoint('mem_write', bp)
            elif sort == 'mem_read':
                hook = LoadHook()
                bp0 = BP(when=BP_BEFORE, enabled=True, action=hook.hook_before,
                         condition=lambda _s, a=block_addr, idx=stmt_idx:
                            _s.scratch.bbl_addr == a and _s.scratch.stmt_idx == idx
                         )
                state.inspect.add_breakpoint('mem_read', bp0)
                bp1 = BP(when=BP_AFTER, enabled=True, action=hook.hook_after,
                         condition=lambda _s, a=block_addr, idx=stmt_idx:
                            _s.scratch.bbl_addr == a and _s.scratch.stmt_idx == idx
                         )
                state.inspect.add_breakpoint('mem_read', bp1)
            elif sort == 'reg_write':
                bp = BP(when=BP_BEFORE, enabled=True, action=PutHook.hook,
                        condition=lambda _s, a=block_addr, idx=stmt_idx:
                            _s.scratch.bbl_addr == a and _s.scratch.stmt_idx == idx
                        )
                state.inspect.add_breakpoint('reg_write', bp)
            else:
                raise NotImplementedError("Unsupported sort %s in stmts_to_instrument." % sort)

        reg_val = 0x13370000
        for block_addr, stmt_idx, reg_offset, reg_bits in regs_to_initialize:
            l.debug("Add a hook to initialize register %s at %x:%d.",
                    state.arch.translate_register_name(reg_offset, size=reg_bits),
                    block_addr, stmt_idx)
            bp = BP(when=BP_BEFORE, enabled=True, action=RegisterInitializerHook(reg_offset, reg_bits, reg_val).hook,
                    condition=lambda _s: _s.scratch.bbl_addr == block_addr and _s.inspect.statement == stmt_idx
                    )
            state.inspect.add_breakpoint('statement', bp)
            reg_val += 16
def _instrument_statements ( state , stmts_to_instrument , regs_to_initialize ) : for sort , block_addr , stmt_idx in stmts_to_instrument : l . debug ( "Add a %s hook to overwrite memory/register values at %#x:%d." , sort , block_addr , stmt_idx ) if sort == 'mem_write' : bp = BP ( when = BP_BEFORE , enabled = True , action = StoreHook . hook , condition = lambda _s , a = block_addr , idx = stmt_idx : _s . scratch . bbl_addr == a and _s . scratch . stmt_idx == idx ) state . inspect . add_breakpoint ( 'mem_write' , bp ) elif sort == 'mem_read' : hook = LoadHook ( ) bp0 = BP ( when = BP_BEFORE , enabled = True , action = hook . hook_before , condition = lambda _s , a = block_addr , idx = stmt_idx : _s . scratch . bbl_addr == a and _s . scratch . stmt_idx == idx ) state . inspect . add_breakpoint ( 'mem_read' , bp0 ) bp1 = BP ( when = BP_AFTER , enabled = True , action = hook . hook_after , condition = lambda _s , a = block_addr , idx = stmt_idx : _s . scratch . bbl_addr == a and _s . scratch . stmt_idx == idx ) state . inspect . add_breakpoint ( 'mem_read' , bp1 ) elif sort == 'reg_write' : bp = BP ( when = BP_BEFORE , enabled = True , action = PutHook . hook , condition = lambda _s , a = block_addr , idx = stmt_idx : _s . scratch . bbl_addr == a and _s . scratch . stmt_idx == idx ) state . inspect . add_breakpoint ( 'reg_write' , bp ) else : raise NotImplementedError ( "Unsupported sort %s in stmts_to_instrument." % sort ) reg_val = 0x13370000 for block_addr , stmt_idx , reg_offset , reg_bits in regs_to_initialize : l . debug ( "Add a hook to initialize register %s at %x:%d." , state . arch . translate_register_name ( reg_offset , size = reg_bits ) , block_addr , stmt_idx ) bp = BP ( when = BP_BEFORE , enabled = True , action = RegisterInitializerHook ( reg_offset , reg_bits , reg_val ) . hook , condition = lambda _s : _s . scratch . bbl_addr == block_addr and _s . inspect . statement == stmt_idx ) state . inspect . add_breakpoint ( 'statement' , bp ) reg_val += 16