示例#1
0
def get_object_id_of_union_member_id(hash_provider, member_id):
    try:
        return union_member_object_ids[member_id]
    except KeyError:

        idx = idc.GetFirstStrucIdx()
        while idx != idc.BADADDR:
            struc_id = idc.GetStrucId(idx)
            if idc.IsUnion(struc_id):

                offset = idc.GetFirstMember(struc_id)

                while offset != idc.BADADDR:
                    smember_id = idc.GetMemberId(struc_id, offset)
                    if smember_id == member_id:
                        name = idc.GetMemberName(struc_id, offset)
                        if name is not None:
                            struc_name = idc.GetStrucName(struc_id)
                            logger.debug("found member id 0x%016X in union %s/%s" % (member_id, struc_name, name))
                            return hash_provider.get_struc_member_id_for_name(struc_name, offset)

                    # next member
                    offset = idc.GetStrucNextOff(struc_id, offset)
            idx = idc.GetNextStrucIdx(idx)

        logger.error("Could not find member id 0x%016X in unions" % member_id)

        return None
示例#2
0
    def populate_struc_enum_ids(self):
        logger.debug("Populating hash cache with current values")
        # force hash generation of struc and enums (without use_time)
        idx = idc.GetFirstStrucIdx()
        while idx != idc.BADADDR:
            self.get_struc_enum_object_id(idc.GetStrucId(idx), use_time=False)
            idx = idc.GetNextStrucIdx(idx)

        for idx in xrange(0, idc.GetEnumQty()):
            enum_id = idc.GetnEnum(idx)
            self.get_struc_enum_object_id(enum_id, use_time=False)

            enum_name = idc.GetEnumName(enum_id)
            for (const_id, const_value,
                 bmask) in enum_member_iterate_all(enum_id):
                const_name = idc.GetConstName(const_id)
                self.get_enum_member_id(enum_id,
                                        enum_name,
                                        const_id,
                                        const_name,
                                        const_value,
                                        bmask,
                                        use_time=False)

        _yatools_hash_provider.populate_persistent_cache()
示例#3
0
def get_structures():
    """ Populate dictionaries with imported structures infomation"""
    structure_ids = {}
    if idc.GetStrucQty() == 0:
        return None

    index = None
    for i in xrange(0, idc.GetStrucQty()):
        if i == 0:
            index = idc.GetFirstStrucIdx()
        else:
            index = idc.GetNextStrucIdx(index)

        if index == idaapi.BADADDR:
            continue

        sid = idc.GetStrucId(index)
        if sid == idaapi.BADADDR:
            continue

        name = idc.GetStrucName(sid)
        if not name:
            continue

        structure_ids[sid] = name

    return structure_ids
示例#4
0
def Structs():
    """
    Get a list of structures

    @return: List of tuples (idx, sid, name)
    """
    idx = idc.GetFirstStrucIdx()
    while idx != idaapi.BADADDR:
        sid = idc.GetStrucId(idx)
        yield (idx, sid, idc.GetStrucName(sid))
        idx = idc.GetNextStrucIdx(idx)
示例#5
0
def get_struc_id_from_member_if(member_id):
    try:
        return member_struc_ids[member_id]
    except KeyError:

        idx = idc.GetFirstStrucIdx()
        while idx != idc.BADADDR:
            struc_id = idc.GetStrucId(idx)
            if idc.IsUnion(struc_id):
                offset = idc.GetFirstMember(struc_id)

                while offset != idc.BADADDR:
                    smember_id = idc.GetMemberId(struc_id, offset)
                    if smember_id == member_id:
                        member_struc_ids[member_id] = struc_id
                        return struc_id
                    offset = idc.GetStrucNextOff(struc_id, offset)
            idx = idc.GetNextStrucIdx(idx)
        logger.error("Could not find struc id from member id 0x%08X (name=%s)" %
                     (member_id, idaapi.get_struc_name(member_id)))
        return None