Example #1
0
    def activate(self, ctx):
        hx_view = idaapi.get_widget_vdui(ctx.widget)
        if not self.check(hx_view):
            return

        data = []
        offset = hx_view.item.e.m
        struct_type = idaapi.remove_pointer(hx_view.item.e.x.type)
        ordinal = helper.get_ordinal(struct_type)
        result = struct_xrefs.XrefStorage().get_structure_info(ordinal, offset)
        for xref_info in result:
            data.append([
                idaapi.get_short_name(xref_info.func_ea) + "+" + hex(int(xref_info.offset)),
                xref_info.type,
                xref_info.line
            ])

        field_name = helper.get_member_name(struct_type, offset)
        chooser = forms.MyChoose(
            data,
            "Cross-references to {0}::{1}".format(struct_type.dstr(), field_name),
            [["Function", 20 | idaapi.CHCOL_PLAIN],
             ["Type", 2 | idaapi.CHCOL_PLAIN],
             ["Line", 40 | idaapi.CHCOL_PLAIN]]
        )
        idx = chooser.Show(True)
        if idx == -1:
            return

        xref = result[idx]
        idaapi.open_pseudocode(xref.func_ea + xref.offset, False)
Example #2
0
def choose_til():
    # type: () -> (idaapi.til_t, int, bool)
    """ Creates a list of loaded libraries, asks user to take one of them and returns it with
    information about max ordinal and whether it's local or imported library """
    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)  # type: idaapi.til_t
        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]  # type: idaapi.til_t
        max_ordinal = idaapi.get_ordinal_qty(selected_library)
        if max_ordinal == idaapi.BADORD:
            _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
Example #3
0
def _choose_structure_by_size(size):
    result = type_library.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 type_library.import_type(selected_library, matched_types[selected_type][1])
    return None
    def activate(self, ctx):
        global potential_negatives

        hx_view = idaapi.get_widget_vdui(ctx.widget)
        result = type_library.choose_til()
        if not result:
            return

        selected_library, max_ordinal, is_local_types = result
        lvar_idx = hx_view.item.e.v.idx
        candidate = potential_negatives[lvar_idx]
        structures = candidate.find_containing_structures(selected_library)
        items = list(
            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:
                type_library.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)
Example #5
0
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]