(self, start, max_call_depth=None)
return subcfg
Get a sub-graph of a certain function.

        :param start: The function start. Currently it should be an integer.
        :param max_call_depth: Call depth limit. None indicates no limit.
        :return: A CFG instance which is a sub-graph of self.graph
Get a sub-graph of a certain function.
Get a sub - graph of a certain function .
def get_function_subgraph(self, start, max_call_depth=None):
        """
        Get a sub-graph of a certain function.

        :param start: The function start. Currently it should be an integer.
        :param max_call_depth: Call depth limit. None indicates no limit.
        :return: A CFG instance which is a sub-graph of self.graph
        """

        # FIXME: syscalls are not supported
        # FIXME: start should also take a CFGNode instance

        start_node = self.get_any_node(start)

        node_wrapper = (start_node, 0)
        stack = [node_wrapper]
        traversed_nodes = {start_node}
        subgraph_nodes = set([start_node])

        while stack:
            nw = stack.pop()
            n, call_depth = nw[0], nw[1]

            # Get successors
            edges = self.graph.out_edges(n, data=True)

            for _, dst, data in edges:
                if dst not in traversed_nodes:
                    # We see a new node!
                    traversed_nodes.add(dst)

                    if data['jumpkind'] == 'Ijk_Call':
                        if max_call_depth is None or (max_call_depth is not None and call_depth < max_call_depth):
                            subgraph_nodes.add(dst)
                            new_nw = (dst, call_depth + 1)
                            stack.append(new_nw)
                    elif data['jumpkind'] == 'Ijk_Ret':
                        if call_depth > 0:
                            subgraph_nodes.add(dst)
                            new_nw = (dst, call_depth - 1)
                            stack.append(new_nw)
                    else:
                        subgraph_nodes.add(dst)
                        new_nw = (dst, call_depth)
                        stack.append(new_nw)

       #subgraph = networkx.subgraph(self.graph, subgraph_nodes)
        subgraph = self.graph.subgraph(subgraph_nodes).copy()

        # Make it a CFG instance
        subcfg = self.copy()
        subcfg._graph = subgraph
        subcfg._starts = (start,)

        return subcfg
def get_function_subgraph ( self , start , max_call_depth = None ) : # FIXME: syscalls are not supported # FIXME: start should also take a CFGNode instance start_node = self . get_any_node ( start ) node_wrapper = ( start_node , 0 ) stack = [ node_wrapper ] traversed_nodes = { start_node } subgraph_nodes = set ( [ start_node ] ) while stack : nw = stack . pop ( ) n , call_depth = nw [ 0 ] , nw [ 1 ] # Get successors edges = self . graph . out_edges ( n , data = True ) for _ , dst , data in edges : if dst not in traversed_nodes : # We see a new node! traversed_nodes . add ( dst ) if data [ 'jumpkind' ] == 'Ijk_Call' : if max_call_depth is None or ( max_call_depth is not None and call_depth < max_call_depth ) : subgraph_nodes . add ( dst ) new_nw = ( dst , call_depth + 1 ) stack . append ( new_nw ) elif data [ 'jumpkind' ] == 'Ijk_Ret' : if call_depth > 0 : subgraph_nodes . add ( dst ) new_nw = ( dst , call_depth - 1 ) stack . append ( new_nw ) else : subgraph_nodes . add ( dst ) new_nw = ( dst , call_depth ) stack . append ( new_nw ) #subgraph = networkx.subgraph(self.graph, subgraph_nodes) subgraph = self . graph . subgraph ( subgraph_nodes ) . copy ( ) # Make it a CFG instance subcfg = self . copy ( ) subcfg . _graph = subgraph subcfg . _starts = ( start , ) return subcfg