def createInferringStatusView(self):
        self.dialog = Gtk.Dialog(title=_("Execution of the inferring process"), flags=0, buttons=None)

        mainTable = Gtk.Table(rows=5, columns=4, homogeneous=False)

        # Insert the current Hypothesis of the automata
        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(500, 500)
        mainTable.attach(self.xdotWidget, 0, 2, 0, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the updated list of requests and associated responses
        scroll_requests = Gtk.ScrolledWindow()
        self.treestore_queries = Gtk.TreeStore(str, str, str)  # queries, responses, color
        treeview_queries = Gtk.TreeView(self.treestore_queries)
        treeview_queries.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        treeview_queries.set_size_request(500, 500)
#        treeview_queries.connect('button-press-event', self.button_press_on_transitions)
        cell = Gtk.CellRendererText()
        # col : membership queries
        col_queries_querie = Gtk.TreeViewColumn(_("Membership queries"))
        col_queries_querie.pack_start(cell, True)
        col_queries_querie.add_attribute(cell, "text", 0)
        treeview_queries.append_column(col_queries_querie)
        # col : responses to queries
        column_queries_responses = Gtk.TreeViewColumn(_("Responses"))
        column_queries_responses.pack_start(cell, True)
        column_queries_responses.add_attribute(cell, "text", 1)
        treeview_queries.append_column(column_queries_responses)
        scroll_requests.add(treeview_queries)
        scroll_requests.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scroll_requests.show()
        mainTable.attach(scroll_requests, 2, 4, 0, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Progress bar
        self.progressbar = Gtk.ProgressBar()
        self.progressbar.show()
#        # Insert the status message
#        self.statusLabel = Gtk.Label(label="A number of X states has been created - Current turn contains N MQ")
#        self.statusLabel.show()
        mainTable.attach(self.progressbar, 0, 2, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the stop button
        self.stopButton = Gtk.Button(_("Stop"))
        self.stopButton.show()
        self.stopButton.connect("clicked", self.stopInference)
        mainTable.attach(self.stopButton, 2, 3, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the Save button
        self.saveButton = Gtk.Button(_("Save as Grammar"))
        self.saveButton.show()
        self.saveButton.connect("clicked", self.saveGrammar)
        mainTable.attach(self.saveButton, 3, 4, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()
예제 #2
0
    def run(self, panel):
        xdotWidget = XDotWidget()
        panel.add(xdotWidget)
        if self.controller.symbol is None:
            return
        # We retrieve all the fields and there associated variables
        fields = dict()
        for field in self.controller.symbol.getExtendedFields():
            var = field.getVariable()
            if var is not None:
                fields["F{0}".format(field.getIndex())] = var

        dotCode = ["digraph G {"]
        dotCode.extend(self.addDotCodeForFields(fields))
        dotCode.append("}")
        xdotWidget.drawDotCode('\n'.join(dotCode))
        xdotWidget.show_all()

        if self.controller.allowMaximize:
            panel.connect("button_press_event", self.doubleClick_cb)
예제 #3
0
    def __init__(self, controller):
        self.controller = controller
        self.netzob = self.controller.netzob
        self.builder = Gtk.Builder()
        self.builder.add_from_file(os.path.join(
            ResourcesConfiguration.getStaticResources(),
            "ui", "simulator",
            "simulatorView.glade"))
        self._getObjects(self.builder, ["simulatorViewport",
                                        "editActorButton",
                                        "deleteActorButton",
                                        "stopActorButton",
                                        "startActorButton",
                                        "actorsListStore",
                                        "listOfActorsTreeView",
                                        "grammarCurrentActorViewport",
                                        "statusCurrentActorImage",
                                        "nameCurrentActorLabel",
                                        "stopCurrentActorButton",
                                        "startCurrentActorButton",
                                        "infoCurrentActorLabel",
                                        "statusCurrentActorLabel",
                                        "currentActorIOChannelListStore",
                                        "currentActorMemoryListStore",
                                        "currentActorPropertiesListStore"
                                        ])
        self._loadActionGroupUIDefinition()
        self.builder.connect_signals(self.controller)
        self.toggledActors = []

        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.grammarCurrentActorViewport.add(self.xdotWidget)

        self.refreshListOfActors()
        self.updateCurrentActor()
예제 #4
0
    def run(self, panel):
        xdotWidget = XDotWidget()
        panel.add(xdotWidget)
        if self.controller.symbol is None:
            return
        # We retrieve all the fields and there associated variables
        fields = dict()
        for field in self.controller.symbol.getExtendedFields():
            var = field.getVariable()
            if var is not None:
                fields["F{0}".format(field.getIndex())] = var

        dotCode = ["digraph G {"]
        dotCode.extend(self.addDotCodeForFields(fields))
        dotCode.append("}")
        xdotWidget.drawDotCode('\n'.join(dotCode))
        xdotWidget.show_all()

        if self.controller.allowMaximize:
            panel.connect("button_press_event", self.doubleClick_cb)
예제 #5
0
class AutomaticGrammarInferenceView(object):

    #+----------------------------------------------
    #| Constructor:
    #+----------------------------------------------
    def __init__(self, project):
        # create logger with the given configuration
        self.log = logging.getLogger(
            'netzob.Inference.Grammar.AutomaticGrammarInferenceView.py')
        self.project = project
        self.inferer = None
        self.computedAutomaton = None
        self.finish = False

    def display(self):
        # Display the form for the creation of a word variable
        self.dialog = Gtk.Dialog(
            title=_("Configuration of the automatic inference"),
            flags=0,
            buttons=None)

        mainTable = Gtk.Table(rows=9, columns=2, homogeneous=False)

        # Infer a client or a server
        targetOfInferenceLabel = Gtk.Label(label=_("Target:"))
        targetOfInferenceLabel.show()
        self.targetOfInferenceCombo = Gtk.ComboBoxText()
        self.targetOfInferenceCombo.set_model(Gtk.ListStore(str))
        targetOfInferenceComboCell = Gtk.CellRendererText()
        self.targetOfInferenceCombo.pack_start(targetOfInferenceComboCell,
                                               True)
        self.targetOfInferenceCombo.add_attribute(targetOfInferenceComboCell,
                                                  'text', 0)
        self.targetOfInferenceCombo.append_text(_("CLIENT"))
        self.targetOfInferenceCombo.append_text(_("SERVER"))
        self.targetOfInferenceCombo.show()
        mainTable.attach(targetOfInferenceLabel,
                         0,
                         1,
                         0,
                         1,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.targetOfInferenceCombo,
                         1,
                         2,
                         0,
                         1,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # IP of the server
        IPLabel = Gtk.Label(label=_("IP:"))
        IPLabel.show()
        self.IPEntry = Gtk.Entry()
        self.IPEntry.show()
        mainTable.attach(IPLabel,
                         0,
                         1,
                         1,
                         2,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.IPEntry,
                         1,
                         2,
                         1,
                         2,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Protocol of the server
        ProtocolLabel = Gtk.Label(label=_("Protocol:"))
        ProtocolLabel.show()
        self.combo_protocolOfNetworkActor = Gtk.ComboBoxText.new_with_entry()
        self.combo_protocolOfNetworkActor.set_model(Gtk.ListStore(str))
        self.combo_protocolOfNetworkActor.append_text(_("TCP"))
        self.combo_protocolOfNetworkActor.append_text(_("UDP"))
        self.combo_protocolOfNetworkActor.set_active(0)
        self.combo_protocolOfNetworkActor.show()

        mainTable.attach(ProtocolLabel,
                         0,
                         1,
                         2,
                         3,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.combo_protocolOfNetworkActor,
                         1,
                         2,
                         2,
                         3,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Source port
        SourcePortLabel = Gtk.Label(label=_("Our port:"))
        SourcePortLabel.show()
        self.ourPortEntry = Gtk.Entry()
        self.ourPortEntry.show()
        mainTable.attach(SourcePortLabel,
                         0,
                         1,
                         3,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.ourPortEntry,
                         1,
                         2,
                         3,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Port of the server
        PortLabel = Gtk.Label(label=_("Target Port:"))
        PortLabel.show()
        self.targetPortEntry = Gtk.Entry()
        self.targetPortEntry.show()
        mainTable.attach(PortLabel,
                         0,
                         1,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.targetPortEntry,
                         1,
                         2,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Estimated number of states
        MaxStatesLabel = Gtk.Label(label=_("Maximum number of states:"))
        MaxStatesLabel.show()
        self.MaxStatesEntry = Gtk.Entry()
        self.MaxStatesEntry.show()
        mainTable.attach(MaxStatesLabel,
                         0,
                         1,
                         5,
                         6,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.MaxStatesEntry,
                         1,
                         2,
                         5,
                         6,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Script to execute to reset the implementation
        scriptLabel = Gtk.Label(label=_("Reseting script:"))
        scriptLabel.show()
        self.scriptEntry = Gtk.Entry()
        self.scriptEntry.show()
        mainTable.attach(scriptLabel,
                         0,
                         1,
                         6,
                         7,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)
        mainTable.attach(self.scriptEntry,
                         1,
                         2,
                         6,
                         7,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Create button
        startButton = Gtk.Button(_("Start inference"))
        startButton.show()
        startButton.connect("clicked", self.startInference)
        mainTable.attach(startButton,
                         1,
                         2,
                         7,
                         8,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()

    def createInferringStatusView(self):
        self.dialog = Gtk.Dialog(title=_("Execution of the inferring process"),
                                 flags=0,
                                 buttons=None)

        mainTable = Gtk.Table(rows=5, columns=4, homogeneous=False)

        # Insert the current Hypothesis of the automata
        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(500, 500)
        mainTable.attach(self.xdotWidget,
                         0,
                         2,
                         0,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the updated list of requests and associated responses
        scroll_requests = Gtk.ScrolledWindow()
        self.treestore_queries = Gtk.TreeStore(
            str, str, str)  # queries, responses, color
        treeview_queries = Gtk.TreeView(self.treestore_queries)
        treeview_queries.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        treeview_queries.set_size_request(500, 500)
        #        treeview_queries.connect('button-press-event', self.button_press_on_transitions)
        cell = Gtk.CellRendererText()
        # col : membership queries
        col_queries_querie = Gtk.TreeViewColumn(_("Membership queries"))
        col_queries_querie.pack_start(cell, True)
        col_queries_querie.add_attribute(cell, "text", 0)
        treeview_queries.append_column(col_queries_querie)
        # col : responses to queries
        column_queries_responses = Gtk.TreeViewColumn(_("Responses"))
        column_queries_responses.pack_start(cell, True)
        column_queries_responses.add_attribute(cell, "text", 1)
        treeview_queries.append_column(column_queries_responses)
        scroll_requests.add(treeview_queries)
        scroll_requests.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scroll_requests.show()
        mainTable.attach(scroll_requests,
                         2,
                         4,
                         0,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Progress bar
        self.progressbar = Gtk.ProgressBar()
        self.progressbar.show()
        #        # Insert the status message
        #        self.statusLabel = Gtk.Label(label="A number of X states has been created - Current turn contains N MQ")
        #        self.statusLabel.show()
        mainTable.attach(self.progressbar,
                         0,
                         2,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the stop button
        self.stopButton = Gtk.Button(_("Stop"))
        self.stopButton.show()
        self.stopButton.connect("clicked", self.stopInference)
        mainTable.attach(self.stopButton,
                         2,
                         3,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the Save button
        self.saveButton = Gtk.Button(_("Save as Grammar"))
        self.saveButton.show()
        self.saveButton.connect("clicked", self.saveGrammar)
        mainTable.attach(self.saveButton,
                         3,
                         4,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()

    def do_pulse(self, *args):
        if self.finish is False:
            self.progressbar.pulse()
            return True
        return False

    def callback_submitedQuery(self, query, resultQuery):
        if query is None:
            self.log.debug("Impossible to show a Null query")
            return

        # Create a str view of the Query
        strQuery = ""
        for symbol in query.getSymbols():
            strSymbol = ""
            if symbol.getType() == "DictionarySymbol":
                strSymbol = symbol.getName()
            else:
                strSymbol = "EmptySymbol"

            strQuery = strQuery + strSymbol + ", "

        # Create a str view of the Result Query
        strResultQuery = ""
        if not type(resultQuery) == list:
            return
        for symbol in resultQuery:
            strSymbol = ""
            if symbol.getType() == "DictionarySymbol":
                strSymbol = symbol.getName()
            else:
                strSymbol = str(symbol)

            strResultQuery = strResultQuery + strSymbol + ","

        self.treestore_queries.append(None, [strQuery, strResultQuery, "blue"])

    def callback_hypotheticalAutomaton(self, hypotheticalAutomaton):
        if hypotheticalAutomaton is not None:
            self.computedAutomaton = hypotheticalAutomaton
            self.xdotWidget.set_dotcode(self.computedAutomaton.getDotCode())

    def stopInference(self, button):
        self.finish = True
        self.log.info("Stop the inferer")
        self.inferer.stop()

    def startInferer(self):
        (yield ThreadedTask(self.inferer.infer))
        self.computedAutomaton = self.inferer.getInferedAutomaton()
        self.finish = True

    def saveGrammar(self, button):
        if self.computedAutomaton is not None:
            self.log.debug(
                "Saving the computed automata as the grammar of current project"
            )
            self.project.getGrammar().setAutomata(self.computedAutomaton)
            self.dialog.destroy()

    def startInference(self, button):
        # We retrieve the specified value
        actorType = self.targetOfInferenceCombo.get_active_text()
        actorIP = self.IPEntry.get_text()
        actorNetworkProtocol = self.combo_protocolOfNetworkActor.get_active_text(
        )
        ourPort = int(self.ourPortEntry.get_text())
        targetPort = int(self.targetPortEntry.get_text())
        scriptFilename = self.scriptEntry.get_text()
        maxNumberOfState = int(self.MaxStatesEntry.get_text())

        inputDictionary = []
        for symbol in self.project.getVocabulary().getSymbols():
            #            if symbol.getName() == "LOGIN" or symbol.getName() == "EXECUTE" or symbol.getName() == "LOGOUT" or symbol.getName() == "DOWNLOAD":
            inputDictionary.append(symbol)
        inputDictionary.append(UnknownSymbol())
        # Close the current dialog
        self.dialog.destroy()

        anID = str(uuid.uuid4())
        memory = Memory()
        if actorType == "CLIENT":
            # Lets create a simple network oracle
            oracleCommunicationChannel = NetworkServer(anID, memory,
                                                       actorNetworkProtocol,
                                                       "127.0.0.1", ourPort,
                                                       actorIP, targetPort)
        else:
            # Lets create a simple network oracle
            oracleCommunicationChannel = NetworkClient(anID, memory,
                                                       actorNetworkProtocol,
                                                       "127.0.0.1", ourPort,
                                                       actorIP, targetPort)

        # Lets create an equivalence oracle
        equivalenceOracle = WMethodNetworkEquivalenceOracle(
            oracleCommunicationChannel, maxNumberOfState, scriptFilename)

        # Lets create the automatic inferer
        self.inferer = GrammarInferer(self.project.getVocabulary(),
                                      inputDictionary,
                                      oracleCommunicationChannel,
                                      equivalenceOracle, scriptFilename,
                                      self.callback_submitedQuery,
                                      self.callback_hypotheticalAutomaton)

        # Open the new dialog which shows the status of the inferring process
        self.createInferringStatusView()

        # Start the progress bar
        GObject.timeout_add(200, self.do_pulse)

        # Start the inferer
        self.job = Job(self.startInferer())
예제 #6
0
    def createInferringStatusView(self):
        self.dialog = Gtk.Dialog(title=_("Execution of the inferring process"),
                                 flags=0,
                                 buttons=None)

        mainTable = Gtk.Table(rows=5, columns=4, homogeneous=False)

        # Insert the current Hypothesis of the automata
        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(500, 500)
        mainTable.attach(self.xdotWidget,
                         0,
                         2,
                         0,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the updated list of requests and associated responses
        scroll_requests = Gtk.ScrolledWindow()
        self.treestore_queries = Gtk.TreeStore(
            str, str, str)  # queries, responses, color
        treeview_queries = Gtk.TreeView(self.treestore_queries)
        treeview_queries.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        treeview_queries.set_size_request(500, 500)
        #        treeview_queries.connect('button-press-event', self.button_press_on_transitions)
        cell = Gtk.CellRendererText()
        # col : membership queries
        col_queries_querie = Gtk.TreeViewColumn(_("Membership queries"))
        col_queries_querie.pack_start(cell, True)
        col_queries_querie.add_attribute(cell, "text", 0)
        treeview_queries.append_column(col_queries_querie)
        # col : responses to queries
        column_queries_responses = Gtk.TreeViewColumn(_("Responses"))
        column_queries_responses.pack_start(cell, True)
        column_queries_responses.add_attribute(cell, "text", 1)
        treeview_queries.append_column(column_queries_responses)
        scroll_requests.add(treeview_queries)
        scroll_requests.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scroll_requests.show()
        mainTable.attach(scroll_requests,
                         2,
                         4,
                         0,
                         4,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Progress bar
        self.progressbar = Gtk.ProgressBar()
        self.progressbar.show()
        #        # Insert the status message
        #        self.statusLabel = Gtk.Label(label="A number of X states has been created - Current turn contains N MQ")
        #        self.statusLabel.show()
        mainTable.attach(self.progressbar,
                         0,
                         2,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the stop button
        self.stopButton = Gtk.Button(_("Stop"))
        self.stopButton.show()
        self.stopButton.connect("clicked", self.stopInference)
        mainTable.attach(self.stopButton,
                         2,
                         3,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        # Insert the Save button
        self.saveButton = Gtk.Button(_("Save as Grammar"))
        self.saveButton.show()
        self.saveButton.connect("clicked", self.saveGrammar)
        mainTable.attach(self.saveButton,
                         3,
                         4,
                         4,
                         5,
                         xoptions=Gtk.AttachOptions.FILL,
                         yoptions=0,
                         xpadding=5,
                         ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()
예제 #7
0
파일: UISimulator.py 프로젝트: KurSh/netzob
    def __init__(self, netzob):
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Simulator.UISimulator.py')
        self.netzob = netzob

        self.actors = []
        self.selectedActor = None
        self.finish = False

        # Init each field with its saved value if it exist
        config = ConfigurationParser()

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Main panel
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.panel = gtk.Table(rows=5, columns=2, homogeneous=False)
        self.panel.show()

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Table hosting the form for a new actor
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.tableFormNewActor = gtk.Table(rows=4, columns=4, homogeneous=True)

        # Actor's name
        label_actorName = gtk.Label(_("Actor's name:"))
        label_actorName.show()
        self.entry_actorName = gtk.Entry()

        if config.get("simulating", "actorName") != None:
            self.entry_actorName.set_text(config.get("simulating", "actorName"))
        else:
            self.entry_actorName.set_text("")

        self.entry_actorName.show()
        self.tableFormNewActor.attach(label_actorName, 0, 1, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_actorName, 1, 2, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # Type of actor
        label_typeOfActor = gtk.Label(_("Type of actor:"))
        label_typeOfActor.show()
        self.combo_typeOfActor = gtk.combo_box_entry_new_text()
        self.combo_typeOfActor.set_model(gtk.ListStore(str))
        self.combo_typeOfActor.append_text("CLIENT")
        self.combo_typeOfActor.append_text("MASTER")

        if (config.get("simulating", "typeOfActor") == "CLIENT"):
            self.combo_typeOfActor.set_active(0)
        if (config.get("simulating", "typeOfActor") == "MASTER"):
            self.combo_typeOfActor.set_active(1)

        self.combo_typeOfActor.show()
        self.tableFormNewActor.attach(label_typeOfActor, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_typeOfActor, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Network layer actor
        label_typeOfNetworkActor = gtk.Label(_("Network layer:"))
        label_typeOfNetworkActor.show()
        self.combo_typeOfNetworkActor = gtk.combo_box_entry_new_text()
        self.combo_typeOfNetworkActor.set_model(gtk.ListStore(str))
        self.combo_typeOfNetworkActor.append_text("CLIENT")
        self.combo_typeOfNetworkActor.append_text("SERVER")

        if (config.get("simulating", "networkLayer") == "CLIENT"):
            self.combo_typeOfNetworkActor.set_active(0)
        if (config.get("simulating", "networkLayer") == "SERVER"):
            self.combo_typeOfNetworkActor.set_active(1)

        self.combo_typeOfNetworkActor.show()
        self.tableFormNewActor.attach(label_typeOfNetworkActor, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_typeOfNetworkActor, 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Network protocol
        label_protocolOfNetworkActor = gtk.Label(_("Network Protocol:"))
        label_protocolOfNetworkActor.show()
        self.combo_protocolOfNetworkActor = gtk.combo_box_entry_new_text()
        self.combo_protocolOfNetworkActor.set_model(gtk.ListStore(str))
        self.combo_protocolOfNetworkActor.append_text(_("TCP"))
        self.combo_protocolOfNetworkActor.append_text(_("UDP"))

        if (config.get("simulating", "networkProtocol") == "TCP"):
            self.combo_protocolOfNetworkActor.set_active(0)
        if (config.get("simulating", "networkProtocol") == "UDP"):
            self.combo_protocolOfNetworkActor.set_active(1)

        self.combo_protocolOfNetworkActor.show()
        self.tableFormNewActor.attach(label_protocolOfNetworkActor, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_protocolOfNetworkActor, 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # IP
        label_IP = gtk.Label(_("IP:"))
        label_IP.show()
        self.entry_IP = gtk.Entry()
        if (config.get("simulating", "ip") != None):
            self.entry_IP.set_text(config.get("simulating", "ip"))
        else:
            self.entry_IP.set_text("")

        self.entry_IP.show()
        self.tableFormNewActor.attach(label_IP, 2, 3, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_IP, 3, 4, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # S-PORT
        label_SPort = gtk.Label(_("Source Port:"))
        label_SPort.show()
        self.entry_SPort = gtk.Entry()
        self.entry_SPort.show()
        self.tableFormNewActor.attach(label_SPort, 2, 3, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_SPort, 3, 4, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # D-PORT
        label_Port = gtk.Label(_("Destination Port:"))
        label_Port.show()
        self.entry_Port = gtk.Entry()

        if (config.getInt("simulating", "port") != None):
            self.entry_Port.set_text(str(config.getInt("simulating", "port")))
        else:
            self.entry_Port.set_text("")

        self.entry_Port.show()
        self.tableFormNewActor.attach(label_Port, 2, 3, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_Port, 3, 4, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add actor button
        self.button_addActor = gtk.Button(gtk.STOCK_OK)
        self.button_addActor.set_label(_("Add actor"))
        self.button_addActor.connect("clicked", self.addActor)
        self.button_addActor.show()
        self.tableFormNewActor.attach(self.button_addActor, 3, 4, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.tableFormNewActor.show()
        self.panel.attach(self.tableFormNewActor, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Panel hosting the list of curent actors
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_listActiveActors = gtk.ScrolledWindow()
        self.treestore_listActiveActors = gtk.TreeStore(str, str)  # actor's name, typ

#        self.treestore_listActiveActors.append(None, ["actor1", "Server"])
#        self.treestore_listActiveActors.append(None, ["actor2", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor3", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor4", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor5", "Client"])

        treeview_listActiveActors = gtk.TreeView(self.treestore_listActiveActors)
        treeview_listActiveActors.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listActiveActors.set_size_request(300, -1)
        treeview_listActiveActors.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # main col
        column_listActiveActors_name = gtk.TreeViewColumn(_("Active actors"))
        column_listActiveActors_name.pack_start(cell, True)
        column_listActiveActors_name.set_attributes(cell, text=0)
        treeview_listActiveActors.append_column(column_listActiveActors_name)
        treeview_listActiveActors.show()
        scroll_listActiveActors.add(treeview_listActiveActors)
        scroll_listActiveActors.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listActiveActors.show()
        self.panel.attach(scroll_listActiveActors, 1, 2, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Inputs
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_inputs = gtk.ScrolledWindow()
        self.treestore_inputs = gtk.TreeStore(str, str, str)  # date, input message symbol

#        self.treestore_inputs.append(None, ["12:45:01", "message 1"])
#        self.treestore_inputs.append(None, ["12:45:11", "message 2"])
#        self.treestore_inputs.append(None, ["12:45:21", "message 3"])
#        self.treestore_inputs.append(None, ["12:45:23", "message 4"])
#        self.treestore_inputs.append(None, ["12:45:23", "message 5"])

        treeview_inputs = gtk.TreeView(self.treestore_inputs)
        treeview_inputs.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_inputs.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col date
        column_inputs_date = gtk.TreeViewColumn(_("Date"))
        column_inputs_date.pack_start(cell, True)
        column_inputs_date.set_attributes(cell, text=0)
        # col message
        column_inputs_message = gtk.TreeViewColumn(_("Received message"))
        column_inputs_message.pack_start(cell, True)
        column_inputs_message.set_attributes(cell, text=1)
        # col symbol
        column_inputs_symbol = gtk.TreeViewColumn(_("Symbol"))
        column_inputs_symbol.pack_start(cell, True)
        column_inputs_symbol.set_attributes(cell, text=2)
        treeview_inputs.append_column(column_inputs_date)
        treeview_inputs.append_column(column_inputs_message)
        treeview_inputs.append_column(column_inputs_symbol)
        treeview_inputs.show()
        scroll_inputs.add(treeview_inputs)
        scroll_inputs.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_inputs.show()
        self.panel.attach(scroll_inputs, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Outputs
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_outputs = gtk.ScrolledWindow()
        self.treestore_outputs = gtk.TreeStore(str, str, str)  # date, output message, symbol

#        self.treestore_outputs.append(None, ["12:45:01", "message 1"])
#        self.treestore_outputs.append(None, ["12:45:11", "message 2"])
#        self.treestore_outputs.append(None, ["12:45:21", "message 3"])
#        self.treestore_outputs.append(None, ["12:45:23", "message 4"])
#        self.treestore_outputs.append(None, ["12:45:23", "message 5"])

        treeview_outputs = gtk.TreeView(self.treestore_outputs)
        treeview_outputs.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_outputs.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col date
        column_outputs_date = gtk.TreeViewColumn(_("Date"))
        column_outputs_date.pack_start(cell, True)
        column_outputs_date.set_attributes(cell, text=0)
        # col message
        column_outputs_message = gtk.TreeViewColumn(_("Emitted message"))
        column_outputs_message.pack_start(cell, True)
        column_outputs_message.set_attributes(cell, text=1)
        # col symbol
        column_outputs_symbol = gtk.TreeViewColumn(_("Emitted message"))
        column_outputs_symbol.pack_start(cell, True)
        column_outputs_symbol.set_attributes(cell, text=2)
        treeview_outputs.append_column(column_outputs_date)
        treeview_outputs.append_column(column_outputs_message)
        treeview_outputs.append_column(column_outputs_symbol)
        treeview_outputs.show()
        scroll_outputs.add(treeview_outputs)
        scroll_outputs.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_outputs.show()
        self.panel.attach(scroll_outputs, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Memory
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_memory = gtk.ScrolledWindow()
        self.treestore_memory = gtk.TreeStore(str, str, str)  # name, type, value

#        self.treestore_memory.append(None, ["var1", "IP", "192.168.0.10"])
#        self.treestore_memory.append(None, ["var2", "WORD", "PSEUDO"])
#        self.treestore_memory.append(None, ["var3", "IP", "192.178.12.12"])

        treeview_memory = gtk.TreeView(self.treestore_memory)
        treeview_memory.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_memory.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col name
        column_memory_name = gtk.TreeViewColumn(_("Variable"))
        column_memory_name.pack_start(cell, True)
        column_memory_name.set_attributes(cell, text=0)
        # col type
        column_memory_type = gtk.TreeViewColumn(_("Type"))
        column_memory_type.pack_start(cell, True)
        column_memory_type.set_attributes(cell, text=1)
        # col Value
        column_memory_value = gtk.TreeViewColumn(_("Value"))
        column_memory_value.pack_start(cell, True)
        column_memory_value.set_attributes(cell, text=2)

        treeview_memory.append_column(column_memory_name)
        treeview_memory.append_column(column_memory_type)
        treeview_memory.append_column(column_memory_value)
        treeview_memory.show()
        scroll_memory.add(treeview_memory)
        scroll_memory.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_memory.show()
        self.panel.attach(scroll_memory, 0, 1, 3, 5, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Panel for the Model
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.xdotWidget = XDotWidget()

        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(300, 300)
        self.panel.attach(self.xdotWidget, 1, 2, 1, 4, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Break and stop
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.tableForBreakAndStop = gtk.Table(rows=1, columns=3, homogeneous=True)
        # Add start button
        self.button_startActor = gtk.Button(gtk.STOCK_OK)
        self.button_startActor.set_label(_("START"))
        self.button_startActor.connect("clicked", self.startSelectedActor)
        self.button_startActor.show()
        self.tableForBreakAndStop.attach(self.button_startActor, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add stop button
        self.button_stopActor = gtk.Button(gtk.STOCK_OK)
        self.button_stopActor.set_label(_("STOP"))
        self.button_stopActor.connect("clicked", self.stopSelectedActor)
        self.button_stopActor.show()
        self.tableForBreakAndStop.attach(self.button_stopActor, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        #Add delete actor button
        self.button_delActor = gtk.Button(gtk.STOCK_OK)
        self.button_delActor.set_label(_("DELETE"))
        self.button_delActor.connect("clicked", self.deleteSelectedActor)
        self.button_delActor.show()
        self.tableForBreakAndStop.attach(self.button_delActor, 2, 3, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.tableForBreakAndStop.show()
        self.panel.attach(self.tableForBreakAndStop, 1, 2, 4, 5, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # Update the GUI
        self.refreshGUI(1)
예제 #8
0
파일: UISimulator.py 프로젝트: KurSh/netzob
class UISimulator:

    #+----------------------------------------------
    #| Called when user select a new trace
    #+----------------------------------------------
    def new(self):
        pass

    def update(self):
        pass

    def clear(self):
        pass

    def kill(self):
        self.finish = True

    def save(self, file):
        self.log = logging.getLogger('netzob.Simuator.UISimulator.py')
        self.log.warn(_("The simulation process cannot be saved for the moment"))

    #+----------------------------------------------
    #| Constructor:
    #| @param netzob: the netzob main class
    #+----------------------------------------------
    def __init__(self, netzob):
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Simulator.UISimulator.py')
        self.netzob = netzob

        self.actors = []
        self.selectedActor = None
        self.finish = False

        # Init each field with its saved value if it exist
        config = ConfigurationParser()

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Main panel
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.panel = gtk.Table(rows=5, columns=2, homogeneous=False)
        self.panel.show()

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Table hosting the form for a new actor
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.tableFormNewActor = gtk.Table(rows=4, columns=4, homogeneous=True)

        # Actor's name
        label_actorName = gtk.Label(_("Actor's name:"))
        label_actorName.show()
        self.entry_actorName = gtk.Entry()

        if config.get("simulating", "actorName") != None:
            self.entry_actorName.set_text(config.get("simulating", "actorName"))
        else:
            self.entry_actorName.set_text("")

        self.entry_actorName.show()
        self.tableFormNewActor.attach(label_actorName, 0, 1, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_actorName, 1, 2, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # Type of actor
        label_typeOfActor = gtk.Label(_("Type of actor:"))
        label_typeOfActor.show()
        self.combo_typeOfActor = gtk.combo_box_entry_new_text()
        self.combo_typeOfActor.set_model(gtk.ListStore(str))
        self.combo_typeOfActor.append_text("CLIENT")
        self.combo_typeOfActor.append_text("MASTER")

        if (config.get("simulating", "typeOfActor") == "CLIENT"):
            self.combo_typeOfActor.set_active(0)
        if (config.get("simulating", "typeOfActor") == "MASTER"):
            self.combo_typeOfActor.set_active(1)

        self.combo_typeOfActor.show()
        self.tableFormNewActor.attach(label_typeOfActor, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_typeOfActor, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Network layer actor
        label_typeOfNetworkActor = gtk.Label(_("Network layer:"))
        label_typeOfNetworkActor.show()
        self.combo_typeOfNetworkActor = gtk.combo_box_entry_new_text()
        self.combo_typeOfNetworkActor.set_model(gtk.ListStore(str))
        self.combo_typeOfNetworkActor.append_text("CLIENT")
        self.combo_typeOfNetworkActor.append_text("SERVER")

        if (config.get("simulating", "networkLayer") == "CLIENT"):
            self.combo_typeOfNetworkActor.set_active(0)
        if (config.get("simulating", "networkLayer") == "SERVER"):
            self.combo_typeOfNetworkActor.set_active(1)

        self.combo_typeOfNetworkActor.show()
        self.tableFormNewActor.attach(label_typeOfNetworkActor, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_typeOfNetworkActor, 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Network protocol
        label_protocolOfNetworkActor = gtk.Label(_("Network Protocol:"))
        label_protocolOfNetworkActor.show()
        self.combo_protocolOfNetworkActor = gtk.combo_box_entry_new_text()
        self.combo_protocolOfNetworkActor.set_model(gtk.ListStore(str))
        self.combo_protocolOfNetworkActor.append_text(_("TCP"))
        self.combo_protocolOfNetworkActor.append_text(_("UDP"))

        if (config.get("simulating", "networkProtocol") == "TCP"):
            self.combo_protocolOfNetworkActor.set_active(0)
        if (config.get("simulating", "networkProtocol") == "UDP"):
            self.combo_protocolOfNetworkActor.set_active(1)

        self.combo_protocolOfNetworkActor.show()
        self.tableFormNewActor.attach(label_protocolOfNetworkActor, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.combo_protocolOfNetworkActor, 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # IP
        label_IP = gtk.Label(_("IP:"))
        label_IP.show()
        self.entry_IP = gtk.Entry()
        if (config.get("simulating", "ip") != None):
            self.entry_IP.set_text(config.get("simulating", "ip"))
        else:
            self.entry_IP.set_text("")

        self.entry_IP.show()
        self.tableFormNewActor.attach(label_IP, 2, 3, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_IP, 3, 4, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # S-PORT
        label_SPort = gtk.Label(_("Source Port:"))
        label_SPort.show()
        self.entry_SPort = gtk.Entry()
        self.entry_SPort.show()
        self.tableFormNewActor.attach(label_SPort, 2, 3, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_SPort, 3, 4, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # D-PORT
        label_Port = gtk.Label(_("Destination Port:"))
        label_Port.show()
        self.entry_Port = gtk.Entry()

        if (config.getInt("simulating", "port") != None):
            self.entry_Port.set_text(str(config.getInt("simulating", "port")))
        else:
            self.entry_Port.set_text("")

        self.entry_Port.show()
        self.tableFormNewActor.attach(label_Port, 2, 3, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        self.tableFormNewActor.attach(self.entry_Port, 3, 4, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add actor button
        self.button_addActor = gtk.Button(gtk.STOCK_OK)
        self.button_addActor.set_label(_("Add actor"))
        self.button_addActor.connect("clicked", self.addActor)
        self.button_addActor.show()
        self.tableFormNewActor.attach(self.button_addActor, 3, 4, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.tableFormNewActor.show()
        self.panel.attach(self.tableFormNewActor, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Panel hosting the list of curent actors
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_listActiveActors = gtk.ScrolledWindow()
        self.treestore_listActiveActors = gtk.TreeStore(str, str)  # actor's name, typ

#        self.treestore_listActiveActors.append(None, ["actor1", "Server"])
#        self.treestore_listActiveActors.append(None, ["actor2", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor3", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor4", "Client"])
#        self.treestore_listActiveActors.append(None, ["actor5", "Client"])

        treeview_listActiveActors = gtk.TreeView(self.treestore_listActiveActors)
        treeview_listActiveActors.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listActiveActors.set_size_request(300, -1)
        treeview_listActiveActors.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # main col
        column_listActiveActors_name = gtk.TreeViewColumn(_("Active actors"))
        column_listActiveActors_name.pack_start(cell, True)
        column_listActiveActors_name.set_attributes(cell, text=0)
        treeview_listActiveActors.append_column(column_listActiveActors_name)
        treeview_listActiveActors.show()
        scroll_listActiveActors.add(treeview_listActiveActors)
        scroll_listActiveActors.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listActiveActors.show()
        self.panel.attach(scroll_listActiveActors, 1, 2, 0, 1, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Inputs
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_inputs = gtk.ScrolledWindow()
        self.treestore_inputs = gtk.TreeStore(str, str, str)  # date, input message symbol

#        self.treestore_inputs.append(None, ["12:45:01", "message 1"])
#        self.treestore_inputs.append(None, ["12:45:11", "message 2"])
#        self.treestore_inputs.append(None, ["12:45:21", "message 3"])
#        self.treestore_inputs.append(None, ["12:45:23", "message 4"])
#        self.treestore_inputs.append(None, ["12:45:23", "message 5"])

        treeview_inputs = gtk.TreeView(self.treestore_inputs)
        treeview_inputs.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_inputs.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col date
        column_inputs_date = gtk.TreeViewColumn(_("Date"))
        column_inputs_date.pack_start(cell, True)
        column_inputs_date.set_attributes(cell, text=0)
        # col message
        column_inputs_message = gtk.TreeViewColumn(_("Received message"))
        column_inputs_message.pack_start(cell, True)
        column_inputs_message.set_attributes(cell, text=1)
        # col symbol
        column_inputs_symbol = gtk.TreeViewColumn(_("Symbol"))
        column_inputs_symbol.pack_start(cell, True)
        column_inputs_symbol.set_attributes(cell, text=2)
        treeview_inputs.append_column(column_inputs_date)
        treeview_inputs.append_column(column_inputs_message)
        treeview_inputs.append_column(column_inputs_symbol)
        treeview_inputs.show()
        scroll_inputs.add(treeview_inputs)
        scroll_inputs.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_inputs.show()
        self.panel.attach(scroll_inputs, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Outputs
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_outputs = gtk.ScrolledWindow()
        self.treestore_outputs = gtk.TreeStore(str, str, str)  # date, output message, symbol

#        self.treestore_outputs.append(None, ["12:45:01", "message 1"])
#        self.treestore_outputs.append(None, ["12:45:11", "message 2"])
#        self.treestore_outputs.append(None, ["12:45:21", "message 3"])
#        self.treestore_outputs.append(None, ["12:45:23", "message 4"])
#        self.treestore_outputs.append(None, ["12:45:23", "message 5"])

        treeview_outputs = gtk.TreeView(self.treestore_outputs)
        treeview_outputs.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_outputs.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col date
        column_outputs_date = gtk.TreeViewColumn(_("Date"))
        column_outputs_date.pack_start(cell, True)
        column_outputs_date.set_attributes(cell, text=0)
        # col message
        column_outputs_message = gtk.TreeViewColumn(_("Emitted message"))
        column_outputs_message.pack_start(cell, True)
        column_outputs_message.set_attributes(cell, text=1)
        # col symbol
        column_outputs_symbol = gtk.TreeViewColumn(_("Emitted message"))
        column_outputs_symbol.pack_start(cell, True)
        column_outputs_symbol.set_attributes(cell, text=2)
        treeview_outputs.append_column(column_outputs_date)
        treeview_outputs.append_column(column_outputs_message)
        treeview_outputs.append_column(column_outputs_symbol)
        treeview_outputs.show()
        scroll_outputs.add(treeview_outputs)
        scroll_outputs.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_outputs.show()
        self.panel.attach(scroll_outputs, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Memory
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        scroll_memory = gtk.ScrolledWindow()
        self.treestore_memory = gtk.TreeStore(str, str, str)  # name, type, value

#        self.treestore_memory.append(None, ["var1", "IP", "192.168.0.10"])
#        self.treestore_memory.append(None, ["var2", "WORD", "PSEUDO"])
#        self.treestore_memory.append(None, ["var3", "IP", "192.178.12.12"])

        treeview_memory = gtk.TreeView(self.treestore_memory)
        treeview_memory.get_selection().set_mode(gtk.SELECTION_NONE)
        treeview_memory.set_size_request(300, -1)
#        treeview_listActiveActors.connect("cursor-changed", self.packet_details)
        cell = gtk.CellRendererText()
        # col name
        column_memory_name = gtk.TreeViewColumn(_("Variable"))
        column_memory_name.pack_start(cell, True)
        column_memory_name.set_attributes(cell, text=0)
        # col type
        column_memory_type = gtk.TreeViewColumn(_("Type"))
        column_memory_type.pack_start(cell, True)
        column_memory_type.set_attributes(cell, text=1)
        # col Value
        column_memory_value = gtk.TreeViewColumn(_("Value"))
        column_memory_value.pack_start(cell, True)
        column_memory_value.set_attributes(cell, text=2)

        treeview_memory.append_column(column_memory_name)
        treeview_memory.append_column(column_memory_type)
        treeview_memory.append_column(column_memory_value)
        treeview_memory.show()
        scroll_memory.add(treeview_memory)
        scroll_memory.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_memory.show()
        self.panel.attach(scroll_memory, 0, 1, 3, 5, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Panel for the Model
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.xdotWidget = XDotWidget()

        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(300, 300)
        self.panel.attach(self.xdotWidget, 1, 2, 1, 4, xoptions=gtk.FILL, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # Break and stop
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.tableForBreakAndStop = gtk.Table(rows=1, columns=3, homogeneous=True)
        # Add start button
        self.button_startActor = gtk.Button(gtk.STOCK_OK)
        self.button_startActor.set_label(_("START"))
        self.button_startActor.connect("clicked", self.startSelectedActor)
        self.button_startActor.show()
        self.tableForBreakAndStop.attach(self.button_startActor, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add stop button
        self.button_stopActor = gtk.Button(gtk.STOCK_OK)
        self.button_stopActor.set_label(_("STOP"))
        self.button_stopActor.connect("clicked", self.stopSelectedActor)
        self.button_stopActor.show()
        self.tableForBreakAndStop.attach(self.button_stopActor, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        #Add delete actor button
        self.button_delActor = gtk.Button(gtk.STOCK_OK)
        self.button_delActor.set_label(_("DELETE"))
        self.button_delActor.connect("clicked", self.deleteSelectedActor)
        self.button_delActor.show()
        self.tableForBreakAndStop.attach(self.button_delActor, 2, 3, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.tableForBreakAndStop.show()
        self.panel.attach(self.tableForBreakAndStop, 1, 2, 4, 5, xoptions=gtk.FILL | gtk.EXPAND, yoptions=gtk.FILL | gtk.EXPAND, xpadding=5, ypadding=5)

        # Update the GUI
        self.refreshGUI(1)

    #+----------------------------------------------
    #| startSelectedActor:
    #| Starts the selected actor
    #+----------------------------------------------
    def startSelectedActor(self, widget):
        if self.selectedActor == None:
            return

        self.log.info(_("Start the actor {0}").format(self.selectedActor.getName()))
        self.selectedActor.start()

    #+----------------------------------------------
    #| stopSelectedActor:
    #| Stops the selected actor
    #+----------------------------------------------
    def stopSelectedActor(self, widget):
        if self.selectedActor == None:
            return

        self.log.info(_("Stop the actor {0}").format(self.selectedActor.getName()))
        self.selectedActor.stop()

    #+----------------------------------------------
    #| deleteSelectedActor:
    #| Delete the selected actor (if stopped)
    #+----------------------------------------------
    def deleteSelectedActor(self, widget):
        if self.selectedActor == None:
            return

        if self.selectedActor.isActive():
            self.log.info(_("Impossible to delete an active actor. It must be stopped before"))
            return

        self.log.info(_("Delete the actor {0}").format(self.selectedActor.getName()))
        self.actors.remove(self.selectedActor)
        self.treestore_listActiveActors.clear()
        self.selectedActor = None

    #+----------------------------------------------
    #| addActor:
    #| Creates and registers an actor based on the form
    #+----------------------------------------------
    def addActor(self, widget):
        # Retrieves the value of the form to create the actor
        actorName = self.entry_actorName.get_text()
        actorGrammarType = self.combo_typeOfActor.get_active_text()
        actorNetworkProtocol = self.combo_protocolOfNetworkActor.get_active_text()
        actorNetworkType = self.combo_typeOfNetworkActor.get_active_text()
        actorIP = self.entry_IP.get_text()
        actorSPort = self.entry_SPort.get_text()
        actorPort = self.entry_Port.get_text()

        # We verify we have everything and the actor's name is unique
        for actor in self.actors:
            if actor.getName() == actorName:
                self.log.warn(_("Impossible to create the requested actor since another one has the same name"))
                return

        self.log.info(_("Will add an actor named {0}").format(actorName))

        grammar = self.netzob.getCurrentProject().getGrammar()
        # We create an actor based on given informations
        if actorGrammarType == "MASTER":
            isMaster = True
        else:
            isMaster = False

        # Create the network layer
        if actorNetworkType == "SERVER":
            communicationChannel = NetworkServer.NetworkServer(actorIP, actorNetworkProtocol, int(actorPort), int(actorSPort))
        else:
            communicationChannel = NetworkClient.NetworkClient(actorIP, actorNetworkProtocol, int(actorPort), int(actorSPort))

        # Create the abstraction layer for this connection
        abstractionLayer = AbstractionLayer.AbstractionLayer(communicationChannel, self.netzob.getCurrentProject().getVocabulary(), Memory(self.netzob.getCurrentProject().getVocabulary().getVariables()))

        # And we create an MMSTD visitor for this
        visitor = MMSTDVisitor.MMSTDVisitor(actorName, grammar.getAutomata(), isMaster, abstractionLayer)

        # add the actor to the list
        self.actors.append(visitor)

        # update the list of actors
        self.updateListOfActors()

#        # we save the form in the configuration considering its a valid one
#        config = ConfigurationParser()
#        config.set("simulating", "actorName", actorName)
#        config.set("simulating", "typeOfActor", actorGrammarType)
#        config.set("simulating", "networkLayer", actorNetworkType)
#        config.set("simulating", "networkProtocol", actorNetworkProtocol)
#        config.set("simulating", "ip", actorIP)
#        config.set("simulating", "port", int(actorPort))

    def updateListOfActors(self):
#        self.treestore_listActiveActors.clear()
        for actor in self.actors:

            # Do we add this actor ?
            treestoreActor = None
            for line in self.treestore_listActiveActors:
                if line[0] == actor.getName():
                    treestoreActor = self.treestore_listActiveActors.get_iter(line.path)
                    found = True

            if treestoreActor == None:
                treestoreActor = self.treestore_listActiveActors.append(None, [actor.getName(), "type"])

            # Retrieve generates instances by the communication channel
            communicationChannel = actor.getAbstractionLayer().getCommunicationChannel()
            instances = communicationChannel.getGeneratedInstances()
            for instance in instances:

                # do we add this instance
                found = False
                for line in self.treestore_listActiveActors:
                    if line[0] == instance.getName():
                        found = True
                if not found:
                    self.treestore_listActiveActors.append(treestoreActor, [instance.getName(), "type"])

    def actorDetails(self, treeview):
        self.selectedActor = None
        actorName = ""
        (model, iter) = treeview.get_selection().get_selected()

        if(iter):
            if(model.iter_is_valid(iter)):
                actorName = model.get_value(iter, 0)
                #actorType = model.get_value(iter, 1)

        for actor in self.actors:
            if actor.getName() == actorName:
                self.selectedActor = actor
            # Retrieve generates instances by the communication channel
            communicationChannel = actor.getAbstractionLayer().getCommunicationChannel()
            instances = communicationChannel.getGeneratedInstances()
            for instance in instances:
                if instance.getName() == actorName:
                    self.selectedActor = instance

        if self.selectedActor == None:
            self.log.warn(_("Impossible to retrieve the requested actor"))
            return

        # Now we update the GUI based on the actor
        self.updateGUIForActor()

    def updateGUIForActor(self):
        if self.selectedActor == None:
            return

        # First we display its model
        automata = self.selectedActor.getModel()
        self.xdotWidget.drawAutomata(automata)
        self.xdotWidget.show_all()

        # Now we display its received message
        self.treestore_inputs.clear()
        for inputMessage in self.selectedActor.getInputMessages():
            self.treestore_inputs.append(None, inputMessage)

        # Now we display its emitted message
        self.treestore_outputs.clear()
        for outputMessage in self.selectedActor.getOutputMessages():
            self.treestore_outputs.append(None, outputMessage)

        # Now we update its memory
        self.treestore_memory.clear()
        for memory_id in self.selectedActor.getMemory().recallAll().keys():
            self.treestore_memory.append(None, [memory_id, "type", self.selectedActor.getMemory().recallAll()[memory_id]])

    def refreshGUI(self, tempo=0.5):
#TODO
#        if not self.finish:
#            threading.Timer(tempo, self.refreshGUI, [tempo]).start()
#            self.updateListOfActors()
#            self.updateGUIForActor()
        pass
예제 #9
0
    def __init__(self, netzob):
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Inference.Grammar.UIGrammarInference.py')
        self.netzob = netzob

        if netzob.getCurrentProject() != None:
            self.grammar = netzob.getCurrentProject().getGrammar()

        self.states = []
        self.initialState = None
        self.transitions = []

        self.panel = gtk.HBox(False, spacing=0)
        self.panel.show()

        # ----------------------------------------
        # Left Panel
        # ----------------------------------------
        self.mainPanel = gtk.VBox(False, spacing=0)
        self.mainPanel.show()

        # First we add a table
        leftFormTable = gtk.Table(rows=7, columns=2, homogeneous=False)

        # We add the button for the automatic inference process
        self.grammarAutomaticInferenceButton = gtk.Button(_("Open wizard for automatic inference"))
        self.grammarAutomaticInferenceButton.connect("clicked", self.showAutomaticInferencePanel)
        self.grammarAutomaticInferenceButton.show()
        self.grammarAutomaticInferenceButton.set_sensitive(True)
        leftFormTable.attach(self.grammarAutomaticInferenceButton, 0, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add the button to abstract the current grammar
        self.grammarAbstractionButton = gtk.Button(_("Abstract current grammar"))
        self.grammarAbstractionButton.connect("clicked", self.showAbstractionPanel)
        self.grammarAbstractionButton.show()
        self.grammarAbstractionButton.set_sensitive(True)
        leftFormTable.attach(self.grammarAbstractionButton, 0, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # CREATE A STATE
        self.createStateButton = gtk.Button(_("Create a state"))
        self.createStateButton.show()
        self.createStateButton.connect("clicked", self.createState)
        self.createStateButton.set_sensitive(False)
        leftFormTable.attach(self.createStateButton, 0, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # The list of current states
        scroll_listStates = gtk.ScrolledWindow()
        self.treestore_listStates = gtk.TreeStore(str, str, str)  # id, name, type
        treeview_listStates = gtk.TreeView(self.treestore_listStates)
        treeview_listStates.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listStates.set_size_request(-1, 250)
        treeview_listStates.connect('button-press-event', self.button_press_on_states)
#        treeview_listStates.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # main col
        column_listStates_name = gtk.TreeViewColumn(_("State name"))
        column_listStates_name.pack_start(cell, True)
        column_listStates_name.set_attributes(cell, text=1)
        treeview_listStates.append_column(column_listStates_name)
        # main col
        column_listStates_type = gtk.TreeViewColumn(_("State Type"))
        column_listStates_type.pack_start(cell, True)
        column_listStates_type.set_attributes(cell, text=2)
        treeview_listStates.append_column(column_listStates_type)
        treeview_listStates.show()
        scroll_listStates.add(treeview_listStates)
        scroll_listStates.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listStates.show()
        leftFormTable.attach(scroll_listStates, 0, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # CREATE A TRANSITION
        self.createTransitionButton = gtk.Button(_("Create a transition"))
        self.createTransitionButton.show()
        self.createTransitionButton.connect("clicked", self.createTransition)
        self.createTransitionButton.set_sensitive(False)
        leftFormTable.attach(self.createTransitionButton, 0, 2, 4, 5, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # The list of current transitions
        scroll_listTransitions = gtk.ScrolledWindow()
        self.treestore_listTransitions = gtk.TreeStore(str, str, str, str, str)  # id, name, start state, end state, type
        treeview_listTransitions = gtk.TreeView(self.treestore_listTransitions)
        treeview_listTransitions.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listTransitions.set_size_request(-1, 250)
        treeview_listTransitions.connect('button-press-event', self.button_press_on_transitions)
#        treeview_listStates.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # col : name of the transition
        column_listTransitions_name = gtk.TreeViewColumn(_("Transition name"))
        column_listTransitions_name.pack_start(cell, True)
        column_listTransitions_name.set_attributes(cell, text=1)
        treeview_listTransitions.append_column(column_listTransitions_name)
        # col : start state
        column_listTransitions_startState = gtk.TreeViewColumn(_("Start state"))
        column_listTransitions_startState.pack_start(cell, True)
        column_listTransitions_startState.set_attributes(cell, text=2)
        treeview_listTransitions.append_column(column_listTransitions_startState)
        # col : end state
        column_listTransitions_endState = gtk.TreeViewColumn(_("End state"))
        column_listTransitions_endState.pack_start(cell, True)
        column_listTransitions_endState.set_attributes(cell, text=3)
        treeview_listTransitions.append_column(column_listTransitions_endState)
        # col : type
        column_listTransitions_type = gtk.TreeViewColumn(_("Type"))
        column_listTransitions_type.pack_start(cell, True)
        column_listTransitions_type.set_attributes(cell, text=4)
        treeview_listTransitions.append_column(column_listTransitions_type)
        treeview_listTransitions.show()
        scroll_listTransitions.add(treeview_listTransitions)
        scroll_listTransitions.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listTransitions.show()
        leftFormTable.attach(scroll_listTransitions, 0, 2, 5, 7, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        leftFormTable.show()
        self.mainPanel.pack_start(leftFormTable, False, False, 0)

        self.panel.pack_start(self.mainPanel, False, False, 0)

        # ----------------------------------------
        # Right panel
        # ----------------------------------------
        self.rightPanel = gtk.HPaned()
        self.rightPanel.show()
        self.panel.pack_start(self.rightPanel, True, True, 0)

        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
#        self.xdotWidget.set_size_request(500, -1)

        self.rightPanel.add(self.xdotWidget)
예제 #10
0
class UIGrammarInference:

    #+----------------------------------------------
    #| Called when user select a new trace
    #+----------------------------------------------
    def new(self):
        pass

    def update(self):
        self.updateInterface()
        self.updateListStates()
        self.updateListTransitions()
        self.updateXDot()

    def clear(self):
        pass

    def kill(self):
        pass

    def save(self, file):
        pass

    #+----------------------------------------------
    #| Constructor:
    #| @param netzob: the netzob main class
    #+----------------------------------------------
    def __init__(self, netzob):
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Inference.Grammar.UIGrammarInference.py')
        self.netzob = netzob

        if netzob.getCurrentProject() != None:
            self.grammar = netzob.getCurrentProject().getGrammar()

        self.states = []
        self.initialState = None
        self.transitions = []

        self.panel = gtk.HBox(False, spacing=0)
        self.panel.show()

        # ----------------------------------------
        # Left Panel
        # ----------------------------------------
        self.mainPanel = gtk.VBox(False, spacing=0)
        self.mainPanel.show()

        # First we add a table
        leftFormTable = gtk.Table(rows=7, columns=2, homogeneous=False)

        # We add the button for the automatic inference process
        self.grammarAutomaticInferenceButton = gtk.Button(_("Open wizard for automatic inference"))
        self.grammarAutomaticInferenceButton.connect("clicked", self.showAutomaticInferencePanel)
        self.grammarAutomaticInferenceButton.show()
        self.grammarAutomaticInferenceButton.set_sensitive(True)
        leftFormTable.attach(self.grammarAutomaticInferenceButton, 0, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Add the button to abstract the current grammar
        self.grammarAbstractionButton = gtk.Button(_("Abstract current grammar"))
        self.grammarAbstractionButton.connect("clicked", self.showAbstractionPanel)
        self.grammarAbstractionButton.show()
        self.grammarAbstractionButton.set_sensitive(True)
        leftFormTable.attach(self.grammarAbstractionButton, 0, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # CREATE A STATE
        self.createStateButton = gtk.Button(_("Create a state"))
        self.createStateButton.show()
        self.createStateButton.connect("clicked", self.createState)
        self.createStateButton.set_sensitive(False)
        leftFormTable.attach(self.createStateButton, 0, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # The list of current states
        scroll_listStates = gtk.ScrolledWindow()
        self.treestore_listStates = gtk.TreeStore(str, str, str)  # id, name, type
        treeview_listStates = gtk.TreeView(self.treestore_listStates)
        treeview_listStates.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listStates.set_size_request(-1, 250)
        treeview_listStates.connect('button-press-event', self.button_press_on_states)
#        treeview_listStates.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # main col
        column_listStates_name = gtk.TreeViewColumn(_("State name"))
        column_listStates_name.pack_start(cell, True)
        column_listStates_name.set_attributes(cell, text=1)
        treeview_listStates.append_column(column_listStates_name)
        # main col
        column_listStates_type = gtk.TreeViewColumn(_("State Type"))
        column_listStates_type.pack_start(cell, True)
        column_listStates_type.set_attributes(cell, text=2)
        treeview_listStates.append_column(column_listStates_type)
        treeview_listStates.show()
        scroll_listStates.add(treeview_listStates)
        scroll_listStates.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listStates.show()
        leftFormTable.attach(scroll_listStates, 0, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # CREATE A TRANSITION
        self.createTransitionButton = gtk.Button(_("Create a transition"))
        self.createTransitionButton.show()
        self.createTransitionButton.connect("clicked", self.createTransition)
        self.createTransitionButton.set_sensitive(False)
        leftFormTable.attach(self.createTransitionButton, 0, 2, 4, 5, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # The list of current transitions
        scroll_listTransitions = gtk.ScrolledWindow()
        self.treestore_listTransitions = gtk.TreeStore(str, str, str, str, str)  # id, name, start state, end state, type
        treeview_listTransitions = gtk.TreeView(self.treestore_listTransitions)
        treeview_listTransitions.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listTransitions.set_size_request(-1, 250)
        treeview_listTransitions.connect('button-press-event', self.button_press_on_transitions)
#        treeview_listStates.connect("cursor-changed", self.actorDetails)
        cell = gtk.CellRendererText()
        # col : name of the transition
        column_listTransitions_name = gtk.TreeViewColumn(_("Transition name"))
        column_listTransitions_name.pack_start(cell, True)
        column_listTransitions_name.set_attributes(cell, text=1)
        treeview_listTransitions.append_column(column_listTransitions_name)
        # col : start state
        column_listTransitions_startState = gtk.TreeViewColumn(_("Start state"))
        column_listTransitions_startState.pack_start(cell, True)
        column_listTransitions_startState.set_attributes(cell, text=2)
        treeview_listTransitions.append_column(column_listTransitions_startState)
        # col : end state
        column_listTransitions_endState = gtk.TreeViewColumn(_("End state"))
        column_listTransitions_endState.pack_start(cell, True)
        column_listTransitions_endState.set_attributes(cell, text=3)
        treeview_listTransitions.append_column(column_listTransitions_endState)
        # col : type
        column_listTransitions_type = gtk.TreeViewColumn(_("Type"))
        column_listTransitions_type.pack_start(cell, True)
        column_listTransitions_type.set_attributes(cell, text=4)
        treeview_listTransitions.append_column(column_listTransitions_type)
        treeview_listTransitions.show()
        scroll_listTransitions.add(treeview_listTransitions)
        scroll_listTransitions.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listTransitions.show()
        leftFormTable.attach(scroll_listTransitions, 0, 2, 5, 7, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        leftFormTable.show()
        self.mainPanel.pack_start(leftFormTable, False, False, 0)

        self.panel.pack_start(self.mainPanel, False, False, 0)

        # ----------------------------------------
        # Right panel
        # ----------------------------------------
        self.rightPanel = gtk.HPaned()
        self.rightPanel.show()
        self.panel.pack_start(self.rightPanel, True, True, 0)

        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
#        self.xdotWidget.set_size_request(500, -1)

        self.rightPanel.add(self.xdotWidget)

    #+-----------------------------------------------------------------------+
    #| createTransition:
    #|     Display the GUI for the creation of a transition and create it
    #+-----------------------------------------------------------------------+
    def createTransition(self, widget):
        self.log.debug(_("Opening the dialog for the creation of a new transition"))
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Definition of the new transition"))

        # Create the ID of the new transition
        transitionID = str(uuid.uuid4())

        mainTable = gtk.Table(rows=5, columns=2, homogeneous=False)

        transitionIDLabel = gtk.Label(_("ID:"))
        transitionIDLabel.show()
        transitionIDValueLabel = gtk.Label(transitionID)
        transitionIDValueLabel.show()
        mainTable.attach(transitionIDLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionIDValueLabel, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        transitionNameLabel = gtk.Label(_("Name:"))
        transitionNameLabel.show()
        transitionNameEntry = gtk.Entry()
        transitionNameEntry.show()
        mainTable.attach(transitionNameLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionNameEntry, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        transitionTypeLabel = gtk.Label(_("Type:"))
        transitionTypeLabel.show()
        transitionTypeCombo = gtk.ComboBox()
        transitionTypeCombo.set_model(gtk.ListStore(str))
        transitionTypeComboCell = gtk.CellRendererText()
        transitionTypeCombo.pack_start(transitionTypeComboCell, True)
        transitionTypeCombo.add_attribute(transitionTypeComboCell, 'text', 0)
        possible_choices = ["SemiStochastic", "OpenChannel", "CloseChannel"]
        for i in range(len(possible_choices)):
            transitionTypeCombo.append_text(str(possible_choices[i]))
        transitionTypeCombo.show()
        mainTable.attach(transitionTypeLabel, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionTypeCombo, 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        transitionStartStateLabel = gtk.Label(_("Start State:"))
        transitionStartStateLabel.show()
        transitionStartStateCombo = gtk.ComboBox()
        transitionStartStateCombo.set_model(gtk.ListStore(str, str))
        transitionStartStateCell = gtk.CellRendererText()
        transitionStartStateCombo.pack_start(transitionStartStateCell, True)
        transitionStartStateCombo.add_attribute(transitionStartStateCell, 'text', 0)

        for state in self.getAutomata().getStates():
            transitionStartStateCombo.get_model().append([state.getName(), str(state.getID())])
        transitionStartStateCombo.show()
        mainTable.attach(transitionStartStateLabel, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionStartStateCombo, 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        transitionStopStateLabel = gtk.Label(_("Stop State:"))
        transitionStopStateLabel.show()
        transitionStopStateCombo = gtk.ComboBox()
        transitionStopStateCombo.set_model(gtk.ListStore(str, str))
        transitionStopStateComboCell = gtk.CellRendererText()
        transitionStopStateCombo.pack_start(transitionStopStateComboCell, True)
        transitionStopStateCombo.add_attribute(transitionStopStateComboCell, 'text', 0)

        for state in self.getAutomata().getStates():
            transitionStopStateCombo.get_model().append([state.getName(), str(state.getID())])
        transitionStopStateCombo.show()
        mainTable.attach(transitionStopStateLabel, 0, 1, 4, 5, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionStopStateCombo, 1, 2, 4, 5, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result != gtk.RESPONSE_OK:
            return

        # We retrieve the selected values
        transitionName = transitionNameEntry.get_text()
        transitionType = transitionTypeCombo.get_model()[transitionTypeCombo.get_active()][0]
        idStartState = transitionStartStateCombo.get_model()[transitionStartStateCombo.get_active()][1]
        idStopState = transitionStopStateCombo.get_model()[transitionStopStateCombo.get_active()][1]
        startState = None
        stopState = None
        for state in self.getAutomata().getStates():
            if str(state.getID()) == idStartState:
                startState = state
            if str(state.getID()) == idStopState:
                stopState = state

        if startState == None or stopState == None:
            self.log.warn(_("The states of the transition are not valid."))
            return

        dialog.destroy()
        createdTransition = None
        if transitionType == "SemiStochastic":
            createdTransition = self.createSemiStochasticTransition(transitionID, transitionName, startState, stopState)
        elif transitionType == "OpenChannel":
            createdTransition = self.createOpenChannelTransition(transitionID, transitionName, startState, stopState)
        elif transitionType == "CloseChannel":
            createdTransition = self.createCloseChannelTransition(transitionID, transitionName, startState, stopState)
        else:
            self.log.warn(_("Impossible to create the requested transition since the type is unknown"))

        if createdTransition != None:
            self.getAutomata().addTransition(createdTransition)
            self.updateListTransitions()
            self.updateXDot()

    def createOpenChannelTransition(self, transitionID, transitionName, startState, stopState):
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Definition of an OpenChannel Transition"))

        mainTable = gtk.Table(rows=2, columns=2, homogeneous=False)
        transitionConnectionTimeLabel = gtk.Label(_("Connection time (ms):"))
        transitionConnectionTimeLabel.show()
        transitionConnectionTimeEntry = gtk.Entry()
        transitionConnectionTimeEntry.show()
        mainTable.attach(transitionConnectionTimeLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionConnectionTimeEntry, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        transitionMaxAttemptsLabel = gtk.Label(_("Maximum number of connection attempts:"))
        transitionMaxAttemptsLabel.show()
        transitionMaxAttemptsEntry = gtk.Entry()
        transitionMaxAttemptsEntry.show()
        mainTable.attach(transitionMaxAttemptsLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionMaxAttemptsEntry, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result != gtk.RESPONSE_OK:
            dialog.destroy()
            return None

        connectionTime = int(transitionConnectionTimeEntry.get_text())
        maxNumberOfAttempt = int(transitionMaxAttemptsEntry.get_text())
        transition = OpenChannelTransition(transitionID, transitionName, startState, stopState, connectionTime, maxNumberOfAttempt)
        startState.registerTransition(transition)
        dialog.destroy()
        return transition

    def createCloseChannelTransition(self, transitionID, transitionName, startState, stopState):
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Definition of an CloseChannel Transition"))

        mainTable = gtk.Table(rows=1, columns=2, homogeneous=False)
        transitionDisconnectionTimeLabel = gtk.Label(_("Disconnection time (ms):"))
        transitionDisconnectionTimeLabel.show()
        transitionDisconnectionTimeEntry = gtk.Entry()
        transitionDisconnectionTimeEntry.show()
        mainTable.attach(transitionDisconnectionTimeLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionDisconnectionTimeEntry, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result != gtk.RESPONSE_OK:
            dialog.destroy()
            return None

        disconnectionTime = int(transitionDisconnectionTimeEntry.get_text())
        transition = CloseChannelTransition(transitionID, transitionName, startState, stopState, disconnectionTime)
        startState.registerTransition(transition)
        dialog.destroy()
        return transition

    def createSemiStochasticTransition(self, transitionID, transitionName, startState, stopState):
        symbols = self.getVocabulary().getSymbols()

        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Definition of a SemiStochastic Transition"))

        mainTable = gtk.Table(rows=9, columns=2, homogeneous=False)

        inputSymbolTitle = gtk.Label(_("Define input symbol"))
        inputSymbolTitle.show()
        mainTable.attach(inputSymbolTitle, 0, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        inputSymbolLabel = gtk.Label(_("Dictionary entry:"))
        inputSymbolLabel.show()

        inputSymbolCombo = gtk.ComboBox()
        inputSymbolCombo.set_model(gtk.ListStore(str, str))  # entry name, entry id
        inputSymbolComboCell = gtk.CellRendererText()
        inputSymbolCombo.pack_start(inputSymbolComboCell, True)
        inputSymbolCombo.add_attribute(inputSymbolComboCell, 'text', 0)

        for symbol in symbols:
            inputSymbolCombo.get_model().append([symbol.getName(), str(symbol.getID())])
        inputSymbolCombo.get_model().append(["EmptySymbol", EmptySymbol.TYPE])
        inputSymbolCombo.get_model().append(["UnknownSymbol", UnknownSymbol.TYPE])
        inputSymbolCombo.show()

        mainTable.attach(inputSymbolLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(inputSymbolCombo, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        outputSymbolTitle = gtk.Label(_("Define output symbols"))
        outputSymbolTitle.show()
        mainTable.attach(outputSymbolTitle, 0, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        outputSymbolLabel = gtk.Label(_("Dictionary entry:"))
        outputSymbolLabel.show()

        outputSymbolCombo = gtk.ComboBox()
        outputSymbolCombo.set_model(gtk.ListStore(str, str, str))  # symbol type, entry name, entry id
        outputSymbolComboCell = gtk.CellRendererText()
        outputSymbolCombo.pack_start(outputSymbolComboCell, True)
        outputSymbolCombo.add_attribute(outputSymbolComboCell, 'text', 1)

        for symbol in symbols:
            outputSymbolCombo.get_model().append([symbol.getType(), symbol.getName(), str(symbol.getID())])
        outputSymbolCombo.show()
        outputSymbolCombo.get_model().append([EmptySymbol.TYPE, "EmptySymbol", ""])
        outputSymbolCombo.get_model().append([UnknownSymbol.TYPE, "UnknownSymbol", ""])

        mainTable.attach(outputSymbolLabel, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(outputSymbolCombo, 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        outputTimeLabel = gtk.Label(_("Time:"))
        outputTimeLabel.show()
        outputTimeEntry = gtk.Entry()
        outputTimeEntry.show()
        mainTable.attach(outputTimeLabel, 0, 1, 5, 6, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(outputTimeEntry, 1, 2, 5, 6, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        outputProbabilityLabel = gtk.Label(_("Probability ([0;100]):"))
        outputProbabilityLabel.show()
        outputProbabilityEntry = gtk.Entry()
        outputProbabilityEntry.show()
        mainTable.attach(outputProbabilityLabel, 0, 1, 6, 7, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(outputProbabilityEntry, 1, 2, 6, 7, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        removeOutputSymbolButton = gtk.Button(_("Remove"))
#       removeOutputSymbolButton.connect("clicked", None)
        removeOutputSymbolButton.show()
        removeOutputSymbolButton.set_sensitive(False)

        outputSymbolsTreeStore = gtk.TreeStore(str, str, str, str, str)  # type, id, name, time, proba

        addOutputSymbolButton = gtk.Button(_("Add"))
        addOutputSymbolButton.connect("clicked", self.addSymbolToTheList, symbols, outputSymbolsTreeStore, outputSymbolCombo, outputTimeEntry, outputProbabilityEntry)
        addOutputSymbolButton.show()
        addOutputSymbolButton.set_sensitive(True)

        mainTable.attach(removeOutputSymbolButton, 0, 1, 7, 8, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(addOutputSymbolButton, 1, 2, 7, 8, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        outputSymbolsScroll = gtk.ScrolledWindow()

        outputSymbolsTreeView = gtk.TreeView(outputSymbolsTreeStore)
        outputSymbolsTreeView.get_selection().set_mode(gtk.SELECTION_SINGLE)
        outputSymbolsTreeView.set_size_request(-1, 250)
#        outputSymbolsTreeView.connect("cursor-changed", self.actorDetails)
        outputSymbolsTreeViewCell = gtk.CellRendererText()
        # col : name of the symbol
        outputSymbolsTreeViewCol_name = gtk.TreeViewColumn('Symbol name')
        outputSymbolsTreeViewCol_name.pack_start(outputSymbolsTreeViewCell, True)
        outputSymbolsTreeViewCol_name.set_attributes(outputSymbolsTreeViewCell, text=2)
        outputSymbolsTreeView.append_column(outputSymbolsTreeViewCol_name)
        # col : time of the symbol
        outputSymbolsTreeViewCol_time = gtk.TreeViewColumn('time')
        outputSymbolsTreeViewCol_time.pack_start(outputSymbolsTreeViewCell, True)
        outputSymbolsTreeViewCol_time.set_attributes(outputSymbolsTreeViewCell, text=3)
        outputSymbolsTreeView.append_column(outputSymbolsTreeViewCol_time)
        # col : proba of the symbo2
        outputSymbolsTreeViewCol_proba = gtk.TreeViewColumn('proba')
        outputSymbolsTreeViewCol_proba.pack_start(outputSymbolsTreeViewCell, True)
        outputSymbolsTreeViewCol_proba.set_attributes(outputSymbolsTreeViewCell, text=4)
        outputSymbolsTreeView.append_column(outputSymbolsTreeViewCol_proba)
        outputSymbolsTreeView.show()
        outputSymbolsScroll.add(outputSymbolsTreeView)
        outputSymbolsScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        outputSymbolsScroll.show()

        mainTable.attach(outputSymbolsScroll, 0, 2, 8, 9, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result != gtk.RESPONSE_OK:
            dialog.destroy()
            return None

        inputEntryID = inputSymbolCombo.get_model()[inputSymbolCombo.get_active()][1]
        if inputEntryID == EmptySymbol.TYPE:
            inputSymbol = EmptySymbol()
        elif inputEntryID == UnknownSymbol.TYPE:
            inputSymbol = UnknownSymbol()
        else:
            inputEntry = None
            for symbol in symbols:
                if str(symbol.getID()) == inputEntryID:
                    inputEntry = symbol
            if inputEntry == None:
                self.log.warn(_("Impossible to retrieve the selected input dictionary entry"))
                dialog.destroy()
                return
            inputSymbol = DictionarySymbol(inputEntry)

        # retrieve the output symbols
        outputSymbols = []  # [[symbol, proba, time], ...]
        for outputData in outputSymbolsTreeStore:
            outputSymbolType = outputData[0]

            if outputSymbolType == EmptySymbol.TYPE:
                outputSymbolTime = outputData[3]
                outputSymbolProba = outputData[4]
                outputSymbols.append([EmptySymbol(), int(outputSymbolProba), int(outputSymbolTime)])
            elif outputSymbolType == UnknownSymbol.TYPE:
                outputSymbolTime = outputData[3]
                outputSymbolProba = outputData[4]
                outputSymbols.append([UnknownSymbol(), int(outputSymbolProba), int(outputSymbolTime)])
            else:
                outputSymbolID = outputData[1]
                outputSymbolName = outputData[2]
                outputSymbolTime = outputData[3]
                outputSymbolProba = outputData[4]

                outputEntry = None
                for symbol in symbols:
                    if str(symbol.getID()) == outputSymbolID:
                        outputEntry = symbol

                if outputEntry == None:
                    self.log.warn(_("Impossible to retrieve the selected output dictionary entry"))
                    dialog.destroy()
                    return
                outputSymbols.append([DictionarySymbol(outputEntry), int(outputSymbolProba), int(outputSymbolTime)])

        # Now we create the transition
        transition = SemiStochasticTransition(transitionID, transitionName, startState, stopState, inputSymbol)
        for data in outputSymbols:
            transition.addOutputSymbol(data[0], data[1], data[2])
        startState.registerTransition(transition)
        dialog.destroy()
        return transition

    def addSymbolToTheList(self, widget, entries, outputSymbolsTreeStore, outputSymbolCombo, outputTimeEntry, outputProbabilityEntry):
        entryType = outputSymbolCombo.get_model()[outputSymbolCombo.get_active()][0]
        if entryType == EmptySymbol.TYPE:
            entryTime = outputTimeEntry.get_text()
            entryProba = outputProbabilityEntry.get_text()
            outputSymbolsTreeStore.append(None, [EmptySymbol.TYPE, "none", "EmptySymbol", entryTime, entryProba])
        elif entryType == UnknownSymbol.TYPE:
            entryTime = outputTimeEntry.get_text()
            entryProba = outputProbabilityEntry.get_text()
            outputSymbolsTreeStore.append(None, [UnknownSymbol.TYPE, "none", "UnknownSymbol", entryTime, entryProba])
        else:
            entryID = outputSymbolCombo.get_model()[outputSymbolCombo.get_active()][2]
            entryTime = outputTimeEntry.get_text()
            entryProba = outputProbabilityEntry.get_text()
            selectedEntry = None
            for entry in entries:
                if str(entry.getID()) == entryID:
                    selectedEntry = entry
            if selectedEntry == None:
                self.log.warn(_("Impossible to retrieve the selected dictionary entry"))
                return

            outputSymbolsTreeStore.append(None, [selectedEntry.getType(), selectedEntry.getID(), selectedEntry.getName(), entryTime, entryProba])

    #+-----------------------------------------------------------------------+
    #| createState:
    #|     Display the GUI for the creation of the state and create it
    #+-----------------------------------------------------------------------+
    def createState(self, widget):
        self.log.debug(_("Opening the dialog for the creation of a new state"))
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Definition of the new state"))

        # Create the ID of the new state
        stateID = str(uuid.uuid4())

        mainTable = gtk.Table(rows=3, columns=2, homogeneous=False)
        stateIDLabel = gtk.Label(_("ID:"))
        stateIDLabel.show()
        stateIDValueLabel = gtk.Label(stateID)
        stateIDValueLabel.show()
        mainTable.attach(stateIDLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(stateIDValueLabel, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        stateNameLabel = gtk.Label(_("Name:"))
        stateNameLabel.show()
        stateNameEntry = gtk.Entry()
        stateNameEntry.show()
        mainTable.attach(stateNameLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(stateNameEntry, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        isItInitialStateLabel = gtk.Label(_("Is it the initial state:"))
        isItInitialStateLabel.show()
        isItInitialStateButton = gtk.CheckButton("")
        if self.getAutomata() == None:
            isItInitialStateButton.set_active(True)
            isItInitialStateButton.set_sensitive(False)
        else:
            isItInitialStateButton.set_active(False)
        isItInitialStateButton.show()

        mainTable.attach(isItInitialStateLabel, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(isItInitialStateButton, 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result == gtk.RESPONSE_OK:
            stateName = stateNameEntry.get_text()

            if stateName != None and len(stateName) > 0:
                # Create of the new state
                self.log.info(_("Create a state {0} ({1})").format(stateName, stateID))
                state = NormalState(stateID, stateName)

                if self.getAutomata() == None:
                    automata = MMSTD(state, self.getVocabulary())
                    self.netzob.getCurrentProject().getGrammar().setAutomata(automata)
                else:
                    if isItInitialStateButton.get_active():
                        self.getAutomata().setInitialState(state)

                self.getAutomata().addState(state)

            dialog.destroy()

            # update the list of states
            self.updateListStates()

            # update the xdot
            self.updateXDot()

    def updateListStates(self):
        self.treestore_listStates.clear()
        if self.getAutomata() == None:
            return
        for state in self.getAutomata().getStates():
            self.treestore_listStates.append(None, [str(state.getID()), state.getName(), state.getType()])

    def updateListTransitions(self):
        self.treestore_listTransitions.clear()
        if self.getAutomata() == None:
            return
        for transition in self.getAutomata().getTransitions():
            startState = transition.getInputState().getName()
            endState = transition.getOutputState().getName()
            self.treestore_listTransitions.append(None, [str(transition.getID()), transition.getName(), startState, endState, transition.getType()])

    def updateXDot(self):
        # We retrieve the xdot from the grammar (if it exists)
        if self.getAutomata() == None:
            return
        self.xdotWidget.drawAutomata(self.getAutomata())

    def updateInterface(self):
        if self.netzob.getCurrentProject() == None:
            self.createStateButton.set_sensitive(False)
            self.createTransitionButton.set_sensitive(False)
        else:
            self.createStateButton.set_sensitive(True)
            self.createTransitionButton.set_sensitive(True)

    def showAbstractionPanel(self, button):
        # Dedicated view to abstract current grammar
        abstractionPanel = AutomaticGrammarAbstractionView(self.netzob.getCurrentProject())
        abstractionPanel.display()
        self.update()

    def showAutomaticInferencePanel(self, button):
        # Dedicated view for the inference process
        inferencePanel = AutomaticGrammarInferenceView(self.netzob.getCurrentProject())
        inferencePanel.display()
        self.update()

    #+----------------------------------------------
    #| button_press_on_states:
    #|   Contextual menu when clicking on a state
    #+----------------------------------------------
    def button_press_on_states(self, treeview, event):
        x = int(event.x)
        y = int(event.y)
        info = treeview.get_path_at_pos(x, y)
        clickedState = None
        if info is not None:
            path = info[0]
            iter = treeview.get_model().get_iter(path)
            idState = str(treeview.get_model().get_value(iter, 0))
            for state in self.getAutomata().getStates():
                if state.getID() == idState:
                    clickedState = state

        if clickedState != None and event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
            self.build_context_menu_for_states(event, clickedState)

    #+----------------------------------------------
    #| button_press_on_transitions:
    #|   Contextual menu when clicking on a transition
    #+----------------------------------------------
    def button_press_on_transitions(self, treeview, event):
        x = int(event.x)
        y = int(event.y)
        info = treeview.get_path_at_pos(x, y)
        clickedTransition = None
        if info is not None:
            path = info[0]
            iter = treeview.get_model().get_iter(path)
            idTransition = str(treeview.get_model().get_value(iter, 0))
            for transition in self.getAutomata().getTransitions():
                if transition.getID() == idTransition:
                    clickedTransition = transition

        if clickedTransition != None and event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
            self.build_context_menu_for_transitions(event, clickedTransition)

    #+----------------------------------------------
    #| build_context_menu_for_transitions:
    #|   Create a menu to display available operations
    #|   on the treeview transition
    #+----------------------------------------------
    def build_context_menu_for_transitions(self, event, transition):
        entries = [
            (gtk.STOCK_REMOVE, self.displayPopupToRemoveTransition, (transition != None))
        ]

        menu = gtk.Menu()
        for stock_id, callback, sensitive in entries:
            item = gtk.ImageMenuItem(stock_id)
            item.connect("activate", callback, transition)
            item.set_sensitive(sensitive)
            item.show()
            menu.append(item)
        menu.popup(None, None, None, event.button, event.time)

    #+----------------------------------------------
    #| build_context_menu_for_states:
    #|   Create a menu to display available operations
    #|   on the treeview states
    #+----------------------------------------------
    def build_context_menu_for_states(self, event, state):
        entries = [
            (gtk.STOCK_EDIT, self.displayPopupToEditState, (state != None)),
            (gtk.STOCK_REMOVE, self.displayPopupToRemoveState, (state != None))
        ]

        menu = gtk.Menu()
        for stock_id, callback, sensitive in entries:
            item = gtk.ImageMenuItem(stock_id)
            item.connect("activate", callback, state)
            item.set_sensitive(sensitive)
            item.show()
            menu.append(item)
        menu.popup(None, None, None, event.button, event.time)

    def displayPopupToRemoveTransition(self, event, transition):
        questionMsg = _("Click yes to confirm the removal of the transition {0}.").format(transition.getName())
        md = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, questionMsg)
        result = md.run()
        md.destroy()
        if result == gtk.RESPONSE_YES:
            self.getAutomata().removeTransition(transition)
            self.update()
        else:
            self.log.debug(_("The user didn't confirm the deletion of the transition {0}").format(transition.getName()))

    #+----------------------------------------------
    #| displayPopupToEditState:
    #|   Display a popup for the edition of a state
    #+----------------------------------------------
    def displayPopupToEditState(self, event, state):
        self.log.debug(_("Opening the dialog for the edition of a state"))
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Edition of a state"))

        # Create the ID of the new state
        stateID = str(state.getID())

        mainTable = gtk.Table(rows=5, columns=2, homogeneous=False)

        # ID of the state
        stateIDLabel = gtk.Label(_("ID:"))
        stateIDLabel.show()
        stateIDValueLabel = gtk.Label(stateID)
        stateIDValueLabel.show()
        mainTable.attach(stateIDLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(stateIDValueLabel, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Name of the state
        stateNameLabel = gtk.Label(_("Name:"))
        stateNameLabel.show()
        stateNameEntry = gtk.Entry()
        stateNameEntry.set_text(str(state.getName()))
        stateNameEntry.show()
        mainTable.attach(stateNameLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(stateNameEntry, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Memopex labels
        memOpexButton = gtk.Button(_("Add a MemOpex"))
        memOpexButton.connect("clicked", self.showCreationOfMemOpex, state)
        memOpexButton.show()
        memOpexButton.set_sensitive(True)
        mainTable.attach(memOpexButton, 0, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # List of memopex
        scroll_listOfMemOpex = gtk.ScrolledWindow()
        treestore_listOfMemOpex = gtk.TreeStore(str, str, str)  # id, transition id, type
        treeview_listOfMemOpex = gtk.TreeView(treestore_listOfMemOpex)
        treeview_listOfMemOpex.get_selection().set_mode(gtk.SELECTION_SINGLE)
        treeview_listOfMemOpex.set_size_request(-1, 250)
        cell = gtk.CellRendererText()
        # main col
        column_listOfMemOpex_transition = gtk.TreeViewColumn(_("Transition ID"))
        column_listOfMemOpex_transition.pack_start(cell, True)
        column_listOfMemOpex_transition.set_attributes(cell, text=1)
        treeview_listOfMemOpex.append_column(column_listOfMemOpex_transition)
        # Type col
        column_listOfMemOpex_type = gtk.TreeViewColumn(_("Type"))
        column_listOfMemOpex_type.pack_start(cell, True)
        column_listOfMemOpex_type.set_attributes(cell, text=2)
        treeview_listOfMemOpex.append_column(column_listOfMemOpex_type)
        treeview_listOfMemOpex.show()

        # Register all the memopex of the current state
        for memOpex in state.getMemOpexs():
            treestore_listOfMemOpex.append(None, [str(memOpex.getID()), str(memOpex.getTransitionID()), memOpex.getType()])

        scroll_listOfMemOpex.add(treeview_listOfMemOpex)
        scroll_listOfMemOpex.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll_listOfMemOpex.show()
        mainTable.attach(scroll_listOfMemOpex, 0, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result == gtk.RESPONSE_OK:
            text = stateNameEntry.get_text()
            if (len(text) > 0):
                state.setName(text)
        dialog.destroy()

        self.update()

    def showCreationOfMemOpex(self, event, state):
        self.log.debug(_("Opening the dialog for the creation of MemOpex of a state"))
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK, None)
        dialog.set_markup(_("Creation of a MemOpex"))

        # MemOpex id
        memOpexId = uuid.uuid4()

        mainTable = gtk.Table(rows=5, columns=2, homogeneous=False)

        # ID of the memopex
        memopexIDLabel = gtk.Label(_("ID:"))
        memopexIDLabel.show()
        memopexIDValueLabel = gtk.Label(str(memOpexId))
        memopexIDValueLabel.show()
        mainTable.attach(memopexIDLabel, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(memopexIDValueLabel, 1, 2, 0, 1, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Transition
        memopexTransitionLabel = gtk.Label(_("Transition:"))
        memopexTransitionLabel.show()

        transitionTypeCombo = gtk.ComboBox()
        transitionTypeCombo.set_model(gtk.ListStore(str, str))  # id, transition name
        transitionTypeComboCell = gtk.CellRendererText()
        transitionTypeCombo.pack_start(transitionTypeComboCell, True)
        transitionTypeCombo.add_attribute(transitionTypeComboCell, 'text', 1)

        for possibleTransition in self.getAutomata().getTransitionsLeadingToState(state):
            transitionTypeCombo.get_model().append([str(possibleTransition.getID()), possibleTransition.getName()])
        transitionTypeCombo.show()
        mainTable.attach(memopexTransitionLabel, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(transitionTypeCombo, 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Operations
        memopexOperationLabel = gtk.Label(_("Operation:"))
        memopexOperationLabel.show()

        operationCombo = gtk.ComboBox()
        operationCombo.set_model(gtk.ListStore(str))  # type
        operationComboCell = gtk.CellRendererText()
        operationCombo.pack_start(operationComboCell, True)
        operationCombo.add_attribute(operationComboCell, 'text', 0)

        operationCombo.get_model().append([_("FORGET")])
        operationCombo.show()
        mainTable.attach(memopexOperationLabel, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(operationCombo, 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Variable
        variableLabel = gtk.Label(_("Variable:"))
        variableLabel.show()

        variableCombo = gtk.ComboBox()
        variableCombo.set_model(gtk.ListStore(str, str))  # id, name
        variableComboCell = gtk.CellRendererText()
        variableCombo.pack_start(variableComboCell, True)
        variableCombo.add_attribute(operationComboCell, 'text', 1)

        for variable in self.getVocabulary().getVariables():
            variableCombo.get_model().append([str(variable.getID()), variable.getUncontextualizedDescription()])

        variableCombo.show()
        mainTable.attach(variableLabel, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(variableCombo, 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)

#        # Memopex labels
#        memOpexButton = gtk.Button("Add a MemOpex")
#        memOpexButton.connect("clicked", self.showCreationOfMemOpex, state)
#        memOpexButton.show()
#        memOpexButton.set_sensitive(True)
#        mainTable.attach(memOpexButton, 0, 2, 2, 3, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
#
#        # List of memopex
#        scroll_listOfMemOpex = gtk.ScrolledWindow()
#        treestore_listOfMemOpex = gtk.TreeStore(str, str, str)  # id, transition id, type
#        treeview_listOfMemOpex = gtk.TreeView(treestore_listOfMemOpex)
#        treeview_listOfMemOpex.get_selection().set_mode(gtk.SELECTION_SINGLE)
#        treeview_listOfMemOpex.set_size_request(-1, 250)
#        cell = gtk.CellRendererText()
#        # main col
#        column_listOfMemOpex_transition = gtk.TreeViewColumn('Transition ID')
#        column_listOfMemOpex_transition.pack_start(cell, True)
#        column_listOfMemOpex_transition.set_attributes(cell, text=1)
#        treeview_listOfMemOpex.append_column(column_listOfMemOpex_transition)
#        # Type col
#        column_listOfMemOpex_type = gtk.TreeViewColumn('Type')
#        column_listOfMemOpex_type.pack_start(cell, True)
#        column_listOfMemOpex_type.set_attributes(cell, text=2)
#        treeview_listOfMemOpex.append_column(column_listOfMemOpex_type)
#        treeview_listOfMemOpex.show()
#
#        # Register all the memopex of the current state
#        for memOpex in state.getMemOpexs() :
#            treestore_listOfMemOpex.append(None, [str(memOpex.getID()), str(memOpex.getTransitionID()), memOpex.getType()])
#
#        scroll_listOfMemOpex.add(treeview_listOfMemOpex)
#        scroll_listOfMemOpex.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
#        scroll_listOfMemOpex.show()
#        mainTable.attach(scroll_listOfMemOpex, 0, 2, 3, 4, xoptions=gtk.FILL, yoptions=0, xpadding=5, ypadding=5)
#
        dialog.vbox.pack_end(mainTable, True, True, 0)
        dialog.show_all()
        result = dialog.run()

        if result == gtk.RESPONSE_OK:
            text = stateNameEntry.get_text()
            if (len(text) > 0):
                state.setName(text)
        dialog.destroy()

        self.update()

    def responseToDialog(self, entry, dialog, response):
        dialog.response(response)

    #+----------------------------------------------
    #| displayPopupToRemoveState:
    #|   Display a popup to remove a state
    #+----------------------------------------------
    def displayPopupToRemoveState(self, event, state):

        questionMsg = _("Click yes to confirm the removal of the state {0}. All its associated transitions will also be deleted.").format(state.getName())
        md = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, questionMsg)
        result = md.run()
        md.destroy()
        if result == gtk.RESPONSE_YES:
            self.getAutomata().removeState(state)
            self.update()
        else:
            self.log.debug(_("The user didn't confirm the deletion of the state {0}").format(state.getName()))

    def getGrammar(self):
        if self.netzob.getCurrentProject() == None:
            return None
        else:
            return self.netzob.getCurrentProject().getGrammar()

    def getAutomata(self):
        grammar = self.getGrammar()
        if grammar == None:
            return None
        return grammar.getAutomata()

    def getVocabulary(self):
        if self.netzob.getCurrentProject() == None:
            return None
        else:
            return self.netzob.getCurrentProject().getVocabulary()
class AutomaticGrammarInferenceView(object):

    #+----------------------------------------------
    #| Constructor:
    #+----------------------------------------------
    def __init__(self, project):
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Inference.Grammar.AutomaticGrammarInferenceView.py')
        self.project = project
        self.inferer = None
        self.computedAutomaton = None
        self.finish = False

    def display(self):
        # Display the form for the creation of a word variable
        self.dialog = Gtk.Dialog(title=_("Configuration of the automatic inference"), flags=0, buttons=None)

        mainTable = Gtk.Table(rows=9, columns=2, homogeneous=False)

        # Infer a client or a server
        targetOfInferenceLabel = Gtk.Label(label=_("Target:"))
        targetOfInferenceLabel.show()
        self.targetOfInferenceCombo = Gtk.ComboBoxText()
        self.targetOfInferenceCombo.set_model(Gtk.ListStore(str))
        targetOfInferenceComboCell = Gtk.CellRendererText()
        self.targetOfInferenceCombo.pack_start(targetOfInferenceComboCell, True)
        self.targetOfInferenceCombo.add_attribute(targetOfInferenceComboCell, 'text', 0)
        self.targetOfInferenceCombo.append_text(_("CLIENT"))
        self.targetOfInferenceCombo.append_text(_("SERVER"))
        self.targetOfInferenceCombo.show()
        mainTable.attach(targetOfInferenceLabel, 0, 1, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.targetOfInferenceCombo, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # IP of the server
        IPLabel = Gtk.Label(label=_("IP:"))
        IPLabel.show()
        self.IPEntry = Gtk.Entry()
        self.IPEntry.show()
        mainTable.attach(IPLabel, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.IPEntry, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Protocol of the server
        ProtocolLabel = Gtk.Label(label=_("Protocol:"))
        ProtocolLabel.show()
        self.combo_protocolOfNetworkActor = Gtk.ComboBoxText.new_with_entry()
        self.combo_protocolOfNetworkActor.set_model(Gtk.ListStore(str))
        self.combo_protocolOfNetworkActor.append_text(_("TCP"))
        self.combo_protocolOfNetworkActor.append_text(_("UDP"))
        self.combo_protocolOfNetworkActor.set_active(0)
        self.combo_protocolOfNetworkActor.show()

        mainTable.attach(ProtocolLabel, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.combo_protocolOfNetworkActor, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Source port
        SourcePortLabel = Gtk.Label(label=_("Our port:"))
        SourcePortLabel.show()
        self.ourPortEntry = Gtk.Entry()
        self.ourPortEntry.show()
        mainTable.attach(SourcePortLabel, 0, 1, 3, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.ourPortEntry, 1, 2, 3, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Port of the server
        PortLabel = Gtk.Label(label=_("Target Port:"))
        PortLabel.show()
        self.targetPortEntry = Gtk.Entry()
        self.targetPortEntry.show()
        mainTable.attach(PortLabel, 0, 1, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.targetPortEntry, 1, 2, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Estimated number of states
        MaxStatesLabel = Gtk.Label(label=_("Maximum number of states:"))
        MaxStatesLabel.show()
        self.MaxStatesEntry = Gtk.Entry()
        self.MaxStatesEntry.show()
        mainTable.attach(MaxStatesLabel, 0, 1, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.MaxStatesEntry, 1, 2, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Script to execute to reset the implementation
        scriptLabel = Gtk.Label(label=_("Reseting script:"))
        scriptLabel.show()
        self.scriptEntry = Gtk.Entry()
        self.scriptEntry.show()
        mainTable.attach(scriptLabel, 0, 1, 6, 7, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)
        mainTable.attach(self.scriptEntry, 1, 2, 6, 7, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Create button
        startButton = Gtk.Button(_("Start inference"))
        startButton.show()
        startButton.connect("clicked", self.startInference)
        mainTable.attach(startButton, 1, 2, 7, 8, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()

    def createInferringStatusView(self):
        self.dialog = Gtk.Dialog(title=_("Execution of the inferring process"), flags=0, buttons=None)

        mainTable = Gtk.Table(rows=5, columns=4, homogeneous=False)

        # Insert the current Hypothesis of the automata
        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.xdotWidget.set_size_request(500, 500)
        mainTable.attach(self.xdotWidget, 0, 2, 0, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the updated list of requests and associated responses
        scroll_requests = Gtk.ScrolledWindow()
        self.treestore_queries = Gtk.TreeStore(str, str, str)  # queries, responses, color
        treeview_queries = Gtk.TreeView(self.treestore_queries)
        treeview_queries.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        treeview_queries.set_size_request(500, 500)
#        treeview_queries.connect('button-press-event', self.button_press_on_transitions)
        cell = Gtk.CellRendererText()
        # col : membership queries
        col_queries_querie = Gtk.TreeViewColumn(_("Membership queries"))
        col_queries_querie.pack_start(cell, True)
        col_queries_querie.add_attribute(cell, "text", 0)
        treeview_queries.append_column(col_queries_querie)
        # col : responses to queries
        column_queries_responses = Gtk.TreeViewColumn(_("Responses"))
        column_queries_responses.pack_start(cell, True)
        column_queries_responses.add_attribute(cell, "text", 1)
        treeview_queries.append_column(column_queries_responses)
        scroll_requests.add(treeview_queries)
        scroll_requests.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scroll_requests.show()
        mainTable.attach(scroll_requests, 2, 4, 0, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Progress bar
        self.progressbar = Gtk.ProgressBar()
        self.progressbar.show()
#        # Insert the status message
#        self.statusLabel = Gtk.Label(label="A number of X states has been created - Current turn contains N MQ")
#        self.statusLabel.show()
        mainTable.attach(self.progressbar, 0, 2, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the stop button
        self.stopButton = Gtk.Button(_("Stop"))
        self.stopButton.show()
        self.stopButton.connect("clicked", self.stopInference)
        mainTable.attach(self.stopButton, 2, 3, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        # Insert the Save button
        self.saveButton = Gtk.Button(_("Save as Grammar"))
        self.saveButton.show()
        self.saveButton.connect("clicked", self.saveGrammar)
        mainTable.attach(self.saveButton, 3, 4, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5)

        self.dialog.vbox.pack_end(mainTable, True, True, 0)
        self.dialog.show_all()

    def do_pulse(self, *args):
        if self.finish is False:
            self.progressbar.pulse()
            return True
        return False

    def callback_submitedQuery(self, query, resultQuery):
        if query is None:
            self.log.debug("Impossible to show a Null query")
            return

        # Create a str view of the Query
        strQuery = ""
        for symbol in query.getSymbols():
            strSymbol = ""
            if symbol.getType() == "DictionarySymbol":
                strSymbol = symbol.getName()
            else:
                strSymbol = "EmptySymbol"

            strQuery = strQuery + strSymbol + ", "

        # Create a str view of the Result Query
        strResultQuery = ""
        if not type(resultQuery) == list:
            return
        for symbol in resultQuery:
            strSymbol = ""
            if symbol.getType() == "DictionarySymbol":
                strSymbol = symbol.getName()
            else:
                strSymbol = str(symbol)

            strResultQuery = strResultQuery + strSymbol + ","

        self.treestore_queries.append(None, [strQuery, strResultQuery, "blue"])

    def callback_hypotheticalAutomaton(self, hypotheticalAutomaton):
        if hypotheticalAutomaton is not None:
            self.computedAutomaton = hypotheticalAutomaton
            self.xdotWidget.set_dotcode(self.computedAutomaton.getDotCode())

    def stopInference(self, button):
        self.finish = True
        self.log.info("Stop the inferer")
        self.inferer.stop()

    def startInferer(self):
        (yield ThreadedTask(self.inferer.infer))
        self.computedAutomaton = self.inferer.getInferedAutomaton()
        self.finish = True

    def saveGrammar(self, button):
        if self.computedAutomaton is not None:
            self.log.debug("Saving the computed automata as the grammar of current project")
            self.project.getGrammar().setAutomata(self.computedAutomaton)
            self.dialog.destroy()

    def startInference(self, button):
        # We retrieve the specified value
        actorType = self.targetOfInferenceCombo.get_active_text()
        actorIP = self.IPEntry.get_text()
        actorNetworkProtocol = self.combo_protocolOfNetworkActor.get_active_text()
        ourPort = int(self.ourPortEntry.get_text())
        targetPort = int(self.targetPortEntry.get_text())
        scriptFilename = self.scriptEntry.get_text()
        maxNumberOfState = int(self.MaxStatesEntry.get_text())

        inputDictionary = []
        for symbol in self.project.getVocabulary().getSymbols():
#            if symbol.getName() == "LOGIN" or symbol.getName() == "EXECUTE" or symbol.getName() == "LOGOUT" or symbol.getName() == "DOWNLOAD":
            inputDictionary.append(symbol)
        inputDictionary.append(UnknownSymbol())
        # Close the current dialog
        self.dialog.destroy()

        anID = str(uuid.uuid4())
        memory = Memory()
        if actorType == "CLIENT":
            # Lets create a simple network oracle
            oracleCommunicationChannel = NetworkServer(anID, memory, actorNetworkProtocol, "127.0.0.1", ourPort, actorIP, targetPort)
        else:
            # Lets create a simple network oracle
            oracleCommunicationChannel = NetworkClient(anID, memory, actorNetworkProtocol, "127.0.0.1", ourPort, actorIP, targetPort)

        # Lets create an equivalence oracle
        equivalenceOracle = WMethodNetworkEquivalenceOracle(oracleCommunicationChannel, maxNumberOfState, scriptFilename)

        # Lets create the automatic inferer
        self.inferer = GrammarInferer(self.project.getVocabulary(), inputDictionary, oracleCommunicationChannel, equivalenceOracle, scriptFilename, self.callback_submitedQuery, self.callback_hypotheticalAutomaton)

        # Open the new dialog which shows the status of the inferring process
        self.createInferringStatusView()

        # Start the progress bar
        GObject.timeout_add(200, self.do_pulse)

        # Start the inferer
        self.job = Job(self.startInferer())
예제 #12
0
class SimulatorView(object):

    def __init__(self, controller):
        self.controller = controller
        self.netzob = self.controller.netzob
        self.builder = Gtk.Builder()
        self.builder.add_from_file(os.path.join(
            ResourcesConfiguration.getStaticResources(),
            "ui", "simulator",
            "simulatorView.glade"))
        self._getObjects(self.builder, ["simulatorViewport",
                                        "editActorButton",
                                        "deleteActorButton",
                                        "stopActorButton",
                                        "startActorButton",
                                        "actorsListStore",
                                        "listOfActorsTreeView",
                                        "grammarCurrentActorViewport",
                                        "statusCurrentActorImage",
                                        "nameCurrentActorLabel",
                                        "stopCurrentActorButton",
                                        "startCurrentActorButton",
                                        "infoCurrentActorLabel",
                                        "statusCurrentActorLabel",
                                        "currentActorIOChannelListStore",
                                        "currentActorMemoryListStore",
                                        "currentActorPropertiesListStore"
                                        ])
        self._loadActionGroupUIDefinition()
        self.builder.connect_signals(self.controller)
        self.toggledActors = []

        self.xdotWidget = XDotWidget()
        self.xdotWidget.show_all()
        self.grammarCurrentActorViewport.add(self.xdotWidget)

        self.refreshListOfActors()
        self.updateCurrentActor()

    def _loadActionGroupUIDefinition(self):
        """Loads the action group and the UI definition of menu items
        . This method should only be called in the constructor"""
        # Load actions
        actionsBuilder = Gtk.Builder()
        actionsBuilder.add_from_file(os.path.join(
            ResourcesConfiguration.getStaticResources(),
            "ui", "simulator",
            "simulatorActions.glade"))
        self._actionGroup = actionsBuilder.get_object("simulatorActionGroup")
        actionsBuilder.connect_signals(self.controller)
        uiDefinitionFilePath = os.path.join(
            ResourcesConfiguration.getStaticResources(),
            "ui", "simulator",
            "simulatorMenuToolbar.ui")
        with open(uiDefinitionFilePath, "r") as uiDefinitionFile:
            self._uiDefinition = uiDefinitionFile.read()

    def _getObjects(self, builder, objectsList):
        for object in objectsList:
            setattr(self, object, builder.get_object(object))

    ## Mandatory view methods
    def getPanel(self):
        return self.simulatorViewport

    # Return the actions
    def getActionGroup(self):
        return self._actionGroup

    # Return toolbar and menu
    def getMenuToolbarUIDefinition(self):
        return self._uiDefinition

    def restart(self):
        """restart the view"""
        self.refreshListOfActors()
        self.deleteActorButton.set_sensitive(False)

    def refreshListOfActors(self):
        """Clear the list of available actors and update it
        with declared actors in the project definition."""
        actors = []
        self.actorsListStore.clear()

        currentProject = self.controller.getCurrentProject()
        if currentProject is not None:
            simulator = currentProject.getSimulator()
            if simulator is not None:
                actors.extend(simulator.getActors())

        for actor in actors:
            i = self.actorsListStore.append()
            toggled = False
            if actor in self.toggledActors:
                toggled = True

            if actor.isActive():
                imageStatus = Gtk.STOCK_YES
            else:
                imageStatus = Gtk.STOCK_NO

            self.actorsListStore.set(i, 0, toggled)
            self.actorsListStore.set(i, 1, imageStatus)
            self.actorsListStore.set(i, 2, str(actor.getID()))
            self.actorsListStore.set(i, 3, actor.getName())

    def updateCurrentActor(self):
        currentActor = self.controller.getCurrentActor()

        self.currentActorIOChannelListStore.clear()
        self.currentActorMemoryListStore.clear()

        if currentActor is None:
            self.statusCurrentActorImage.hide()
            self.nameCurrentActorLabel.set_label("")
            self.nameCurrentActorLabel.hide()

            self.stopCurrentActorButton.set_sensitive(False)
            self.startCurrentActorButton.set_sensitive(False)

            self.updateGrammarOfCurrentActor()

            self.infoCurrentActorLabel.set_label("")
            self.infoCurrentActorLabel.hide()

            self.statusCurrentActorLabel.set_label("")
            self.statusCurrentActorLabel.hide()
        else:
            if currentActor.isActive():
                imageStatus = Gtk.STOCK_YES
                actorStatus = "active"
            else:
                imageStatus = Gtk.STOCK_NO
                actorStatus = "inactive"

            self.statusCurrentActorImage = Gtk.Image(stock=imageStatus)
            self.statusCurrentActorImage.show()
            self.nameCurrentActorLabel.set_label(currentActor.getName())
            self.nameCurrentActorLabel.show()

            self.stopCurrentActorButton.set_sensitive(True)
            self.startCurrentActorButton.set_sensitive(True)

            self.updateGrammarOfCurrentActor()

            self.infoCurrentActorLabel.set_label("hum hum")
            self.infoCurrentActorLabel.show()

            self.statusCurrentActorLabel.set_label(actorStatus)
            self.statusCurrentActorLabel.show()

            self.displayPropertiesOfActor(currentActor)

    def displayPropertiesOfActor(self, actor):
        """Display the properties of the actor"""
        self.currentActorPropertiesListStore.clear()

        for property in actor.getProperties():
            self.currentActorPropertiesListStore.append([str(property.getName()), str(property.getCurrentValue())])

    def updateGrammarOfCurrentActor(self):
        currentActor = self.controller.getCurrentActor()
        if currentActor is not None:
            grammar = self.controller.getCurrentProject().getGrammar()
            if grammar is not None:
                automata = grammar.getAutomata()
                if automata is not None:
                    self.xdotWidget.drawAutomata(automata)
                else:
                    self.xdotWidget.clear()
            self.xdotWidget.show()
        else:
            self.xdotWidget.clear()
            self.xdotWidget.hide()

    def registerInputSymbolOfCurrentActor(self, receptionTime, message, symbol):
        """Add a symbol, the message and the reception time in the list"""
        i = self.currentActorIOChannelListStore.append()
        self.currentActorIOChannelListStore.set(i, 0, Gtk.STOCK_GO_BACK)
        self.currentActorIOChannelListStore.set(i, 1, receptionTime)
        self.currentActorIOChannelListStore.set(i, 2, symbol.getName())
        self.currentActorIOChannelListStore.set(i, 3, message)

    def registerOutputSymbolOfCurrentActor(self, receptionTime, message, symbol):
        """Add a symbol, the message and the reception time in the list"""
        i = self.currentActorIOChannelListStore.append()
        self.currentActorIOChannelListStore.set(i, 0, Gtk.STOCK_GO_FORWARD)
        self.currentActorIOChannelListStore.set(i, 1, receptionTime)
        self.currentActorIOChannelListStore.set(i, 2, symbol.getName())
        self.currentActorIOChannelListStore.set(i, 3, message)

    def registerMemoryAccess(self, access, variable, value):
        """Describe in the GUI a memory access"""

        now = datetime.datetime.now()
        receptionTime = now.strftime("%H:%M:%S")

        if variable is not None:
            name = variable.getName()
        else:
            name = "?"

        data = str(value)

        i = self.currentActorMemoryListStore.append()
        self.currentActorMemoryListStore.set(i, 0, access)
        self.currentActorMemoryListStore.set(i, 1, receptionTime)
        self.currentActorMemoryListStore.set(i, 2, name)
        self.currentActorMemoryListStore.set(i, 3, data)

    def updateStatusOfCurrentActor(self):
        """Update the status (displayed) of the current actor"""

        currentActor = self.controller.getCurrentActor()
        if currentActor is not None:
            if currentActor.isActive():
                actorStatus = "active"
                self.stopCurrentActorButton.set_sensitive(True)
                self.startCurrentActorButton.set_sensitive(False)

            else:
                actorStatus = "inactive"
                self.stopCurrentActorButton.set_sensitive(False)
                self.startCurrentActorButton.set_sensitive(True)

            self.statusCurrentActorLabel.set_label(actorStatus)
            self.statusCurrentActorLabel.show()

        self.refreshListOfActors()
예제 #13
0
 def __init__(self, grammarController):
     XDotWidget.__init__(self)
     self.grammarController = grammarController
     self.connect('clicked', self.on_click_action)