예제 #1
0
 def __call__(self):
     sptr = idaapi.get_struc(idc.get_struc_id(self.sname.encode('utf-8')))
     if self.smname:
         mptr = idaapi.get_member_by_name(sptr, self.smname.encode('utf-8'))
         idaapi.set_member_cmt(mptr,
                               self.cmt.encode('utf-8') if self.cmt else '',
                               self.repeatable_cmt)
     else:
         idaapi.set_struc_cmt(sptr.id,
                              self.cmt.encode('utf-8') if self.cmt else '',
                              self.repeatable_cmt)
예제 #2
0
 def __setstate__(self, state):
     name, (cmtt, cmtf), members = state
     identifier = idaapi.get_struc_id(name)
     if identifier == idaapi.BADADDR:
         logging.warn('Creating structure %s [%d fields]%s' %
                      (name, len(members), ' // %s' %
                       (cmtf or cmtt) if cmtf or cmtt else ''))
         identifier = idaapi.add_struc(idaapi.BADADDR, name)
     # FIXME: although set_struc_idx and stuff doesn't seem too important.
     idaapi.set_struc_cmt(identifier, cmtt, True)
     idaapi.set_struc_cmt(identifier, cmtf, False)
     self.__id = identifier
     self.__members = members
     return
예제 #3
0
 def __setstate__(self, state):
     name, (cmtt, cmtf), members = state
     identifier = idaapi.get_struc_id(name)
     if identifier == idaapi.BADADDR:
         logging.warn(
             "{:s}.structure_t.__setstate__ : Creating structure {:s} [{:d} fields]{:s}"
             .format(
                 __name__, name, len(members),
                 " // {:s}".format(cmtf or cmtt) if cmtf or cmtt else ''))
         identifier = idaapi.add_struc(idaapi.BADADDR, name)
     idaapi.set_struc_cmt(identifier, cmtt, True)
     idaapi.set_struc_cmt(identifier, cmtf, False)
     self.__id = identifier
     self.__members = members
     return
예제 #4
0
    def build_struct(self):
        ''' Creates an IDA structure for this Type.
        '''
        if self.struct is not None:
            return

        for p in self.parents:
            p.build_struct()

        self.struct = idc.AddStrucEx(-1, self.name, 0)

        if as_signed(self.struct, TARGET_ADDRESS_SIZE) == -1:
            raise RuntimeError("Unable to make struct `{}`".format(self.name))
        else:
            #TODO: either come up with another way of showing this, or
            #      sync it with the actual function names
            cmt = "constructors: "
            for c in self.constructors():
                cmt += "{}(0x{:02x}), ".format(idc.Name(c), c)
            cmt = cmt.strip(", ")
            idaapi.set_struc_cmt(self.struct, cmt, False)

        if TARGET_ADDRESS_SIZE == 8:
            mask = idc.FF_QWRD
        else:
            mask = idc.FF_DWRD

        # Only bases get the magic _vptr member
        if len(self.parents) == 0:
            idc.AddStrucMember(self.struct, "_vptr", 0, idc.FF_DATA | mask, -1,
                               TARGET_ADDRESS_SIZE)
            idc.SetType(idc.GetMemberId(self.struct, 0), "_vfunc**")

        for i, parent in enumerate(self.parents):
            try:
                #TODO: for non-itanium ABI, this may not be available
                #      when RTTI is disabled
                offset = self.tablegroup.tables[i].offset_to_top
            except:
                break

            idc.AddStrucMember(self.struct, "parent_{}".format(i),
                               -offset, idc.FF_DATA, -1,
                               idc.GetStrucSize(parent.struct))

            idc.SetType(idc.GetMemberId(self.struct, -offset), parent.name)
예제 #5
0
def handle_structs(delta, segs):
    for idx in range(idaapi.get_struc_qty()):
        tid = idaapi.get_struc_by_idx(idx)
        for cmt_type in (True, False):
            cmt = idaapi.get_struc_cmt(tid, cmt_type)
            if cmt:
                new_cmt = rebase_comment(segs, delta, cmt)
                if new_cmt:
                    idaapi.set_struc_cmt(tid, new_cmt, cmt_type)
        s = idaapi.get_struc(tid)
        for midx in range(s.memqty):
            m = s.get_member(midx)
            for cmt_type in (True, False):
                cmt = idaapi.get_member_cmt(m.id, cmt_type)
                if cmt:
                    new_cmt = rebase_comment(segs, delta, cmt)
                    if new_cmt:
                        idaapi.set_member_cmt(m, new_cmt, cmt_type)
예제 #6
0
 def comment(self, comment):
     return idaapi.set_struc_cmt(self.id, comment, True)
예제 #7
0
 def comment(self, comment):
     return idaapi.set_struc_cmt(self.id, comment, True)
예제 #8
0
 def __call__(self):
     idaapi.set_struc_cmt(self.tid, self.cmt.encode('utf-8'),
                          self.repeatable_cmt)
예제 #9
0
def comment(id, cmt=None, repeatable=1):
    """set/get the comment of a particular structure"""
    if cmt is None:
        return idaapi.get_struc_cmt(id, repeatable)
    return idaapi.set_struc_cmt(id, cmt, repeatable)
예제 #10
0
def comment(id=six.integer_types, cmt=basestring, **repeatable):
    """Set the comment for the structure identified by ``id`` to ``cmt``.
    If the bool ``repeatable`` is specified, set the repeatable comment.
    """
    return idaapi.set_struc_cmt(id, cmt, repeatable.get('repeatable', True))
예제 #11
0
 def comment(self, comment, repeatable=True):
     '''Set the repeatable comment for the structure to ``comment``.'''
     return idaapi.set_struc_cmt(self.id, comment, repeatable)
예제 #12
0
 def __call__(self):
     idaapi.set_struc_cmt(self.tid, self.cmt, self.repeatable_cmt)