def handle_operand(self, insn, op, isRead): flags = ida_bytes.get_flags(insn.ea) is_offs = ida_bytes.is_off(flags, op.n) dref_flag = ida_xref.dr_R if isRead else ida_xref.dr_W def_arg = ida_bytes.is_defarg(flags, op.n) optype = op.type itype = insn.itype # create code xrefs if optype == ida_ua.o_imm: makeoff = False if itype in [self.itype_ncall, self.itype_call]: insn.add_cref(op.value, op.offb, ida_xref.fl_CN) makeoff = True #elif itype == self.itype_mov: # e.g., mov #addr, PC # insn.add_cref(op.value, op.offb, ida_xref.fl_JN) # makeoff = True if makeoff and not def_arg: otype = ida_offset.get_default_reftype(insn.ea) ida_offset.op_offset(insn.ea, op.n, otype, ida_idaapi.BADADDR, insn.cs) is_offs = True if is_offs: insn.add_off_drefs(op, ida_xref.dr_O, 0) elif optype == ida_ua.o_near: if insn.itype in [self.itype_ncall, self.itype_call]: fl = ida_xref.fl_CN else: fl = ida_xref.fl_JN insn.add_cref(op.addr, op.offb, fl) # create data xrefs elif optype == ida_ua.o_mem: insn.create_op_data(op.addr, op.offb, op.dtype) insn.add_dref(op.addr, op.offb, dref_flag) '''
def op_type_changed(self, ea, n): flags = ida_bytes.get_flags(ea) self.log("op_type_changed(ea=0x%08X, n=%d). Flags now: 0x%08X" % (ea, n, flags)) buf = ida_nalt.opinfo_t() opi = ida_bytes.get_opinfo(buf, ea, n, flags) if opi: if ida_bytes.is_struct(flags): self.log("New struct: 0x%08X (name=%s)" % ( opi.tid, ida_struct.get_struc_name(opi.tid))) elif ida_bytes.is_strlit(flags): encidx = ida_nalt.get_str_encoding_idx(opi.strtype) if encidx == ida_nalt.STRENC_DEFAULT: encidx = ida_nalt.get_default_encoding_idx(ida_nalt.get_strtype_bpu(opi.strtype)) encname = ida_nalt.get_encoding_name(encidx) strlen = ida_bytes.get_max_strlit_length( ea, opi.strtype, ida_bytes.ALOPT_IGNHEADS | ida_bytes.ALOPT_IGNCLT) raw = ida_bytes.get_strlit_contents(ea, strlen, opi.strtype) or b"" self.log("New strlit: 0x%08X, raw hex=%s (encoding=%s)" % ( opi.strtype, binascii.hexlify(raw), encname)) elif ida_bytes.is_off(flags, n): self.log("New offset: refinfo={target=0x%08X, base=0x%08X, tdelta=0x%08X, flags=0x%X}" % ( opi.ri.target, opi.ri.base, opi.ri.tdelta, opi.ri.flags)) elif ida_bytes.is_enum(flags, n): self.log("New enum: 0x%08X (enum=%s), serial=%d" % ( opi.ec.tid, ida_enum.get_enum_name(opi.ec.tid), opi.ec.serial)) pass elif ida_bytes.is_stroff(flags, n): parts = [] for i in range(opi.path.len): tid = opi.path.ids[i] parts.append("0x%08X (name=%s)" % (tid, ida_struct.get_struc_name(tid))) self.log("New stroff: path=[%s] (len=%d, delta=0x%08X)" % ( ", ".join(parts), opi.path.len, opi.path.delta)) elif ida_bytes.is_custom(flags) or ida_bytes.is_custfmt(flags, n): self.log("New custom data type") # unimplemented else: print("Cannot retrieve opinfo_t")
def is_op_offset(insn, op): """ Check is an operand has been marked as an offset (by auto-analysis or manually) """ flags = idaapi.get_flags(insn.ea) return ida_bytes.is_off(flags, op.n)