def find_linear_terminator(ea, max_num=256): """Find the terminating instruction of a basic block, without actually associating the instructions with the block. This scans linearly until we find something that is definitely a basic block terminator. This does not consider the case of intermediate blocks.""" prev_term = None for i in xrange(max_num): term_inst = get_instruction(ea) if not term_inst: log.warning( "Unable to decode linear terminator at {:08x}".format(ea)) term_inst = prev_term break prev_term = term_inst if term_inst.is_block_terminator() or not term_inst.is_valid(): break ea = term_inst.next_ea # The next instruction was already processed as part of some other scan. if program.instruction_is_valid(ea) or instruction_is_referenced(ea): break if term_inst: term_inst.mark_as_terminator() return term_inst
def find_linear_terminator(ea, max_num=256): """Find the terminating instruction of a basic block, without actually associating the instructions with the block. This scans linearly until we find something that is definitely a basic block terminator. This does not consider the case of intermediate blocks.""" prev_term = None for i in xrange(max_num): term_inst = get_instruction(ea) if not term_inst: log.warning("Unable to decode linear terminator at {:08x}".format(ea)) term_inst = prev_term break prev_term = term_inst if term_inst.is_block_terminator() or not term_inst.is_valid(): break ea = term_inst.next_ea # The next instruction was already processed as part of some other scan. if program.instruction_is_valid(ea) or instruction_is_referenced(ea): break if term_inst: term_inst.mark_as_terminator() return term_inst
def get_instruction(ea): """Gets the instruction located at `ea`. If we haven't initialized an `Instruction` data structure for the instruction at `ea`, then we decode the instruction and fill in the missing data.""" if program.has_instruction(ea): return program.get_instruction(ea) if program.instruction_is_valid(ea): return None decoded_inst, decoded_bytes = decode_instruction(ea) if not decoded_inst: log.error("Unable to decode instruction at {:08x}".format(ea)) return None inst = program.get_instruction(ea) if inst.is_valid(): return inst inst.bytes = "".join(decoded_bytes) inst.personality = get_instruction_personality(decoded_inst) return inst
def get_instruction(ea): """Gets the instruction located at `ea`. If we haven't initialized an `Instruction` data structure for the instruction at `ea`, then we decode the instruction and fill in the missing data.""" if program.has_instruction(ea): return program.get_instruction(ea) if program.instruction_is_valid(ea): return None decoded_inst, decoded_bytes = decode_instruction(ea) if not decoded_inst: log.error("Unable to decode instruction at {:08x}".format(ea)) return None inst = program.get_instruction(ea) if inst.is_valid(): return inst inst.bytes = "".join(decoded_bytes) inst.personality = get_instruction_personality(decoded_inst) return inst