def list(*args, **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 """ # FIXME: refactor this implementation into a utility module # so that this can be reused elsewhere if len(args) == 1: type['like'] = args[0] if 'regex' in type: match = lambda x: re.search(type['regex'], x.name) elif 'index' in type: match = lambda x: idaapi.get_struc_idx(x.id) == type['index'] elif 'identifer' in type: match = lambda x: x.id == type['identifier'] elif 'like' in type: match = lambda x: fnmatch.fnmatch(x.name, type['like']) elif 'pred' in type: match = type['pred'] else: match = bool for st in itertools.ifilter(match, iterate()): print '[%d] %s +%x (%d members)%s' % (idaapi.get_struc_idx( st.id), st.name, st.size, len( st.members), st.comment and ' // %s' % st.comment or '') return
def by(**type): """Search through all the structures within the database and return the first result. like = glob match regex = regular expression index = particular index identifier or id = internal id number """ searchstring = ', '.join("{:s}={!r}".format(k, v) for k, v in type.iteritems()) res = __builtin__.list(iterate(**type)) if len(res) > 1: map(logging.info, (("[{:d}] {:s}".format(idaapi.get_struc_idx(st.id), st.name)) for i, st in enumerate(res))) logging.warn( "{:s}.search({:s}) : Found {:d} matching results, returning the first one. : {!r}" .format(__name__, searchstring, len(res), res[0])) res = next(iter(res), None) if res is None: raise LookupError( "{:s}.search({:s}) : Found 0 matching results.".format( __name__, searchstring)) return res
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 search(*args, **type): """Search through all the structures within the database and return the first result. Search type can be identified by providing a named argument. like = glob match regex = regular expression index = particular index identifier = particular id number """ try: if len(args) == 1: type['like'] = args[0] if type: if 'regex' in type: match = lambda x: re.search(type['regex'], x.name) elif 'index' in type: match = lambda x: idaapi.get_struc_idx(x.id) == type['index'] elif 'identifer' in type: match = lambda x: x.id == type['identifier'] elif 'like' in type: match = lambda x: fnmatch.fnmatch(x.name, type['like']) elif 'pred' in type: match = type['pred'] else: raise LookupError except: raise LookupError, 'Unable to determine search type : %r' % (args or type) res = filter(match, iterate()) if len(res) > 1: logging.warn( 'structure.search(%s) : Found %d results, returning the first one.' % (args and 'match' or type.iterkeys().next(), len(res))) fn = lambda x: sys.stdout.write(x + "\n") map(logging.info, (('[%d] %s' % (idaapi.get_struc_idx(x.id), x.name)) for i, x in enumerate(res))) return itertools.ifilter(match, iterate()).next()
def list(self, *args, **type): # FIXME: refactor this implementation into a utility module # so that this can be reused elsewhere if len(args) == 1: type['like'] = args[0] if 'regex' in type: match = lambda x: re.search(type['regex'], x.name) elif 'index' in type: match = lambda x: idaapi.get_struc_idx(x.id) == type['index'] elif 'identifer' in type: match = lambda x: x.id == type['identifier'] elif 'like' in type: match = lambda x: fnmatch.fnmatch(x.name, type['like']) elif 'pred' in type: match = type['pred'] else: match = bool for x in itertools.ifilter(match, self): print '[%d] %s %x:+%x %r(%x,%x%s)%s' % ( x.index, x.name, x.offset, x.size, x.type, x.flag, x.dt_type, '' if x.typeid is None else ', %x' % x.typeid, x.comment and ' // %s' % x.comment or '') return
def index(self): return idaapi.get_struc_idx(self.id)
def index(id, index=None): """set/get the index of a particular structure""" if index is None: return idaapi.get_struc_idx(id) return idaapi.set_struc_idx(id, index)
def index(id): '''Return the index for the structure identified by ``id``.''' return idaapi.get_struc_idx(id)
def index(self): '''Return the index of the structure.''' return idaapi.get_struc_idx(self.id)