def list(**type): """List all the structures within the database. Search type can be identified by providing a named argument. like = glob match regex = regular expression index = particular index identifier = particular id number pred = function predicate """ res = __builtin__.list(iterate(**type)) maxindex = max( __builtin__.map( utils.compose(operator.attrgetter('index'), "{:d}".format, len), res) or [1]) maxname = max( __builtin__.map(utils.compose(operator.attrgetter('name'), len), res) or [1]) maxsize = max( __builtin__.map( utils.compose(operator.attrgetter('size'), "{:x}".format, len), res) or [1]) for st in res: print("[{:{:d}d}] {:>{:d}s} {:<+{:d}x} ({:d} members){:s}".format( idaapi.get_struc_idx(st.id), maxindex, st.name, maxname, st.size, maxsize, len(st.members), " // {:s}".format(st.comment) if st.comment else '')) return
def list(**type): """List all the enumerations within the database. Search type can be identified by providing a named argument. like = glob match regex = regular expression index = particular index identifier = particular id number pred = function predicate """ res = __builtin__.list(iterate(**type)) maxindex = max(__builtin__.map(idaapi.get_enum_idx, res)) maxname = max( __builtin__.map(utils.compose(idaapi.get_enum_name, len), res)) maxsize = max(__builtin__.map(size, res)) cindex = math.ceil(math.log(maxindex or 1) / math.log(10)) cmask = max( __builtin__.map( utils.compose(mask, math.log, functools.partial(operator.mul, 1.0 / math.log(16)), math.ceil), res) or [database.config.bits() / 4.0]) for n in res: print("[{:{:d}d}] {:>{:d}s} & {:#<{:d}x} ({:d} members){:s}".format( idaapi.get_enum_idx(n), int(cindex), idaapi.get_enum_name(n), maxname, mask(n), int(cmask), len(__builtin__.list(members(n))), " // {:s}".format(comment(n)) if comment(n) else '')) return
def rebase(info): functions, globals = map(utils.compose(sorted, list), (database.functions(), internal.netnode.alt.fiter(internal.comment.tagging.node()))) p = ui.progress() p.update(current=0, title="Rebasing tagcache...", min=0, max=len(functions)+len(globals)) fcount = gcount = 0 # for each segment p.open() for si in xrange(info.size()): p.update(title="Rebasing segment {:d} of {:d} (+{:x}) : {:x} -> {:x}".format(si, info.size(), info[si].size, info[si]._from, info[si].to)) # for each function (using target address because ida moved the netnodes for us) res = [n for n in functions if info[si].to <= n < info[si].to + info[si].size] for i, fn in __rebase_function(info[si]._from, info[si].to, info[si].size, res): text = "Function {:d} of {:d} : {:x}".format(i + fcount, len(functions), fn) p.update(value=sum((fcount,gcount,i)), text=text) fcount += len(res) # for each global res = [(ea,count) for ea,count in globals if info[si]._from <= ea < info[si]._from + info[si].size] for i, ea in __rebase_globals(info[si]._from, info[si].to, info[si].size, res): time.sleep(0.001) text = "Global {:d} of {:d} : {:x}".format(i + gcount, len(globals), ea) p.update(value=sum((fcount,gcount,i)), text=text) gcount += len(res) p.close()
def list(**type): """List all the segments defined in the database. Search type can be identified by providing a named argument. like = glob match regex = regular expression selector = segment selector index = particular index name = specific segment name predicate = function predicate """ res = __builtin__.list(iterate(**type)) maxindex = max(__builtin__.map(operator.attrgetter('index'), res) or [1]) maxaddr = max(__builtin__.map(operator.attrgetter('endEA'), res) or [1]) maxsize = max(__builtin__.map(operator.methodcaller('size'), res) or [1]) maxname = max(__builtin__.map(utils.compose(idaapi.get_true_segm_name,len), res) or [1]) cindex = math.ceil(math.log(maxindex)/math.log(10)) caddr = math.ceil(math.log(maxaddr)/math.log(16)) csize = math.ceil(math.log(maxsize)/math.log(16)) for seg in res: comment = idaapi.get_segment_cmt(seg, 0) or idaapi.get_segment_cmt(seg, 1) print("[{:{:d}d}] {:0{:d}x}:{:0{:d}x} {:>{:d}s} {:<+#{:d}x} sel:{:04x} flags:{:02x}{:s}".format(seg.index, int(cindex), seg.startEA, int(caddr), seg.endEA, int(caddr), idaapi.get_true_segm_name(seg), maxname, seg.size(), int(csize), seg.sel, seg.flags, "// {:s}".format(comment) if comment else '')) return
def list(self, **type): """List all the members within the structure. Search type can be identified by providing a named argument. like = glob match regex = regular expression index = particular index identifier = particular id number predicate = function predicate """ res = __builtin__.list(self.iterate(**type)) escape = repr maxindex = max( __builtin__.map( utils.compose(operator.attrgetter('index'), "{:d}".format, len), res) or [1]) maxoffset = max( __builtin__.map( utils.compose(operator.attrgetter('offset'), "{:x}".format, len), res) or [1]) maxsize = max( __builtin__.map( utils.compose(operator.attrgetter('size'), "{:x}".format, len), res) or [1]) maxname = max( __builtin__.map( utils.compose(operator.attrgetter('name'), escape, len), res) or [1]) maxtype = max( __builtin__.map( utils.compose(operator.attrgetter('type'), repr, len), res) or [1]) for m in res: print "[{:{:d}d}] {:>{:d}x}:+{:<{:d}x} {:<{:d}s} {:{:d}s} (flag={:x},dt_type={:x}{:s}){:s}".format( m.index, maxindex, m.offset, int(maxoffset), m.size, maxsize, escape(m.name), int(maxname), m.type, int(maxtype), m.flag, m.dt_type, '' if m.typeid is None else ",typeid={:x}".format(m.typeid), " // {:s}".format(m.comment) if m.comment else '') return
def list(cls, enum): # FIXME: make this consistent with every other .list eid = by(enum) res = __builtin__.list(cls.iterate(eid)) maxindex = max(__builtin__.map(utils.first, enumerate(res)) or [1]) maxvalue = max( __builtin__.map(utils.compose(cls.value, "{:x}".format, len), res) or [1]) for i, mid in enumerate(res): print("[{:d}] {:>0{:d}x} {:s}".format(i, cls.value(mid), maxvalue, cls.name(mid))) return
def down(self): '''Return all the structures that are referenced by this specific structure.''' x, sid = idaapi.xrefblk_t(), self.id # grab structures that this one references ok = x.first_from(sid, 0) if not ok: return [] # continue collecting all structures that this one references res = [(x.to, x.iscode, x.type)] while x.next_from(): res.append((x.to, x.iscode, x.type)) # convert refs into a list of OREFs refs = [ interface.OREF(xrto, xriscode, interface.ref_t.of(xrtype)) for xrto, xriscode, xrtype in res ] # return it as a tuple return map(utils.compose(operator.itemgetter(0), instance), refs)