def activate(self, ctx): hx_view = idaapi.get_tform_vdui(ctx.form) result = TypeLibrary.choose_til() if result: selected_library, max_ordinal, is_local_types = result lvar_idx = hx_view.item.e.v.idx candidate = self.potential_negative[lvar_idx] structures = candidate.find_containing_structures(selected_library) items = map( lambda x: [str(x[0]), "0x{0:08X}".format(x[1]), x[2], x[3]], structures) structure_chooser = Forms.MyChoose( items, "Select Containing Structure", [["Ordinal", 5], ["Offset", 10], ["Member_name", 20], ["Structure Name", 20]], 165) selected_idx = structure_chooser.Show(modal=True) if selected_idx != -1: if not is_local_types: TypeLibrary.import_type(selected_library, items[selected_idx][3]) lvar = hx_view.cfunc.get_lvars()[lvar_idx] lvar_cmt = re.sub("```.*```", '', lvar.cmt) hx_view.set_lvar_cmt( lvar, lvar_cmt + "```{0}+{1}```".format(structures[selected_idx][3], structures[selected_idx][1])) hx_view.refresh_view(True)
def select_structure_by_size(size): result = TypeLibrary.choose_til() if result: selected_library, max_ordinal, is_local_type = result matched_types = [] tinfo = idaapi.tinfo_t() for ordinal in xrange(1, max_ordinal): tinfo.create_typedef(selected_library, ordinal) if tinfo.get_size() == size: name = tinfo.dstr() description = idaapi.print_tinfo(None, 0, 0, idaapi.PRTYPE_DEF, tinfo, None, None) matched_types.append([str(ordinal), name, description]) type_chooser = Forms.MyChoose( matched_types, "Select Type", [["Ordinal", 5 | idaapi.Choose2.CHCOL_HEX], ["Type Name", 25], ["Declaration", 50]], 165) selected_type = type_chooser.Show(True) if selected_type != -1: if is_local_type: return int(matched_types[selected_type][0]) return TypeLibrary.import_type(selected_library, matched_types[selected_type][1]) return None
def choose_virtual_func_address(name, tinfo=None, offset=None): addresses = get_virtual_func_addresses(name, tinfo, offset) if not addresses: return if len(addresses) == 1: return addresses[0] chooser = Forms.MyChoose( [[to_hex(ea), idc.Demangle(idc.get_name(ea), idc.INF_LONG_DN)] for ea in addresses], "Select Function", [["Address", 10], ["Full name", 50]] ) idx = chooser.Show(modal=True) if idx != -1: return addresses[idx]
def choose_til(): idati = idaapi.cvar.idati list_type_library = [(idati, idati.name, idati.desc)] for idx in xrange(idaapi.cvar.idati.nbases): type_library = idaapi.cvar.idati.base(idx) # idaapi.til_t type list_type_library.append((type_library, type_library.name, type_library.desc)) library_chooser = Forms.MyChoose( list(map(lambda x: [x[1], x[2]], list_type_library)), "Select Library", [["Library", 10 | idaapi.Choose2.CHCOL_PLAIN], ["Description", 30 | idaapi.Choose2.CHCOL_PLAIN]], 69 ) library_num = library_chooser.Show(True) if library_num != -1: selected_library = list_type_library[library_num][0] max_ordinal = idaapi.get_ordinal_qty(selected_library) if max_ordinal == idaapi.BADORD: TypeLibrary.enable_library_ordinals(library_num - 1) max_ordinal = idaapi.get_ordinal_qty(selected_library) print "[DEBUG] Maximal ordinal of lib {0} = {1}".format(selected_library.name, max_ordinal) return selected_library, max_ordinal, library_num == 0 return None