Пример #1
0
    def __process_struct_members(self, st_obj):

        members = []
        for st_member in st_obj.members:
            mem_name = ida_struct.get_member_name(
                st_member.id) or ('unknown_%s' % st_member.id)

            mem_off_start = 0 if st_obj.is_union() else st_member.soff
            mem_off_end = st_member.eoff

            mem_tinfo = ida_typeinf.tinfo_t()
            ida_struct.get_member_tinfo(mem_tinfo, st_member)

            mem_typename = ida_typeinf.print_tinfo('', 0, 0,
                                                   ida_typeinf.PRTYPE_1LINE,
                                                   mem_tinfo, '', '')
            if not mem_typename:
                mem_typename = self.__describe_type_basetype(
                    mem_tinfo.get_realtype())

            members.append({
                'offset': mem_off_start,
                'length': mem_off_end - mem_off_start,
                'type': mem_typename,
                'name': mem_name,
            })

        return members
Пример #2
0
    def member_data(self, member):
        d = {}
        # TODO: variable size bool
        # TODO: retrieve_member_info - get operand type member info
        d['name'] = ida_struct.get_member_name(member.id)
        d['size'] = ida_struct.get_member_size(member)
        d['flag'] = member.flag
        d['offset'] = member.soff
        d['comment'] = ida_struct.get_member_cmt(member.id, False)
        d['repeatable_comment'] = ida_struct.get_member_cmt(member.id, True)

        if member.has_ti():
            tinfo = ida_typeinf.tinfo_t()
            ida_struct.get_member_tinfo(tinfo, member)
            d['type_info_serialize'] = tinfo.serialize()
            d['type_info'] = str(tinfo)

        oi = ida_nalt.opinfo_t()
        ida_struct.retrieve_member_info(oi, member)
        # TODO: Do things with OI

        sptr = ida_struct.get_sptr(member)
        if sptr:
            struct_name = ida_struct.get_struc_name(sptr.id)
            d['struct_name'] = struct_name
            d['struct_uuid'] = StructureAnnotation.depend(self, struct_name)
        return d
Пример #3
0
def post_struct_member_type_change(member):
    xrefs = idautils.XrefsFrom(member.id)
    xrefs = filter(lambda x: x.type == ida_xref.dr_I and x.user == 1, xrefs)
    for xref in xrefs:
        if utils.is_func(xref.to):
            function_ptr_tinfo = idaapi.tinfo_t()
            ida_struct.get_member_tinfo(function_ptr_tinfo, member)
            if function_ptr_tinfo.is_funcptr():
                function_tinfo = function_ptr_tinfo.get_pointed_object()
                if function_tinfo is not None:
                    ida_typeinf.apply_tinfo(
                        xref.to, function_tinfo, idaapi.TINFO_DEFINITE
                    )
Пример #4
0
def get_member_tinfo(mptr):
    if not mptr:
        return None
    member_tif = idaapi.tinfo_t()
    if not ida_struct.get_member_tinfo(member_tif, mptr):
        return None
    return member_tif
Пример #5
0
 def data_type_size(self) -> int:
     """The data type size, defaults to 1 if unknown"""
     if self.is_stack:
         tif = ida_typeinf.tinfo_t()
         success = ida_struct.get_member_tinfo(tif, self._member)
         if not success:
             # Sometimes IDA will fail to get member type information for unknown reasons.
             # In these cases, set the type size ourselves if it is obvious or default to 1.
             return self.SIZE_MAP.get(self._data_type_enum, 1)
         return tif.get_size()
     else:
         return ida_bytes.get_data_elsize(self.addr, self._data_type_enum)
Пример #6
0
 def get_ownertype(self):
     tif = ida_typeinf.tinfo_t()
     success = ida_struct.get_member_tinfo(tif, self.mem)
     # if type information is available in Ida analysis
     if success:
         if ida_typeinf.is_type_ptr_or_array(tif.get_realtype()) or self.get_size()>=8:
             return "pointer"
         else:
             return "scalar"
     # return type scalar by default
     else:
         if self.get_size()>=8:
             return "pointer"
         else:
             return "scalar"
Пример #7
0
def get_member_type(struct, idx):
    """
    Retrieve the type information for the struct member

    :return: Type string
    """

    member = ida_struct.get_member(struct, idx)
    tif = idaapi.tinfo_t()
    ida_struct.get_member_tinfo(tif, member)
    elements = str(tif).split(' ')
    typ = None
    if len(elements) == 2 and elements[0] == 'unsigned':
        if elements[1] == '__int8':
            typ = 'uint8_t'
        elif elements[1] == '__int16':
            typ = 'uint16_t'
        elif elements[1] == '__int32':
            typ = 'uint32_t'
        elif elements[1] == '__int64':
            typ = 'uint64_t'
        elif elements[1] != '':
            typ = elements[1]
    elif len(elements) == 1:
        if elements[0] == '__int8':
            typ = 'int8_t'
        elif elements[0] == '__int16':
            typ = 'int16_t'
        elif elements[0] == '__int32':
            typ = 'int32_t'
        elif elements[0] == '__int64':
            typ = 'int64_t'
        elif elements[0] != '':
            typ = str(tif)

    return typ
Пример #8
0
 def is_array_type(self):
     tif = ida_typeinf.tinfo_t()
     success = ida_struct.get_member_tinfo(tif, self.mem)
     return ida_typeinf.is_type_array(tif.get_realtype())
Пример #9
0
 def get_type(self):
     tif = ida_typeinf.tinfo_t()
     success = ida_struct.get_member_tinfo(tif, self.mem)
     return tif.get_realtype()
Пример #10
0
def get_member_tinfo(member, member_typeinf=None):
    if member_typeinf is None:
        member_typeinf = idaapi.tinfo_t()
    ida_struct.get_member_tinfo(member_typeinf, member)
    return member_typeinf