def fetch_contents(fn): """Fetch the reference count for the contents of function `fn` in the database. Returns the tuple `(func, address, tags)` where the `address` and `tags` fields are both dictionaries containing the reference count for the addresses and tag names. The field `func` contains the address of the function. """ addr, tags = {}, {} for ea in func.iterate(fn): ui.navigation.auto(ea) # grab both comment types so that we can decode them. after decoding, # then iterate through all of their keys and tally up their counts. repeatable, nonrepeatable = (db.comment(ea, repeatable=item) for item in [True, False]) for items in map(internal.comment.decode, [repeatable, nonrepeatable]): #items.pop('name', None) for name in items: addr[ea] = addr.get(ea, 0) + 1 tags[name] = tags.get(name, 0) + 1 continue continue return func.address(fn), addr, tags
def contents(ea): '''Re-build the cache for the contents of the function `ea`.''' try: func.address(ea) except internal.exceptions.FunctionNotFoundError: return {}, {} # read addresses and tags from contents ui.navigation.auto(ea) logging.debug( u"{:s}.contents({:#x}): Fetching the contents from the function {:#x}." .format('.'.join([__name__]), ea, ea)) f, addr, tags = fetch_contents(ea) # clean out any hidden tag values for k in tags.keys(): if k in {'__tags__', '__address__'}: if f in addr: addr[f] -= 1 if addr[f] == 0: addr.pop(f) if k in tags: tags[k] -= 1 if tags[k] == 0: tags.pop(k) continue # update addresses and tags to contents ui.navigation.set(ea) logging.debug( u"{:s}.contents({:#x}): Updating the name reference cache for the contents of function {:#x}." .format('.'.join([__name__]), ea, ea)) for k, v in tags.items(): internal.comment.contents.set_name(f, k, v) logging.debug( u"{:s}.contents({:#x}): Updating the address reference cache for the contents of function {:#x}." .format('.'.join([__name__]), ea, ea)) for k, v in addr.items(): if not func.within(k): continue internal.comment.contents.set_address(k, v) return addr, tags
def customnames(): '''Iterate through all of the custom names defined in the database and update the cache with their reference counts.''' # FIXME: first delete all the custom names '__name__' tag left, right = db.config.bounds() for ea in db.address.iterate(left, right): ctx = internal.comment.contents if func.within(ea) and func.address(ea) != ea else internal.comment.globals if db.type.has_customname(ea): ctx.inc(ea, '__name__') continue return
def customnames(): '''Iterate through all of the custom names defined in the database and update the cache with their reference counts.''' # FIXME: first delete all the custom names '__name__' tag left, right = db.range() for ea in db.address.iterate(left, right): ctx = internal.comment.globals if not func.within(ea) or func.address(ea) == ea else internal.comment.contents if db.type.has_customname(ea): ctx.inc(ea, '__name__') continue return
def contents(ea): '''Re-build the cache for the contents of the function `ea`.''' try: func.address(ea) except internal.exceptions.FunctionNotFoundError: return {}, {} # read addresses and tags from contents ui.navigation.auto(ea) logging.debug(u"{:s}.contents({:#x}): Fetching the contents from the function {:#x}.".format('.'.join(('custom', __name__)), ea, ea)) f, addr, tags = fetch_contents(ea) # clean out any hidden tag values for k in six.viewkeys(tags): if k in {'__tags__', '__address__'}: if f in addr: addr[f] -= 1 if addr[f] == 0: addr.pop(f) if k in tags: tags[k] -= 1 if tags[k] == 0: tags.pop(k) continue # update addresses and tags to contents ui.navigation.set(ea) logging.debug(u"{:s}.contents({:#x}): Updating the name reference cache for the contents of function {:#x}.".format('.'.join(('custom', __name__)), ea, ea)) for k, v in six.iteritems(tags): internal.comment.contents.set_name(f, k, v) logging.debug(u"{:s}.contents({:#x}): Updating the address reference cache for the contents of function {:#x}.".format('.'.join(('custom', __name__)), ea, ea)) for k, v in six.iteritems(addr): if not func.within(k): continue internal.comment.contents.set_address(k, v) return addr, tags
def fetch_contents(fn): """Fetch the reference count for the contents of function `fn` in the database. Returns the tuple `(func, address, tags)` where the `address` and `tags` fields are both dictionaries containing the reference count for the addresses and tag names. The field `func` contains the address of the function. """ addr, tags = {}, {} for ea in func.iterate(fn): ui.navigation.auto(ea) res = db.tag(ea) #res.pop('name', None) for k, v in six.iteritems(res): addr[ea] = addr.get(ea, 0) + 1 tags[k] = tags.get(k, 0) + 1 continue return func.address(fn), addr, tags