Example #1
0
    def export_to_graphml(self):
        """
        GraphML is nice. Display with yed and enjoy.
        """
        filename = AskFile(1, "*.graphml", "File to export to?")

        if not filename:
            # For example, file dialog was closed
            print 'Error getting filename'
            return None

        if self.cache.trace_d:
            # Already populated
            trace_d = self.cache.trace_d

        else:
            print '[!] Could not find trace dictionary on cache'
            return None

        # TODO: working with tid 0 for now
        # Maybe just generate several filename_N.graphml?
        t0_list = trace_d[0]
        edge_list = [map(lambda x: GetFunctionName(x), e) for e in t0_list]

        return graphing.write_to_graphml(edge_list, filename)
Example #2
0
    def get_all_dangerous_connections(self):
        """
        Get all connections between IO and dangerous
        functions. It is a necessary (but not sufficient)
        condition for a problem like memory corruption
        All code pieces were there already :)
        """
        conn_graphs = []
        dang_conns = []
        dang_funcs = self.get_dangerous_functions()

        if not dang_funcs:
            return []

        for df in dang_funcs:
            for io_caller in self.input_to_function(df):
                # [(u, v), ...]
                dang_conns.append((io_caller, df))

        # Calculate the connect graphs
        for tu in dang_conns:
            u, v = tu   # tuple unpacking
            cg = self.get_connect_graph(u, v)
            sh_path = graphing.cg_shortest_path(cg, u, v)

            if not sh_path:
                # Error. Skipping this one
                continue

            sh_path_len = len(sh_path) - 1  # by definition
            conn_graphs.append((u, v, sh_path_len))

        return conn_graphs
Example #3
0
    def export_to_graphml(self):
        """
        GraphML is nice. Display with yed and enjoy.
        """
        filename = AskFile(1, "*.graphml", "File to export to?")

        if not filename:
            # For example, file dialog was closed
            print 'Error getting filename'
            return None

        if self.cache.trace_d:
            # Already populated
            trace_d = self.cache.trace_d

        else:
            print '[!] Could not find trace dictionary on cache'
            return None

        # TODO: working with tid 0 for now
        # Maybe just generate several filename_N.graphml?
        t0_list = trace_d[0]
        edge_list = [map(lambda x: GetFunctionName(x), e) for e in t0_list]

        return graphing.write_to_graphml(edge_list, filename)
Example #4
0
    def show_connect_graph(self, cg = None):
        """
        Convenience method
        Displays a ConnectGraph from orig to dest
        """
        if cg:
            conn = graphing.ConnectGraph(cg)
            conn.Show()
            return True

        else:
            return False
Example #5
0
    def get_bb_connect_graph(self, co):
        """
        This is a thin wrapper.
        :param co:
        :return: generator of lists or None
        """
        bg = graphing.BlockGraph(here())
        paths = bg.find_connected_paths(co)

        if not paths:
            return None

        return paths
Example #6
0
    def get_connect_graph(self, u, v):
        """
        Calculates a ConnectGraph from orig to dest
        """
        fg = graphing.FunctionGraph()

        co = self.config.connect_func_cutoff
        cg = fg.connect_graph(u, v, co)

        if cg == {}:
            return False

        else:
            return cg