Exemple #1
0
    def contents(*tags, **location):
        """Iterate through the specified contents `tags` within the database using the cache.

        Each iteration yields a tuple of the format `(location, tags)` where
        `location` can be either an address or a chunk identifier and offset
        depending on whether `location` was specified as true or not.
        """
        global export
        location = location.get('location', False)

        iterable = db.selectcontents(Or=tags) if tags else db.selectcontents()
        for F, res in iterable:
            for loc, res in export.content(F, *res, location=location):
                if res: yield loc, res
            continue
        return
Exemple #2
0
    def contents(*tags, **location):
        """Iterate through the specified contents `tags` within the database using the cache.

        Each iteration yields a tuple of the format `(location, tags)` where
        `location` can be either an address or a chunk identifier and offset
        depending on whether `location` was specified as true or not.
        """
        global export
        location = location.get('location', False)

        iterable = db.selectcontents(Or=tags) if tags else db.selectcontents()
        for F, res in iterable:
            for loc, res in export.content(F, *res, location=location):
                if res: yield loc, res
            continue
        return
Exemple #3
0
def cached():
    '''Return all tags using the database's tag cache as (globals, contents).'''
    print >> output, '--> Grabbing globals (cached)...'
    g = {ea: t for ea, t in db.select()}

    print >> output, '--> Grabbing contents from all functions (cached)...'
    res = itertools.starmap(fn.select, db.selectcontents())
    f = {ea: t for ea, t in itertools.chain(*res)}

    return (g, f)
Exemple #4
0
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
Exemple #5
0
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)
Exemple #6
0
def list():
    '''Return all the contents tags within the database as a set.'''
    return {t for t in itertools.chain(*(t for _, t in db.selectcontents()))}
Exemple #7
0
 def contents(*tags, **boolean):
     for res in db.selectcontents(*tags, **boolean):
         for ea, res in fn.select(*res):
             yield ea, res
         continue
     return
Exemple #8
0
def list():
    '''Return the tags for the all of the function contents within the database as a set.'''
    return {
        res
        for res in itertools.chain(*(res for _, res in db.selectcontents()))
    }
Exemple #9
0
def list():
    '''Return the tags for the all of the function contents within the database as a set.'''
    return {res for res in itertools.chain(*(res for _, res in db.selectcontents()))}