Example #1
0
 def load(self):
     outdir = config.get_cache_filename(
         config.CACHE_SIGNATURE_GROUPS_DIR,
         self._context.dumpname)
     inname = os.path.sep.join([outdir, self._name])
     self._similarities = utils.int_array_cache(inname)
     return
Example #2
0
 def _load(self):
   ## DO NOT SORT LIST. c'est des sequences. pas des sets.
   myname = self.cacheFilenamePrefix+'.pinned'
   sig = utils.int_array_cache(myname)
   if sig is None:
     log.info("Signature has to be calculated for %s. It's gonna take a while."%(self.name))
     pointerSearcher = pointerfinder.PointerSearcher(self.mmap)
     self.WORDSIZE = pointerSearcher.WORDSIZE
     sig = []
     # save first offset
     last = self.mmap.start
     for i in pointerSearcher: #returns the vaddr
       sig.append(i-last) # save intervals between pointers
       #print hex(i), 'value:', hex(self.mmap.readWord(i) )
       last=i
     # save it
     sig = utils.int_array_save(myname, sig)
   else:
     log.debug("%d Signature intervals loaded from cache."%( len(sig) ))
   self.sig = sig
   #
   self.addressCache[0] = self.mmap.start # previous pointer of interval 0 is start of mmap
   self._loadAddressCache()
   return
 def load(self, _context):
     inname = _context.get_filename_cache_signatures()
     self._similarities = utils.int_array_cache(inname)
     return
 def load(self):
     outdir = config.get_cache_filename(config.CACHE_SIGNATURE_GROUPS_DIR,
                                        self._context.dumpname)
     inname = os.path.sep.join([outdir, self._name])
     self._similarities = utils.int_array_cache(inname)
     return
Example #5
0
 def load(self, _context):
     inname = _context.get_filename_cache_signatures()
     self._similarities = utils.int_array_cache(inname)
     return
Example #6
0
def clean(digraph):
    # clean solos
    isolates = networkx.algorithms.isolate.isolates(digraph)
    digraph.remove_nodes_from(isolates)

    # clean solos clusters
    graph = networkx.Graph(digraph)  # undirected
    subgraphs = networkx.algorithms.components.connected.connected_component_subgraphs(
        graph)
    isolates1 = set(utils.flatten(g.nodes() for g in subgraphs if len(g) == 1))  # self connected
    isolates2 = set(utils.flatten(g.nodes() for g in subgraphs if len(g) == 2))
    isolates3 = set(utils.flatten(g.nodes() for g in subgraphs if len(g) == 3))
    digraph.remove_nodes_from(isolates1)
    digraph.remove_nodes_from(isolates2)
    digraph.remove_nodes_from(isolates3)

    #
    #graph = digraph.to_undirected()
    #subgraphs = networkx.algorithms.components.connected.connected_component_subgraphs(graph)
    subgraphs = [g for g in subgraphs if len(g) > 3]
    isolatedGraphs = subgraphs[1:100]

    # group by nodes number
    isoDict = defaultdict(list)
    [isoDict[len(g)].append(g) for g in isolatedGraphs]

    # test isomorphism
    isoGraphs = dict()
    for numNodes, graphs in isoDict.items():
        numgraphs = len(graphs)
        if numgraphs == 1:
            continue
        isoGraph = networkx.Graph()
        # quick find isomorphisms
        todo = set(graphs)
        for i, g1 in enumerate(graphs):
            for g2 in graphs[i + 1:]:
                if networkx.is_isomorphic(g1, g2):
                    print 'numNodes:%d graphs %d, %d are isomorphic' % (numNodes, i, i + 1)
                    isoGraph.add_edge(g1, g2, {'isomorphic': True})
                    if g2 in todo:
                        todo.remove(g2)
                    if g1 in todo:
                        todo.remove(g1)
                    # we can stop here, chain comparaison will work between g2
                    # and g3
                    break

        if len(isoGraph) > 0:
            isoGraphs[numNodes] = isoGraph

    # draw the isomorphisms
    for i, item in enumerate(isoGraphs.items()):
        num, g = item
        # networkx.draw(g)
        for rg in g.nodes():
            networkx.draw(rg)
        fname = os.path.sep.join(
            [config.imgCacheDir, 'isomorph_subgraphs_%d.png' % (num)])
        plt.savefig(fname)
        plt.clf()
    # need to use gephi-like for rendering nicely on the same pic

    bigGraph = networkx.DiGraph()
    bigGraph.add_edges_from(digraph.edges(subgraphs[0].nodes()))

    stack_addrs = utils.int_array_cache(
        config.get_cache_filename(config.CACHE_STACK_VALUES, ctx.dumpname, ctx._heap_addr))
    stack_addrs_txt = set(['%x' % (addr)
                           for addr in stack_addrs])  # new, no long

    stacknodes = list(set(bigGraph.nodes()) & stack_addrs_txt)
    print 'stacknodes left', len(stacknodes)
    orig = list(set(graph.nodes()) & stack_addrs_txt)
    print 'stacknodes orig', len(orig)

    # identify strongly referenced allocators
    degreesList = [(bigGraph.in_degree(node), node)
                   for node in bigGraph.nodes()]
    degreesList.sort(reverse=True)
Example #7
0
def clean(digraph):
    # clean solos
    isolates = networkx.algorithms.isolate.isolates(digraph)
    digraph.remove_nodes_from(isolates)

    # clean solos clusters
    graph = networkx.Graph(digraph)  # undirected
    subgraphs = networkx.algorithms.components.connected.connected_component_subgraphs(
        graph)
    isolates1 = set(utils.flatten(g.nodes() for g in subgraphs
                                  if len(g) == 1))  # self connected
    isolates2 = set(utils.flatten(g.nodes() for g in subgraphs if len(g) == 2))
    isolates3 = set(utils.flatten(g.nodes() for g in subgraphs if len(g) == 3))
    digraph.remove_nodes_from(isolates1)
    digraph.remove_nodes_from(isolates2)
    digraph.remove_nodes_from(isolates3)

    #
    #graph = digraph.to_undirected()
    #subgraphs = networkx.algorithms.components.connected.connected_component_subgraphs(graph)
    subgraphs = [g for g in subgraphs if len(g) > 3]
    isolatedGraphs = subgraphs[1:100]

    # group by nodes number
    isoDict = defaultdict(list)
    [isoDict[len(g)].append(g) for g in isolatedGraphs]

    # test isomorphism
    isoGraphs = dict()
    for numNodes, graphs in isoDict.items():
        numgraphs = len(graphs)
        if numgraphs == 1:
            continue
        isoGraph = networkx.Graph()
        # quick find isomorphisms
        todo = set(graphs)
        for i, g1 in enumerate(graphs):
            for g2 in graphs[i + 1:]:
                if networkx.is_isomorphic(g1, g2):
                    print('numNodes:%d graphs %d, %d are isomorphic' %
                          (numNodes, i, i + 1))
                    isoGraph.add_edge(g1, g2, {'isomorphic': True})
                    if g2 in todo:
                        todo.remove(g2)
                    if g1 in todo:
                        todo.remove(g1)
                    # we can stop here, chain comparaison will work between g2
                    # and g3
                    break

        if len(isoGraph) > 0:
            isoGraphs[numNodes] = isoGraph

    # draw the isomorphisms
    for i, item in enumerate(isoGraphs.items()):
        num, g = item
        # networkx.draw(g)
        for rg in g.nodes():
            networkx.draw(rg)
        fname = os.path.sep.join(
            [config.imgCacheDir,
             'isomorph_subgraphs_%d.png' % num])
        plt.savefig(fname)
        plt.clf()
    # need to use gephi-like for rendering nicely on the same pic

    bigGraph = networkx.DiGraph()
    bigGraph.add_edges_from(digraph.edges(subgraphs[0].nodes()))

    stack_addrs = utils.int_array_cache(
        config.get_cache_filename(config.CACHE_STACK_VALUES, ctx.dumpname,
                                  ctx._heap_addr))
    stack_addrs_txt = set(['%x' % addr
                           for addr in stack_addrs])  # new, no long

    stacknodes = list(set(bigGraph.nodes()) & stack_addrs_txt)
    print('stacknodes left', len(stacknodes))
    orig = list(set(graph.nodes()) & stack_addrs_txt)
    print('stacknodes orig', len(orig))

    # identify strongly referenced allocators
    degreesList = [(bigGraph.in_degree(node), node)
                   for node in bigGraph.nodes()]
    degreesList.sort(reverse=True)