def by_fullname(self, fullname): '''Return the member with the specified ``fullname``.''' mem = idaapi.get_member_by_fullname(self.owner.ptr, str(fullname)) if mem is None: raise KeyError( "{:s}.instance({:s}).members.by_fullname : Unable to find member with full name : {!r}" .format(__name__, self.owner.name, fullname)) index = self.index(mem) return self[index]
class Member(IdaObj): _get = staticmethod(idaapi.get_member_by_id) _from = staticmethod(lambda x: idaapi.get_member_by_fullname(x).id) @property def name(self): return idaapi.get_member_fullname(self.id) @property def type(self): self.ti = idaapi.tinfo_t() if not idaapi.get_member_tinfo(self.ti, self.member): print "[-] can't get member `%s` type" % self.name return return Type(self.ti)
def update_idb(self): sid = ida_struct.get_struc_id(self._name) if sid != -1: sptr = ida_struct.get_struc(sid) ida_struct.del_struc(sptr) sid = ida_struct.add_struc(idc.BADADDR, self._name, 0) sptr = ida_struct.get_struc(sid) for f in self._fields: ida_struct.add_struc_member(sptr, f.name, idc.BADADDR, (idc.FF_BYTE | idc.FF_DATA) & 0xFFFFFFFF, None, 1) member_name = "{}.{}".format(self._name, f.name) idc.SetType( idaapi.get_member_by_fullname(member_name)[0].id, f.type) ida_auto.auto_wait()
def update_idb(self, delete_existing_members=True): sid = ida_struct.get_struc_id(self._name) sptr = ida_struct.get_struc(sid) if sid == idc.BADADDR: sid = ida_struct.add_struc(idc.BADADDR, self._name, 0) sptr = ida_struct.get_struc(sid) else: if delete_existing_members: ida_struct.del_struc_members(sptr, 0, 0xffffffff) for f in self._fields: ida_struct.add_struc_member(sptr, f.name, f.offset, (idc.FF_BYTE | idc.FF_DATA) & 0xFFFFFFFF, None, 1) member_name = "{}.{}".format(self._name, f.name) idc.SetType( idaapi.get_member_by_fullname(member_name)[0].id, f.type) ida_auto.auto_wait()
def byfullname(self, fullname): index = idaapi.get_member_by_fullname(self.owner.ptr, fullname) return self[index]
def byFullname(self, fullname): mem = idaapi.get_member_by_fullname(self.owner.ptr, str(fullname)) if mem is None: raise KeyError, fullname index = self.index(mem) return self[index]
def refs(self): """Return the (address, opnum, type) of all the references (code & data) to this structure within the database. If `opnum` is None, then the `address` has the structure applied to it. If `opnum` is defined, then the instruction at `address` references a field that is the specified structure. """ x, sid = idaapi.xrefblk_t(), self.id # grab first reference to structure ok = x.first_to(sid, 0) if not ok: return [] # collect rest of it's references refs = [(x.frm, x.iscode, x.type)] while x.next_to(): refs.append((x.frm, x.iscode, x.type)) # calculate the high-byte which is used to differentiate an address from a structure bits = math.trunc(math.ceil(math.log(idaapi.BADADDR) / math.log(2.0))) highbyte = 0xff << (bits - 8) # iterate through figuring out if sid is applied to an address or another structure res = [] for ref, _, _ in refs: # structure (probably a frame member) if ref & highbyte == highbyte: # get sptr, mptr name = idaapi.get_member_fullname(ref) mptr, _ = idaapi.get_member_by_fullname(name) if not isinstance(mptr, idaapi.member_t): cls = self.__class__ raise TypeError( "{:s} : Unexpected type {!r} for netnode '{:s}'". format('.'.join((__name__, cls.__name__)), mptr.__class__, name)) sptr = idaapi.get_sptr(mptr) # get frame, func_t frname, _ = name.split('.', 2) frid = internal.netnode.get(frname) ea = idaapi.get_func_by_frame(frid) f = idaapi.get_func(ea) # now find all xrefs to member within function xl = idaapi.xreflist_t() idaapi.build_stkvar_xrefs(xl, f, mptr) # now we can add it for xr in xl: ea, opnum, state = xr.ea, int( xr.opnum), instruction.op_state(ea, opnum) res.append( interface.OREF(ea, opnum, interface.ref_t.of_state(state))) continue # address res.append(interface.OREF(ref, None, interface.ref_t.of_state( '*'))) # using '*' to describe being applied to the an address return res