Exemplo n.º 1
0
def checkmarks():
    '''Output all functions (sys.stdout) containing more than 1 mark.'''
    res = []
    for a,m in database.marks():
        try:
            res.append((function.top(a), a, m))
        except ValueError:
            pass
        continue

    d = list(res)
    d.sort( lambda a,b: cmp(a[0], b[0]) )

    flookup = {}
    for fn,a,m in d:
        try:
            flookup[fn].append((a,m))
        except:
            flookup[fn] = [(a,m)]
        continue

    functions = [ (k,v) for k,v in flookup.items() if len(v) > 1 ]
    if not functions:
        logging.warning('There are no functions available containing multiple marks.')
        return

    for k,v in functions:
        print >>sys.stdout, '%x : in function %s'% (k,function.name(function.byAddress(k)))
        print >>sys.stdout, '\n'.join( ('- %x : %s'%(a,m) for a,m in sorted(v)) )
    return
Exemplo n.º 2
0
    def tag(ea, *args, **kwds):
        '''tag(ea, key?, value?, repeatable=True/False) -> fetches/stores a tag from specified address'''
        # if not in a function, it could be a global, so make the tag repeatable
        #   otherwise, use a non-repeatable comment
        ea = int(ea)
        try:
            func = function.byAddress(ea)
        except Exception:
            func = None
        kwds.setdefault('repeatable', True if func is None else False)

        if len(args) < 2:
            return tag_read(ea, *args, **kwds)

        key, value = args
        result = tag_write(ea, key, value, **kwds)

        # add tag-name to function's cache
        if func is not None and value is not None and key is not '__tags__':
            top = func.startEA
            tags = function.tags(ea)
            tags.add(key)
            tag_write(top, '__tags__', tags)

        return result
Exemplo n.º 3
0
def checkmarks():
    """Emit all functions that contain more than 1 mark within them.

    As an example, if marks are used to keep track of backtraces then
    this tool will emit where those backtraces intersect.
    """
    res = []
    for a, m in database.marks():
        try:
            res.append((func.top(a), a, m))
        except internal.exceptions.FunctionNotFoundError:
            pass
        continue

    d = list(res)
    d.sort( lambda a, b: cmp(a[0], b[0]) )

    flookup = {}
    for fn, a, m in d:
        try:
            flookup[fn].append((a, m))
        except:
            flookup[fn] = [(a, m)]
        continue

    functions = [ (k, v) for k, v in flookup.items() if len(v) > 1 ]
    if not functions:
        logging.warning('There are no functions available containing multiple marks.')
        return

    for k, v in functions:
        print >>sys.stdout, "{:#x} : in function {:s}".format(k, func.name(func.byAddress(k)))
        print >>sys.stdout, '\n'.join( ("- {:#x} : {:s}".format(a, m) for a, m in sorted(v)) )
    return
Exemplo n.º 4
0
def makecall(ea):
    if not function.contains(ea, ea):
        return None

    # scan down until we find a call that references something
    chunk, = ((l, r) for l, r in function.chunks(ea) if l <= ea <= r)
    result = []
    while (len(result) < 1) and ea < chunk[1]:
        # FIXME: it's probably not good to just scan for a call
        if not instruction(ea).startswith('call '):
            ea = next(ea)
            continue
        result = cxdown(ea)

    if len(result) != 1:
        raise ValueError('Invalid code reference: %x %s' % (ea, repr(result)))
    fn, = result

    result = []
    for offset, name, size in function.getArguments(fn):
        left, _ = function.stackwindow(ea, offset + config.bits() / 8)
        # FIXME: if left is not an assignment or a push, find last assignment
        result.append((name, left))

    result = [
        '%s=%s' % (name, _instruction.op_repr(ea, 0)) for name, ea in result
    ]
    return '%s(%s)' % (_declaration.demangle(
        function.name(function.byAddress(fn))), ','.join(result))
Exemplo n.º 5
0
def checkmarks():
    '''Output all functions (sys.stdout) containing more than 1 mark.'''
    res = []
    for a, m in database.marks():
        try:
            res.append((function.top(a), a, m))
        except ValueError:
            pass
        continue

    d = list(res)
    d.sort(lambda a, b: cmp(a[0], b[0]))

    flookup = {}
    for fn, a, m in d:
        try:
            flookup[fn].append((a, m))
        except:
            flookup[fn] = [(a, m)]
        continue

    functions = [(k, v) for k, v in flookup.items() if len(v) > 1]
    if not functions:
        logging.warning(
            'There are no functions available containing multiple marks.')
        return

    for k, v in functions:
        print >> sys.stdout, "{:x} : in function {:s}".format(
            k, function.name(function.byAddress(k)))
        print >> sys.stdout, '\n'.join(
            ("- {:x} : {:s}".format(a, m) for a, m in sorted(v)))
    return
Exemplo n.º 6
0
    def tag(ea, *args, **kwds):
        '''tag(ea, key?, value?, repeatable=True/False) -> fetches/stores a tag from specified address'''
        # if not in a function, it could be a global, so make the tag repeatable
        #   otherwise, use a non-repeatable comment
        ea = int(ea)
        try:
            func = function.byAddress(ea)
        except Exception:
            func = None
        kwds.setdefault('repeatable', True if func is None else False)

        if len(args) < 2:
            return tag_read(ea, *args, **kwds)

        key,value = args
        result = tag_write(ea, key, value, **kwds)

        # add tag-name to function's cache
        if func is not None and value is not None and key is not '__tags__':
            top = func.startEA
            tags = function.tags(ea)
            tags.add(key)
            tag_write(top, '__tags__', tags)

        return result
Exemplo n.º 7
0
def makecall(ea):
    if not function.contains(ea, ea):
        return None

    # scan down until we find a call that references something
    chunk, = ((l,r) for l,r in function.chunks(ea) if l <= ea <= r)
    result = []
    while (len(result) < 1) and ea < chunk[1]:
        # FIXME: it's probably not good to just scan for a call
        if not instruction(ea).startswith('call '):
            ea = next(ea)
            continue
        result = cxdown(ea)

    if len(result) != 1:
        raise ValueError('Invalid code reference: %x %s'% (ea,repr(result)))
    fn, = result

    result = []
    for offset,name,size in function.getArguments(fn):
        left,_ = function.stackwindow(ea, offset+config.bits()/8)
        # FIXME: if left is not an assignment or a push, find last assignment
        result.append((name,left))

    result = ['%s=%s'%(name,_instruction.op_repr(ea,0)) for name,ea in result]
    return '%s(%s)'%(internal.declaration.demangle(function.name(function.byAddress(fn))), ','.join(result))
Exemplo n.º 8
0
def checkmarks():
    """Emit all functions that contain more than 1 mark within them.

    As an example, if marks are used to keep track of backtraces then
    this tool will emit where those backtraces intersect.
    """
    res = []
    for a, m in database.marks():
        try:
            res.append((func.top(a), a, m))
        except internal.exceptions.FunctionNotFoundError:
            pass
        continue

    d = list(res)
    d.sort( lambda a, b: cmp(a[0], b[0]) )

    flookup = {}
    for fn, a, m in d:
        try:
            flookup[fn].append((a, m))
        except:
            flookup[fn] = [(a, m)]
        continue

    functions = [ (k, v) for k, v in flookup.items() if len(v) > 1 ]
    if not functions:
        logging.warning('There are no functions available containing multiple marks.')
        return

    for k, v in functions:
        print >>sys.stdout, "{:#x} : in function {:s}".format(k, func.name(func.byAddress(k)))
        print >>sys.stdout, '\n'.join( ("- {:#x} : {:s}".format(a, m) for a, m in sorted(v)) )
    return