def content(cls, F, *tags, **location): '''Iterate through the specified `tags` belonging to the contents of the function at `ea` using the cache.''' identity = lambda res: res translate = addressToLocation if location.get('location', False) else identity iterable = func.select(F, Or=tags) if tags else func.select(F) for ea, res in iterable: ui.navigation.set(ea) if res: yield translate(ea), res return
def recovermarks(): '''Utilizing any tag information found in the database, recreate all the database marks.''' # collect result = [] for fn,l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'],'__iter__') else [int(x,16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea,d['mark']) for ea,d in function.select(fn,'mark')] if m != set(a for a,_ in res): logging.warning("%x: ignoring cached version of marks due to being out-of-sync with real values : %r : %r", fn, map(hex,m), map(hex,set(a for a,_ in res))) result.extend(res) result.sort(cmp=lambda x,y: cmp(x[1],y[1])) # discovered marks versus database marks result = dict(result) current = {ea:descr for ea,descr in database.marks()} # create tags for x,y in result.items(): if (x not in current) or (current[x] != result[x]): if current[x] != result[x]: logging.info('%x: database tag is newer than mark description : %r', x, result[x]) database.mark(x, y) continue logging.warning('%x: skipping already existing mark : %r', x, current[x]) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning('%x: unreachable mark (global) : %r', ea, current[ea]) # color them colormarks()
def dump_labels(func, statement="g"): Escape = lambda s: s.replace('"', '\\"') for ea, t in fn.select(func, 'name'): print 'bp {:s} ".printf \\"label {:s}:{:s}\\\\n\\";{:s}"'.format( eaToReference(ea), fn.name(func), Escape(t['name']), Escape(statement)) return
def recovermarks(): """Walk through the tags made by ``colormarks`` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = {item for item in l['marks']} if hasattr(l['marks'], '__iter__') else { int(item, 16) for item in l['marks'].split(',') } if isinstance(l['marks'], six.string_types) else {l['marks']} res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != {ea for ea, _ in res}: logging.warning( "{:s} : Ignoring the function tag \"{:s}\" for function {:#x} due to its value being out-of-sync with the contents values ({!s} <> {!s})." .format('.'.join([__name__, 'recovermarks']), fn, builtins.map("{:#x}".format, m), builtins.map("{:#x}".format, {ea for ea, _ in res}))) result.extend(res) result.sort(key=lambda item: item[1]) # discovered marks versus database marks result = {ea: item for ea, item in result.items()} current = {ea: descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning( "{:#x}: skipping already existing mark : {!r}".format( x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format( x, result[x])) elif current[x] != result[x]: logging.info( "{:#x}: database tag is different than mark description : {!r}" .format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in {item for item in current.keys() }.difference({item for item in result.keys()}): logging.warning("{:#x}: unreachable mark (global) : {!r}".format( ea, current[ea])) # color them colormarks()
def breakpoints(f=None, **kwargs): """Query the function `f` for the "break" tag, and use it to emit a list of breakpoints for windbg. If the string `module` is specified, then use it instead of the current filename when emitting the location. If the string `tagname` is provided, then use it to query instead of "break". """ tagname = kwargs.get('tagname', 'break') # if no function was provided, then recurse into ourself for all of them if f is None: for f, _ in db.selectcontents(tagname): breakpoints(f, **kwargs) return #entry, exit = func.top(f), func.bottom(f) #funcname = func.name(f) #[(entry,{tagname:'.printf "Entering {:s} %x,%x\\n",poi(@esp),@esp'.format(funcname)})], [(x,{tagname:'.printf "Exiting {:s} %x,%x\\n",poi(@esp),@esp'.format(funcname)}) for x in exit], # query the given function for the requested tagname tags, select = {}, itertools.chain(func.select(f, And=(tagname,), Or=('',))) for ea, t in select: h = tags.setdefault(ea, {}) for k in t.keys(): if k == tagname: h.setdefault(k, []).extend(t[k] if isinstance(t[k], builtins.list) else t[k].split(';')) elif operator.contains(h, k): logging.warning(u"{:s}.breakpoints({:#x}{:s}) : The specified key \"{:s}\" already exists in dictionary for address {:#x}.".format(__name__, func.addr(f), u", {:s}".format(utils.strings.kwargs(kwargs)) if kwargs else '', utils.string.escape(k, '"'), ea)) else: h[k] = t[k] continue continue # aggregate all of the discovered tags into a list of breakpoints for ea, t in tags.items(): ofs, commands = db.offset(ea), [] # create the command that emits the current label label_t = string.Template(r'.printf "$label -- $note\n"' if operator.contains(t, '') else r'.printf "$label\n"') commands.append(label_t.safe_substitute(label=label(ea), note=t.get('', ''))) # append the commands to execute when encountering the given breakpoint res = t.get(tagname, ['g']) if isinstance(res, builtins.list): commands.extend(res) else: commands.append(res) # escape all of the commands since we're going to join them together commands = (escape(cmd) for cmd in commands) six.print_('bp {:s} "{:s}"'.format(reference(ea, **kwargs), escape(';'.join(commands), depth=1))) return
def dump_breaks(func=None, tagname='break', stdout=True): if func is None: for func, _ in db.selectcontents(tagname): dump_breaks(func, tagname=tagname) return Escape = lambda s: s.replace('"', '\\"') entry, exit = fn.top(func), fn.bottom(func) funcname = fn.name(func) #[(entry,{tagname:'.printf "Entering {:s} %x,%x\\n",poi(@esp),@esp'.format(funcname)})], [(x,{tagname:'.printf "Exiting {:s} %x,%x\\n",poi(@esp),@esp'.format(funcname)}) for x in exit], select = itertools.chain(fn.select(func, And=(tagname, ), Or=('', ))) res = {} for ea, t in select: h = res.setdefault(ea, {}) for k in t.keys(): if k == tagname: h.setdefault(k, []).extend(t[k].split(';')) else: assert k not in h h[k] = t[k] continue output = [] for ea, t in res.iteritems(): ofs = db.offset(ea) commands = [] label = Template('.printf "$label -- $note\\n"' if t. has_key('') else '.printf "$label\\n"') commands.append( label.safe_substitute(label=eaToLabel(ea), note=t.get('', ''))) commands.extend(t.get(tagname, ['g'])) commands = map(windbgescape, commands) breakpoint = 'bp {:s} "{:s}"'.format(eaToReference(ea), Escape(';'.join(commands))) if stdout: print(breakpoint) output.append(breakpoint) if len(output) == 1: return output[0] + '\n' return '\n'.join(output)
def recovermarks(): '''Utilizing any tag information found in the database, recreate all the database marks.''' # collect result = [] for fn, l in database.select('marks'): m = set((l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks']. split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in function.select(fn, 'mark')] if m != set(a for a, _ in res): logging.warning( "{:x}: ignoring cached version of marks due to being out-of-sync with real values : {!r} : {!r}" .format(fn, map(hex, m), map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea: descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning( "{:x}: skipping already existing mark : {!r}".format( x, current[x])) continue # x not in current if x not in current: logging.info("{:x}: adding missing mark due to tag : {!r}".format( x, result[x])) elif current[x] != result[x]: logging.info( "{:x}: database tag is different than mark description : {!r}". format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:x}: unreachable mark (global) : {!r}".format( ea, current[ea])) # color them colormarks()
def recovermarks(): """Walk through the tags made by `colormarks` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != set(a for a, _ in res): logging.warning("{:#x}: ignoring cached version of marks due to being out-of-sync with real values : {!r} : {!r}".format(fn, builtins.map(hex, m), builtins.map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea : descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning("{:#x}: skipping already existing mark : {!r}".format(x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format(x, result[x])) elif current[x] != result[x]: logging.info("{:#x}: database tag is different than mark description : {!r}".format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:#x}: unreachable mark (global) : {!r}".format(ea, current[ea])) # color them colormarks()
def recovermarks(): """Walk through the tags made by ``colormarks`` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != { a for a, _ in res }: logging.warning("{:s} : Ignoring the function tag \"{:s}\" for function {:#x} due to its value being out-of-sync with the contents values ({!s} <> {!s}).".format('.'.join((__name__, 'recovermarks')), fn, builtins.map(hex, m), builtins.map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea : descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning("{:#x}: skipping already existing mark : {!r}".format(x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format(x, result[x])) elif current[x] != result[x]: logging.info("{:#x}: database tag is different than mark description : {!r}".format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:#x}: unreachable mark (global) : {!r}".format(ea, current[ea])) # color them colormarks()
'\nUser not found!\n\n\nCreating the new list of repositories.\n\n' ) print( "Here's a list of repositories that you're saving in your DB:\n\n") for i in web_page_json: insert_values(username, i['name']) print('->' + i['name']) count = 0 while count == 0: ans = input( '\n\nDo you want to show your repositories list saved on your DB? (y/n)' ) if ans.lower() == 'y': lista = select() for r in lista: print(f'{r[0]}:{r[1]}') count = 1 print('\n\nThanks for using!\n\n...Shuting down...') sleep(2) elif ans.lower() == 'n': print('\n\nThanks for using!\n\n...Shuting down...') sleep(2) exit() else: print('\n\nInvalid insert.\n\nTry again') else: print('\nUser not available.')
def contents(*tags, **boolean): for res in db.selectcontents(*tags, **boolean): for ea, res in fn.select(*res): yield ea, res continue return
def search(func, *tags): print '\n'.join(map(db.disasm, fn.select(func, Or=tags)))