Пример #1
0
    def near_offset(self, offset):
        '''Return the member near to the specified ``offset``.'''
        min, max = map(lambda sz: sz + self.baseoffset,
                       (idaapi.get_struc_first_offset(self.owner.ptr),
                        idaapi.get_struc_last_offset(self.owner.ptr)))
        if (offset < min) or (offset >= max):
            logging.warn(
                "{:s}.instance({:s}).members.near_offset : Requested offset {:+#x} not within bounds ({:#x},{:#x}). Trying anyways.."
                .format(__name__, self.owner.name, offset, min, max))

        res = offset - self.baseoffset
        mem = idaapi.get_member(self.owner.ptr, res)
        if mem is None:
            logging.info(
                "{:s}.instance({:s}).members.near_offset : Unable to locate member at offset {:+#x}. Trying get_best_fit_member instead."
                .format(__name__, self.owner.name, res))
            mem = idaapi.get_best_fit_member(self.owner.ptr, res)

        if mem is None:
            raise LookupError(
                "{:s}.instance({:s}).members.near_offset : Unable to find member near offset : {:+#x}"
                .format(__name__, self.owner.name, offset))

        index = self.index(mem)
        return self[index]
Пример #2
0
def loadMembersIDA7(struc, sid):
    '''Returns list of tuples of (offset, memberName, member)'''
    #mixing idc & idaapi, kinda annoying but need low-level idaapi for a
    # type access, but cant dig into structs...
    members = []
    off = idaapi.get_struc_first_offset(struc)
    while off != idc.BADADDR:
        logger.debug('struc offset: 0x%x (%d)', off, off)
        member = idaapi.get_member(struc, off)
        if (member == 0) or (member is None):
            pass  #not really an error, i guess
        else:
            members.append((off, idc.get_member_name(sid, off), member))
        off = idaapi.get_struc_next_offset(struc, off)
    members.sort(key=lambda mem: mem[0])
    return members
Пример #3
0
def loadMembersIDA7(struc, sid):
    '''Returns list of tuples of (offset, memberName, member)'''
    #mixing idc & idaapi, kinda annoying but need low-level idaapi for a 
    # type access, but cant dig into structs...
    members = []
    off = idaapi.get_struc_first_offset(struc) 
    while off != idc.BADADDR:
        logger.debug('struc offset: 0x%x (%d)', off, off)
        member = idaapi.get_member(struc, off)
        if (member == 0) or (member is None):
            pass    #not really an error, i guess
        else:
            members.append( (off, idc.get_member_name(sid, off), member) )
        off = idaapi.get_struc_next_offset(struc, off )
    members.sort(key = lambda mem: mem[0])
    return members
Пример #4
0
    def byOffset(self, offset):
        min, max = map(lambda sz: sz - self.baseoffset,
                       (idaapi.get_struc_first_offset(self.owner.ptr),
                        idaapi.get_struc_last_offset(self.owner.ptr)))
        if (offset < min) or (offset >= max):
            logging.warn(
                'structure_t(%s).members.byoffset : Requested offset %x not within bounds (%x,%x). Trying anyways..'
                % (self.owner.name, offset, min, max))

        mem = idaapi.get_member(self.owner.ptr, offset - self.baseoffset)
        if mem is None:
            logging.warn(
                'structure_t(%s).members.byoffset : Unable to locate member at offset %x. Trying get_best_fit_member instead.'
                % (self.owner.name, offset - self.baseoffset))
            mem = idaapi.get_best_fit_member(self.owner.ptr,
                                             offset - self.baseoffset)
        if mem is None:
            raise IndexError, offset
        index = self.index(mem)
        return self[index]
Пример #5
0
    def by_offset(self, offset):
        '''Return the member at the specified ``offset``.'''
        min, max = map(lambda sz: sz + self.baseoffset,
                       (idaapi.get_struc_first_offset(self.owner.ptr),
                        idaapi.get_struc_last_offset(self.owner.ptr)))

        mptr = idaapi.get_member(self.owner.ptr, max - self.baseoffset)
        msize = idaapi.get_member_size(mptr)
        if (offset < min) or (offset >= max + msize):
            raise LookupError(
                "{:s}.instance({:s}).members.by_offset : Requested offset {:+#x} not within bounds ({:#x},{:#x})"
                .format(__name__, self.owner.name, offset, min, max + msize))

        mem = idaapi.get_member(self.owner.ptr, offset - self.baseoffset)
        if mem is None:
            raise LookupError(
                "{:s}.instance({:s}).members.by_offset : Unable to find member at offset : {:+#x}"
                .format(__name__, self.owner.name, offset))

        index = self.index(mem)
        return self[index]