Esempio n. 1
0
def collect(ea, sentinel):
    """Collect all the basic blocks starting at address `ea` and recurse until a terminating block is encountered.

    If the set `sentinel` is specified, then its addresses are used as
    sentinel blocks and collection will terminate when those blocks are
    reached.
    """
    if isinstance(sentinel, list):
        sentinel = set(sentinel)
    if not all((sentinel, isinstance(sentinel, set))):
        raise AssertionError(
            "{:s}.collect({:#x}, {!r}) : Sentinel is empty or not a set.".
            format(__name__, ea, sentinel))

    def _collect(addr, result):
        process = set()
        for blk in builtins.map(func.block, func.block.after(addr)):
            if any(blk in coll for coll in (result, sentinel)):
                continue
            process.add(blk)
        for addr, _ in process:
            result |= _collect(addr, result | process)
        return result

    addr, _ = blk = func.block(ea)
    return _collect(addr, set([blk]))
Esempio n. 2
0
def collect(ea, sentinel):
    if isinstance(sentinel, list):
        sentinel = set(sentinel)
    if not all((sentinel, isinstance(sentinel, set))):
        raise AssertionError(
            "{:s}.collect({:x}, {!r}) : Sentinel is empty or not a set.".
            format(__name__, ea, sentinel))

    def _collect(addr, result):
        process = set()
        for blk in map(function.block, function.block.after(addr)):
            if any(blk in coll for coll in (result, sentinel)):
                continue
            process.add(blk)
        for addr, _ in process:
            result |= _collect(addr, result | process)
        return result

    addr, _ = blk = function.block(ea)
    return _collect(addr, set([blk]))
Esempio n. 3
0
def collect(ea, sentinel):
    """Collect all the basic blocks starting at address `ea` and recurse until a terminating block is encountered.

    If the set `sentinel` is specified, then its addresses are used as
    sentinel blocks and collection will terminate when those blocks are
    reached.
    """
    if isinstance(sentinel, list):
        sentinel = set(sentinel)
    if not all((sentinel, isinstance(sentinel, set))):
        raise AssertionError("{:s}.collect({:#x}, {!r}) : Sentinel is empty or not a set.".format(__name__, ea, sentinel))
    def _collect(addr, result):
        process = set()
        for blk in builtins.map(func.block, func.block.after(addr)):
            if any(blk in coll for coll in (result, sentinel)):
                continue
            process.add(blk)
        for addr, _ in process:
            result |= _collect(addr, result | process)
        return result
    addr, _ = blk = func.block(ea)
    return _collect(addr, set([blk]))