def branch_on_watched( bs, watched, func ): # should have an argument on whether to merge like unlift does (unlift versions should be merged too) flow = bs.flow.clone() call_stack = list(bs.call_stack) branches = {} # value -> string def watcher(new_value): if not branches: branches[value] = bs.program.render_code[label. position:label.position + patch_len] if new_value in branches: data = branches[value] else: prgm = get_redirection(lambda rdi: get_jmp( compiler.translate("branch_on_watched", flow, stack=call_stack, this=func(new_value)))) data = prgm.render_code prgm.render_code = OffsetListProxy(bs.program.render_code, label.position) branches[value] = data bs.program.render_code[label.position:label.position + patch_len] = data value = watched.get_and_watch(watcher) label = bs.program.get_unique_label() bs.code += label # remove later for i in xrange(patch_len): bs.code += isa.nop() func(value)(bs)
def branch_on_watched(bs, watched, func): # should have an argument on whether to merge like unlift does (unlift versions should be merged too) flow = bs.flow.clone() call_stack = list(bs.call_stack) branches = {} # value -> string def watcher(new_value): if not branches: branches[value] = bs.program.render_code[label.position:label.position + patch_len] if new_value in branches: data = branches[value] else: prgm = get_redirection(lambda rdi: get_jmp(compiler.translate("branch_on_watched", flow, stack=call_stack, this=func(new_value)))) data = prgm.render_code prgm.render_code = OffsetListProxy(bs.program.render_code, label.position) branches[value] = data bs.program.render_code[label.position:label.position + patch_len] = data value = watched.get_and_watch(watcher) label = bs.program.get_unique_label() bs.code += label # remove later for i in xrange(patch_len): bs.code += isa.nop() func(value)(bs)
def _align_stream(self, length, align): return [x86.nop() for i in xrange(0, align - (length % align))]