Example #1
0
    def data(self):
        # if idx is None this is called for the pre-apply data identity validation
        # we'll return None so data will definitely not match
        if self.idx is None:
            return None

        struc_id = ida_struct.get_struc_by_idx(self.idx)
        struct = ida_struct.get_struc(struc_id)

        # Skip TIL structures
        if struct.from_til():
            return None

        # Skip empty structures
        if not struct.memqty:
            return None

        d = {}
        d['name'] = ida_struct.get_struc_name(struc_id)
        d['comment'] = ida_struct.get_struc_cmt(struc_id, False)
        d['repeatable_comment'] = ida_struct.get_struc_cmt(struc_id, False)
        d['size'] = ida_struct.get_struc_size(struct)
        d['union'] = ida_struct.is_union(struc_id)
        # TODO: struct alignment, hidden, listed

        d['members'] = {}
        member_idx = 0
        while member_idx != idaapi.BADADDR:
            member = struct.get_member(member_idx)
            d['members'][member_idx] = self.member_data(member)
            member_idx = ida_struct.get_next_member_idx(struct, member.soff)
            # TODO: FIX issue with looping over members
            member_idx = idaapi.BADADDR

        return d
Example #2
0
    def __process_structs(self):
        structs = []

        st_idx = ida_struct.get_first_struc_idx()
        while st_idx != ida_idaapi.BADADDR:

            st_id = ida_struct.get_struc_by_idx(st_idx)
            st_obj = ida_struct.get_struc(st_id)

            st_name = ida_struct.get_struc_name(st_id)

            structs.append({
                'type': self.__describe_struct_type(st_obj.props),
                'name': st_name,
                'size': int(ida_struct.get_struc_size(st_obj)),
                'members': self.__process_struct_members(st_obj)
            })

            st_idx = ida_struct.get_next_struc_idx(st_idx)

        return structs
Example #3
0
 def view_dblclick(self, viewer, point):
     widget_type = ida_kernwin.get_widget_type(viewer)
     if not (widget_type == 48 or widget_type == 28):
         return
     # Decompiler or Structures window
     func_cand_name = None
     place, x, y = ida_kernwin.get_custom_viewer_place(viewer, False)
     if place.name() == "structplace_t":  # Structure window:
         structplace = ida_kernwin.place_t_as_structplace_t(place)
         if structplace is not None:
             s = ida_struct.get_struc(ida_struct.get_struc_by_idx(structplace.idx))
             if s:
                 member = ida_struct.get_member(s, structplace.offset)
                 if member:
                     func_cand_name = ida_struct.get_member_name(member.id)
     if func_cand_name is None:
         line = utils.get_curline_striped_from_viewer(viewer)
         func_cand_name = cpp_utils.find_valid_cppname_in_line(line, x)
     if func_cand_name is not None:
         func_cand_ea = ida_name.get_name_ea(BADADDR, func_cand_name)
         if func_cand_ea is not None and utils.is_func_start(func_cand_ea):
             idc.jumpto(func_cand_ea)
Example #4
0
 def dependency_name(self):
     struc_id = ida_struct.get_struc_by_idx(self.idx)
     return ida_struct.get_struc_name(struc_id)
Example #5
0
# https://github.com/csnover/ida-misc
#
# Sorts all the structs in a database in case-insensitive alphabetical order.

import ida_struct
from idaapi import BADADDR

structs = []

idx = ida_struct.get_first_struc_idx()
while idx != BADADDR:
    id = ida_struct.get_struc_by_idx(idx)
    name = ida_struct.get_struc_name(id)
    structs.append((name, ida_struct.get_struc(id)))
    idx = ida_struct.get_next_struc_idx(idx)

structs.sort(key=lambda t: t[0].lower())

for i, t in enumerate(structs):
    ida_struct.set_struc_idx(t[1], i)