def apply_struct(start, end, reg_name, struct_name): offsets, operands = infer_struct_offsets(start, end, reg_name) sid = get_struct(struct_name) for ea, n in operands: insn = idautils.DecodeInstruction(ea) idc.op_stroff(insn, n, sid, 0)
def typeset_reg_for_address(ea, reg, type_name): opnds = sark.Line(ea).insn.operands for i in range(len(opnds)): if ('[%s]' % get_reg_user_name(ea, reg) in opnds[i].text) or ('[%s,' % get_reg_user_name(ea, reg) in opnds[i].text): str_id = ida_struct.get_struc_id(type_name) idc.op_stroff(ea, i, str_id, 0) ida_nalt.set_aflags(ea, ida_nalt.get_aflags(ea) | ida_nalt.AFL_ZSTROFF)
def make_comments(self): """make comments in idb""" EFI_BOOT_SERVICES_ID = idc.get_struc_id("EFI_BOOT_SERVICES") self.get_boot_services() empty = True for service in self.gBServices: for address in self.gBServices[service]: message = f"EFI_BOOT_SERVICES->{service}" idc.set_cmt(address, message, 0) idc.op_stroff(address, 0, EFI_BOOT_SERVICES_ID, 0) empty = False print(f"[ {address:016X} ] {message}") if empty: print(" * list is empty")
def make_comments(self): """make comments in idb""" EFI_BOOT_SERVICES_ID = idc.get_struc_id('EFI_BOOT_SERVICES') self.get_boot_services() empty = True for service in self.gBServices: for address in self.gBServices[service]: message = 'EFI_BOOT_SERVICES->{0}'.format(service) idc.set_cmt(address, message, 0) idc.op_stroff(address, 0, EFI_BOOT_SERVICES_ID, 0) empty = False print('[ {ea} ] {message}'.format( ea='{addr:#010x}'.format(addr=address), message=message)) if empty: print(' * list is empty')
def load(infos): insn = ida_ua.insn_t() for info in infos: # Find or create struct. struct_id = ida_struct.get_struc_id(info['name']) if struct_id == BADADDR: print('[IDA-Sync] Creating new struct %s.' % info['name']) struct_id = ida_struct.add_struc(info['idx'], info['name']) struct = ida_struct.get_struc(struct_id) ida_struct.set_struc_idx(struct, info['idx']) # Create struct members. for member in info['members']: ida_struct.add_struc_member( struct, member['name'], member['offset'], # flag 0, # opinfo_t instance... maybe it should sometimes be # something? None, member['size'], ) # Create xrefs to members of the struct as offsets. for xref in info['xrefs']: typ = xref['type'] # Offset xref. if typ == 1: # TODO figure out what second argument does. idc.op_plain_offset(xref['from'], 1, xref['offset']) # Read/write xrefs. elif typ in [2, 3]: ida_ua.create_insn(xref['from'], insn) idc.op_stroff(insn, 1, struct.id, 0) # TODO do the other cases come up? else: pass
def _update_structs_from_track(track): for item, track in track: for op in item.operands(): if op.type in [o_displ, o_phrase] and op.reg in track and isinstance(track[op.reg], Structure): if track[op.reg].dummy: _guess_struct_field(item, op, track[op.reg]) op_stroff(item.insn, op.n, track[op.reg].sid, 0) for obj, state in copy(track).items(): if isinstance(obj, Pointer) and isinstance(state, Structure): obj.name = underscore_to_global(state.name) obj.type = state.name + " *" track.pop(obj) if isinstance(state, StructureMember): if state.type is not None and is_structure_type(state.type.rstrip(" *")): struc = Structure(state.type.rstrip(" *")) if isinstance(obj, Pointer): obj.name = underscore_to_global(struc.name) obj.type = struc.name + " *" track[obj] = struc
def _insn_op_stroff_695(insn, n, sid, delta): """A wrapper of idc.op_stroff for IDA 6.95.""" return idc.op_stroff(insn.ea, n, sid, delta)
def _insn_op_stroff_700(insn, n, sid, delta): """A wrapper of idc.op_stroff for IDA 7.""" return idc.op_stroff(insn, n, sid, delta)
def get_cur_type(ea, reg): opnds = sark.Line(ea).insn.operands for i in range(len(opnds)): if '[%s]' % get_reg_user_name(ea, reg) in opnds[i].text: str_id = ida_struct.get_struc_id(type_name) idc.op_stroff(ea, i, str_id, 0)
def OpStroff(ea, n, strid): return idc.op_stroff(ea, n, strid, 0)