我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用idaapi.is_call_insn()。
def get_func_code_refs_from(func_ea, iaddrs): """Returns a set with the code references from this function""" code_refs = set() for addr in iaddrs: ref = idaapi.BADADDR for r in idautils.XrefsFrom(addr, idaapi.XREF_FAR): if r.iscode: to_func = idaapi.get_func(r.to) if not to_func or to_func.startEA != func_ea: ref = r.to else: ref = r.to if (ref != idaapi.BADADDR or idaapi.is_call_insn(addr) or idaapi.is_indirect_jump_insn(addr)): #print hex(i.addr), i, hex(ref) code_refs.add(ref) return code_refs
def enum_calls_in_function(fva): ''' yield the call instructions in the given function. Args: fva (int): the starting address of a function Returns: sequence[tuple[int, str]]: the address of a call instruction, and the disassembly line at that address ''' for ea in enum_function_addrs(fva): if idaapi.is_call_insn(ea): disasm = ida_lines.generate_disassembly(ea, 16, True, False)[1][0] # replace consequent whitespaces by a single whitespaces disasm = re.sub("\s\s+", " ", disasm) yield ea, disasm
def is_call(ea): '''Returns True if the instruction at ``ea`` is a call instruction.''' # MASK_TYPE = 0x0300 # T_BRANCH = 0x0100 # # MASK_BRTYPE = 0b111 # CF_JMPIMM = 0b001 # CF_JMPCOND = 0b000 # CF_CALL = 0b010 # # F = feature(ea) # return database.is_code(ea) and (feature(ea) & MASK_TYPE == T_BRANCH) and (feature(ea) & idaapi.CF_CALL == idaapi.CF_CALL) idaapi.decode_insn(ea) return idaapi.is_call_insn(ea)
def graph_down(ea, path=set()): """ Recursively collect all function calls. Copied with minor modifications from http://hooked-on-mnemonics.blogspot.com/2012/07/renaming-subroutine-blocks-and.html """ path.add(ea) # # iterate through all the instructions in the target function (ea) and # inspect all the call instructions # for x in [x for x in idautils.FuncItems(ea) if idaapi.is_call_insn(x)]: # TODO for r in idautils.XrefsFrom(x, idaapi.XREF_FAR): #print "0x%08X" % h, "--calls-->", "0x%08X" % r.to if not r.iscode: continue # get the function pointed at by this call func = idaapi.get_func(r.to) if not func: continue # ignore calls to imports / library calls / thunks if (func.flags & (idaapi.FUNC_THUNK | idaapi.FUNC_LIB)) != 0: continue # # if we have not traversed to the destination function that this # call references, recurse down to it to continue our traversal # if r.to not in path: graph_down(r.to, path) return path