Exemplo n.º 1
0
def load_kmdf_types_into_idb():
    header_path = idautils.GetIdbDir()
    # change relative path to use more easily
    idaapi.idc_parse_types("".join([header_path, "../Tools/kmdf_re/code/WDFStructsV2.h"]), idc.PT_FILE)
    for idx in range(1, idc.GetMaxLocalType()):
        print(idx, idc.GetLocalTypeName(idx))
        idc.Til2Idb(idx, idc.GetLocalTypeName(idx))
Exemplo n.º 2
0
    def initialize_nodes(self):
        for ordinal in xrange(1, idc.GetMaxLocalType()):
            # if ordinal == 15:
            #     import pydevd
            #     pydevd.settrace("localhost", port=12345, stdoutToServer=True, stderrToServer=True)

            local_tinfo = StructureGraph.get_tinfo_by_ordinal(ordinal)
            if not local_tinfo:
                continue
            name = idc.GetLocalTypeName(ordinal)

            if local_tinfo.is_typeref():
                typeref_ordinal = local_tinfo.get_ordinal()
                members_ordinals = []
                if typeref_ordinal:
                    typeref_tinfo = StructureGraph.get_tinfo_by_ordinal(
                        typeref_ordinal)
                    if typeref_tinfo.is_typeref() or typeref_tinfo.is_udt(
                    ) or typeref_tinfo.is_ptr():
                        members_ordinals = [typeref_ordinal]
                cdecl_typedef = idaapi.print_tinfo(None, 4, 5, 0x3,
                                                   local_tinfo, None, None)
                self.local_types[ordinal] = LocalType(name,
                                                      members_ordinals,
                                                      cdecl_typedef,
                                                      is_typedef=True)
            elif local_tinfo.is_udt():
                # udt_data = idaapi.udt_type_data_t()
                # local_tinfo.get_udt_details(udt_data)
                members_ordinals = StructureGraph.get_members_ordinals(
                    local_tinfo)
                cdecl_typedef = idaapi.print_tinfo(None, 4, 5, 0x1,
                                                   local_tinfo, None, None)
                self.local_types[ordinal] = LocalType(
                    name,
                    members_ordinals,
                    cdecl_typedef,
                    is_union=local_tinfo.is_union())
            elif local_tinfo.is_ptr():
                typeref_ordinal = StructureGraph.get_ordinal(local_tinfo)
                members_ordinals = [typeref_ordinal] if typeref_ordinal else []
                cdecl_typedef = idaapi.print_tinfo(None, 4, 5, 0x2,
                                                   local_tinfo, None, None)
                self.local_types[ordinal] = LocalType(name,
                                                      members_ordinals,
                                                      cdecl_typedef + ' *',
                                                      is_typedef=True)
            elif local_tinfo.is_enum():
                cdecl_typedef = idaapi.print_tinfo(None, 4, 5, 0x21,
                                                   local_tinfo, None, None)
                self.local_types[ordinal] = LocalType(name, [],
                                                      cdecl_typedef,
                                                      is_enum=True)

        self.ordinal_list = set(self.ordinal_list).intersection(
            self.local_types)
        for ordinal in self.ordinal_list:
            self.local_types[ordinal].is_selected = True
Exemplo n.º 3
0
def get_type_from_name(name):
    target_idx = 0
    for idx in range(1, idc.GetMaxLocalType()):
        if name in idc.GetLocalTypeName(idx):
            target_idx = idx
            break
    if target_idx != 0:
        return idc.GetLocalType(target_idx, 0)
    return None
Exemplo n.º 4
0
def load_til(path_to_til):
    if not ida_typeinf.load_til(path_to_til, os.path.dirname(path_to_til)):
        raise Exception("load_til('%s') has failed" % (path_to_til))

    # Fix UINTN to be the actual word size if we can determine it
    idc.Til2Idb(-1, "UINTN")
    entry = idc.GetEntryPoint(idc.GetEntryOrdinal(0))
    if entry != idc.BADADDR:
        typedef = "typedef UINT" + str(16 << idc.GetSegmentAttr(entry, idc.SEGATTR_BITNESS)) + " UINTN;"
        for i in range(0, idc.GetMaxLocalType()):
            if idc.GetLocalTypeName(i) == "UINTN":
                idc.SetLocalType(idc.SetLocalType(i, "", 0), typedef, 0)
Exemplo n.º 5
0
    def __get_local_types(self):
        for id_ida in range(1, idc.GetMaxLocalType()):
            name = idc.GetLocalTypeName(id_ida)
            sizeType = 0
            sid = idc.GetStrucIdByName(name)
            if sid != -1:
                sizeType = idc.GetStrucSize(sid)

            one_line = idc.GetLocalType(id_ida, idc.PRTYPE_1LINE)
            multi_line = idc.GetLocalType(
                id_ida, idc.PRTYPE_MULTI | idc.PRTYPE_TYPE | idc.PRTYPE_PRAGMA)

            yield models_ida.IdaRawLocalType(id_ida=id_ida,
                                             sizeType=sizeType,
                                             name=name,
                                             one_line=one_line,
                                             multi_line=multi_line)
Exemplo n.º 6
0
def get_local_type_idx(name):
    for idx in range(1, idc.GetMaxLocalType()):
        if name in idc.GetLocalTypeName(idx):
            return idx
    return None
Exemplo n.º 7
0
def get_struct_idx(name):
    for idx in range(1, idc.GetMaxLocalType()):
        if name == idc.GetLocalTypeName(idx):
            return idx
    return None
Exemplo n.º 8
0
def load_kmdf_types_into_idb():
    header_path = idautils.GetIdbDir()
    idaapi.idc_parse_types("".join([header_path, "WDFStructs.h"]), idc.PT_FILE)
    for idx in range(1, idc.GetMaxLocalType()):
        print(idx, idc.GetLocalTypeName(idx))
        idc.Til2Idb(idx, idc.GetLocalTypeName(idx))