Example #1
0
    def concatField_activate_cb(self, action):
        # Sanity check
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        symbol = self.view.getDisplayedField()
        if symbol is None:
            NetzobErrorMessage(_("No selected symbol."))
            return
        selectedFields = self.view.selectedMessageTable.treeViewHeaderGroup.getSelectedFields(
        )
        if selectedFields is None or len(selectedFields) < 2:
            NetzobErrorMessage(_("You need to select at least two fields."))
            return
        # We retrieve the first and last fields selected
        firstField = selectedFields[0]
        lastField = selectedFields[0]

        for selectedField in selectedFields:
            if selectedField.getIndex() < firstField.getIndex():
                firstField = selectedField
            if selectedField.getIndex() > lastField.getIndex():
                lastField = selectedField

        # We concat all the fields in the first one
        (errorCode, errorMsg) = firstField.concatFields(lastField)
        if errorCode is False:
            NetzobErrorMessage(errorMsg)
        else:
            self.view.updateSelectedMessageTable()
            self.view.updateLeftPanel()
Example #2
0
 def partitioningSmooth_activate_cb(self, action):
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     layers = self.view.getCheckedLayerList()
     if layers == []:
         NetzobErrorMessage(_("No symbol selected."))
         return
     smooth_controller = SmoothPartitioningController(self, layers)
     smooth_controller.run()
Example #3
0
 def messagesDistribution_activate_cb(self, action):
     # Sanity check
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     symbols = self.view.getCheckedSymbolList()
     if symbols == []:
         NetzobErrorMessage(_("No symbol selected."))
         return
     distribution = MessagesDistributionController(
         self, self._view.getCheckedSymbolList())
     distribution.run()
Example #4
0
 def partitioningReset_activate_cb(self, action):
     """Callback executed when the user clicks
     on the reset button. It starts the dedicated controller."""
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     layers = self.view.getCheckedLayerList()
     if layers == []:
         NetzobErrorMessage(_("No symbol selected."))
         return
     reset_controller = ResetPartitioningController(self, layers)
     reset_controller.run()
Example #5
0
 def sequenceAlignment_activate_cb(self, action):
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     layers = self.view.getCheckedLayerList()
     if layers == []:
         NetzobErrorMessage(_("No layer selected."))
         return
     sequence_controller = SequenceAlignmentController(self,
                                                       layers,
                                                       doUpgma=True)
     sequence_controller.run()
Example #6
0
 def environmentDep_activate_cb(self, action):
     """Callback executed when the user requests
     the execution of environmental deps search through menu
     or toolbar"""
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     symbols = self.view.getCheckedSymbolList()
     if symbols == []:
         NetzobErrorMessage(_("No symbol selected."))
         return
     envDepController = EnvironmentDependenciesSearcherController(
         self, symbols)
     envDepController.run()
Example #7
0
    def fieldLimits_activate_cb(self, action):
        # Sanity checks
        if self.netzob.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return

        layers = self.view.getCheckedLayerList()
        if layers == []:
            NetzobErrorMessage(_("No symbol selected."))
            return

        for layer in layers:
            layer.computeFieldsLimits()
            self.view.updateSelectedMessageTable()
        NetzobInfoMessage(_("Fields limits computed."))
Example #8
0
    def concatSymbolButton_clicked_cb(self, toolButton):
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        # retrieve the checked symbols
        symbols = self.view.getCheckedSymbolList()

        # Create a new symbol
        newSymbol = Symbol(str(uuid.uuid4()), "Merged",
                           self.getCurrentProject())

        # fetch all their messages
        for sym in symbols:
            newSymbol.addMessages(sym.getMessages())

        #delete all selected symbols
        self.view.emptyMessageTableDisplayingSymbols(symbols)
        for sym in symbols:
            self.getCurrentProject().getVocabulary().removeSymbol(sym)

        #add the concatenate symbol
        self.getCurrentProject().getVocabulary().addSymbol(newSymbol)

        #refresh view
        self.view.updateLeftPanel()
    def initBuffer(self):
        self.split_position = 1
        self.split_min_len = 999999
        self.split_max_len = 0
        self.split_align = "left"

        # Find the size of the shortest/longest message
        cells = self.field.getCells()
        for m in cells:
            if len(m) > self.split_max_len:
                self.split_max_len = len(m)
            if len(m) < self.split_min_len:
                self.split_min_len = len(m)

        if self.split_min_len == 0:
            self.view.splitFieldDialog.destroy()
            NetzobErrorMessage(_("Can't split field with empty cell(s)."))
            return False

        self.view.buffer.get_buffer().create_tag("redTag",
                                                 weight=Pango.Weight.BOLD,
                                                 foreground="red",
                                                 family="Courier")
        self.view.buffer.get_buffer().create_tag("greenTag",
                                                 weight=Pango.Weight.BOLD,
                                                 foreground="#006400",
                                                 family="Courier")

        self.updateDisplayFollowingSplitPosition()

        self.view.setMaxSizeOfSplitPositionAdjustment(self.split_min_len - 1)

        return True
Example #10
0
    def saveProject_activate_cb(self, action):
        """Save the current project"""

        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."), self.view.mainWindow)
            return
        self.getCurrentProject().saveConfigFile(self.getCurrentWorkspace())
Example #11
0
    def createSymbolButton_clicked_cb(self, toolButton):
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return

        builder2 = Gtk.Builder()
        builder2.add_from_file(
            os.path.join(ResourcesConfiguration.getStaticResources(), "ui",
                         "dialogbox.glade"))
        dialog = builder2.get_object("createsymbol")
        dialog.set_transient_for(self.netzob.view.mainWindow)

        # Disable apply button if no text
        applybutton = builder2.get_object("button1")
        entry = builder2.get_object("entry1")
        entry.connect("changed", self.entry_disableButtonIfEmpty_cb,
                      applybutton)

        result = dialog.run()

        if (result == 0):
            newSymbolName = entry.get_text()
            newSymbolId = str(uuid.uuid4())
            self.log.debug(
                "A new symbol will be created with the given name: {0}".format(
                    newSymbolName))
            currentProject = self.netzob.getCurrentProject()
            newSymbol = Symbol(newSymbolId, newSymbolName, currentProject)
            currentProject.getVocabulary().addSymbol(newSymbol)
            self.view.updateLeftPanel()
            dialog.destroy()
        if (result == 1):
            dialog.destroy()
Example #12
0
 def editVariable_activate_cb(self, action):
     # Sanity check
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     symbol = self.view.getDisplayedField()
     if symbol is None:
         NetzobErrorMessage(_("No selected symbol."))
         return
     fields = self.view.selectedMessageTable.treeViewHeaderGroup.getSelectedFields(
     )
     if fields is None or len(fields) < 1:
         NetzobErrorMessage(_("No selected field."))
         return
     # Open a popup to edit the variable
     field = fields[-1]  # We take the last selected field
     creationPanel = VariableTreeController(self.netzob, symbol, field)
    def displayPopupToCreateLayer_cb(self, event):
        # If fields header are selected, we get it
        selectedFields = self.vocabularyController.view.selectedMessageTable.treeViewHeaderGroup.getSelectedFields()
        if selectedFields is None or len(selectedFields) == 0:
            # Either, we only consider the current field
            selectedFields = [self.field]
        # We retrieve the first and last fields selected
        firstField = selectedFields[0]
        lastField = selectedFields[0]
        for field in selectedFields:
            if field.getIndex() < firstField.getIndex():
                firstField = field
            if field.getIndex() > lastField.getIndex():
                lastField = field
        # Update selected fields to the entire range
        selectedFields = []
        for field in self.getSymbol().getExtendedFields():
            if field.getIndex() >= firstField.getIndex() and field.getIndex() <= lastField.getIndex():
                selectedFields.append(field)
        # Verify that selected field range does not overlap existing layers (i.e. if the selected fields have the same parent)
        parent = selectedFields[0].getParentField()
        for selectedField in selectedFields:
            if parent != selectedField.getParentField():
                NetzobErrorMessage(_("Selected field range overlaps existing layer."))
                return
        # Retrieve layer's name
        dialog = Gtk.Dialog(title=_("Layer creation"), flags=0, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_size_request(200, 50)
        label = Gtk.Label("Name:")
        entry = Gtk.Entry()
        dialog.vbox.pack_start(label, True, True, 0)
        dialog.vbox.pack_start(entry, True, True, 0)
        dialog.show_all()
        result = dialog.run()
        if (result == Gtk.ResponseType.OK):
            name = entry.get_text()
            dialog.destroy()
            if name == "":
                return
        else:
            dialog.destroy()
            return
        # Create a new layer
        regex = ""
        for selectedField in selectedFields:
            regex += "(?:" + selectedField.getRegex()[1:]
        fieldLayer = Field(str(name), "(" + regex + ")", self.getSymbol())
        index_newField = 999999
        parentField = None
        for selectedField in selectedFields:
            parentField = selectedField.getParentField()
            if parentField.getLocalFields().index(selectedField) < index_newField:
                index_newField = parentField.getLocalFields().index(selectedField)  # Retrieve the lowest index of the new fields
            fieldLayer.addField(selectedField)
            parentField.getLocalFields().remove(selectedField)
        parentField.getLocalFields().insert(index_newField, fieldLayer)
#        self.getSymbol().getField().addField(fieldLayer, index_newField)
        self.vocabularyController.view.updateLeftPanel()
Example #14
0
    def rawExportProject_activate_cb(self, action):
        """Display the dialog in order to export the symbols when the
        user request it through the menu."""

        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."), self.view.mainWindow)
            return
        logging.debug("Export raw symbols")
        controller = RawExportController(self)
Example #15
0
 def doReadMessages(self):
     # Launch packets capturing
     try:
         self.model.startSniff(self.callback_readMessage)
     except NetzobImportException, importEx:
         if importEx.statusCode == WARNING:
             self.view.showWarning(importEx.message)
         else:
             NetzobErrorMessage(importEx.message)
Example #16
0
    def moveMessagesToOtherSymbol_activate_cb(self, action):
        """Callback executed when the user clicks on the move
        button. It retrieves the selected message, and change the cursor
        to show that moving is in progress. The user needs to click on a symbol to
        select the target symbol"""
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        selectedMessages = self.view.getSelectedMessagesInSelectedMessageTable(
        )
        if selectedMessages is None or len(selectedMessages) == 0:
            NetzobErrorMessage(_("No selected message."))
            return

        self.selectedMessagesToMove = selectedMessages

        cursor = Gdk.Cursor.new(Gdk.CursorType.FLEUR)
        self.view.vocabularyPanel.get_root_window().set_cursor(cursor)
 def doReadMessages(self):
     # Read PCAP file using PCAPImporter
     try:
         self.model.setBPFFilter(self.view.filterEntry.get_text().strip())
         self.model.readMessages()
     except NetzobImportException, importEx:
         if importEx.statusCode == WARNING:
             self.view.showWarning(importEx.message)
         else:
             NetzobErrorMessage(importEx.message)
Example #18
0
    def split_activate_cb(self, action):
        self.log.debug("Split field action requested by user")
        # Sanity check
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
#        displayedField = self.view.getDisplayedField()
#        if displayedField is None:
#            NetzobErrorMessage(_("No selected symbol."))
#            return
        fields = self.view.selectedMessageTable.treeViewHeaderGroup.getSelectedFields(
        )
        # Split field
        if fields is not None and len(fields) > 0:
            field = fields[-1]  # We take the last selected field
            controller = SplitFieldController(self, field)
            controller.run()
        else:
            NetzobErrorMessage(_("No selected field."))
Example #19
0
    def selectElement(self, widget):
        """selectElement:
                Give the ID of the variable associated to the selected element to the globally calling variableCreationController.

                @param widget: the widget on which this function is connected.
        """
        if self.selectedVariable is not None:
            self.variableCreationController.view.getWidg("IDEntry").set_text(str(self.selectedVariable.getID()))
            self.view.getWidg("dialog").destroy()
        else:
            NetzobErrorMessage(_("No variable selected."))
Example #20
0
    def importMessagesFromFile_activate_cb(self, action):
        """Execute all the plugins associated with
        file import."""
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return

        importerPlugins = NetzobPlugin.getLoadedPlugins(FileImporterPlugin)
        if len(importerPlugins) < 1:
            NetzobErrorMessage(_("No importer plugin available."))
            return

        chooser = ImportFileChooserDialog(importerPlugins)
        res = chooser.run()
        plugin = None
        if res == chooser.RESPONSE_OK:
            (filePathList, plugin) = chooser.getFilenameListAndPlugin()
        chooser.destroy()
        if plugin is not None:
            plugin.setFinish_cb(self.view.updateSymbolList)
            plugin.importFile(filePathList)
Example #21
0
    def actionCallback(self):
        """setVal:
                Callback when plugin is launched.

                @type val:
                @param val:
        """
        if self.netzob.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        controller = PeachExportController(self.netzob, self)
        controller.run()
Example #22
0
 def filterMessages_toggled_cb(self, action):
     """Callback executed when the user clicks
     on the filter messages toggle button"""
     if self.getCurrentProject() is None:
         if action.get_active():
             NetzobErrorMessage(_("No project selected."))
         action.set_active(False)
         return
     if action.get_active():
         self._view.filterMessagesController.show()
     else:
         self._view.filterMessagesController.hide()
Example #23
0
    def doReadMessages(self):
        # Sanity checks
        device = self.view.deviceCombo.get_active_text()
        if device is None:
            NetzobErrorMessage(_("Incorrect device"))
            return
        count = self.view.countEntry.get_text()
        try:
            count = int(count)
        except ValueError:
            NetzobErrorMessage(_("Incorrect count"))
            return
        if count < 1:
            NetzobErrorMessage(_("Incorrect count"))
        time = self.view.timeEntry.get_text()
        try:
            time = int(time)
        except ValueError:
            NetzobErrorMessage(_("Incorrect time"))
            return
        if time < 1:
            NetzobErrorMessage(_("Incorrect time"))

        # Launch packets capturing
        try:
            self.model.setBPFFilter(self.view.filterEntry.get_text().strip())
            self.model.readMessages(self.callback_readMessage, device, count,
                                    time)
        except NetzobImportException, importEx:
            if importEx.statusCode == WARNING:
                self.view.showWarning(importEx.message)
            else:
                NetzobErrorMessage(importEx.message)
    def actionCallback(self, vocabularyView):
        """setVal:
                Callback when plugin is launched.

                @type val:
                @param val:
        """
        if self.netzob.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        self.finish = vocabularyView.updateSymbolList
        controller = NetworkCapturerController(self.netzob, self)
        controller.run()
Example #25
0
    def run(self):
        data = []
        proj = self.netzob.getCurrentProject()

        if not proj:
            NetzobErrorMessage(_("No project selected."),
                               parent=self.netzob.view.mainWindow)
            return

        syms = proj.getVocabulary().getSymbols()
        dial = self.view.buildDialog()
        self.view.updateSymbols(syms)
        dial.show_all()
Example #26
0
 def deleteSymbolButton_clicked_cb(self, toolButton):
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     # Delete symbol
     for sym in self.view.getCheckedSymbolList():
         currentProject = self.netzob.getCurrentProject()
         currentVocabulary = currentProject.getVocabulary()
         for mess in sym.getMessages():
             currentVocabulary.removeMessage(mess)
         currentVocabulary.removeSymbol(sym)
         self.view.emptyMessageTableDisplayingSymbols([sym])
     # Update view
     self.view.updateLeftPanel()
     self.view.updateSelectedMessageTable()
Example #27
0
 def deleteMessages_activate_cb(self, action):
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     selectedMessages = self.view.getSelectedMessagesInSelectedMessageTable(
     )
     if selectedMessages == [] or selectedMessages is None:
         NetzobErrorMessage(_("No selected message."))
         return
     questionMsg = ngettext(
         "Click yes to confirm the deletion of the selected message",
         "Click yes to confirm the deletion of the selected messages",
         len(selectedMessages))
     result = NetzobQuestionMessage(questionMsg)
     if result != Gtk.ResponseType.YES:
         return
     for message in selectedMessages:
         # Remove message from model
         self.netzob.getCurrentProject().getVocabulary().removeMessage(
             message)
         message.getSymbol().removeMessage(message)
     # Update view
     self.view.updateSelectedMessageTable()
     self.view.updateLeftPanel()
    def findSizeFields_results_cb(self, results, savedEncapsulationLevel):
        dialog = Gtk.Dialog(title="Potential size fields and related payload", flags=0, buttons=None)
        ## ListStore format:
        # int: size field column
        # int: size field size
        # int: start column
        # int: substart column
        # int: end column
        # int: subend column
        # str: message rendered in cell
        treeview = Gtk.TreeView(Gtk.ListStore(int, int, int, int, int, int, str))
        cell = Gtk.CellRendererText()
        selection = treeview.get_selection()
        selection.connect("changed", self.sizeField_selected, savedEncapsulationLevel)
        column = Gtk.TreeViewColumn('Size field and related payload')
        column.pack_start(cell, True)
        column.add_attribute(cell, "text", 6)
        treeview.append_column(column)

       # Chose button
        but = NetzobButton("Apply size field")
        but.connect("clicked", self.applySizeField, dialog, savedEncapsulationLevel)
        dialog.action_area.pack_start(but, True, True, 0)

       # Text view containing potential size fields
        treeview.set_size_request(800, 300)

        if len(results) == 0:
            NetzobErrorMessage("No size field found.")
        else:
            for result in results:
                treeview.get_model().append(result)

            treeview.show()
            scroll = Gtk.ScrolledWindow()
            scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            scroll.show()
            scroll.add(treeview)
            dialog.vbox.pack_start(scroll, True, True, 0)
            dialog.connect("destroy", self.destroyDialogFindSizeFields, savedEncapsulationLevel)
            dialog.show()
Example #29
0
    def variableTable_activate_cb(self, action):
        if self.getCurrentProject() is None:
            NetzobErrorMessage(_("No project selected."))
            return
        builder2 = Gtk.Builder()
        builder2.add_from_file(
            os.path.join(ResourcesConfiguration.getStaticResources(), "ui",
                         "vocabulary", "variableTable.glade"))

        dialog = builder2.get_object("variableDialog")
        variable_liststore = builder2.get_object("variableListstore")

        # FIXME!
        # Missing code here!

        # ++CODE HERE++
        # ADD DATA NEEDED ON THE LISTSTORE FOR EVERY VARIABLE CREATE BY USER
        # EXEMPLE TO ADD ONE LINE WITH VALUE : [variable1, symbolToto, re{g0.6]ex, ipv4, initialValue : 192.168.0.6 ]
        # EXEMPLE CODE :
        # """i = variable_liststore.append()
        # variable_liststore.set(i, 0, "variable1")
        # variable_liststore.set(i, 1, "symbolToto")
        # variable_liststore.set(i, 2, "re{g0.6]ex")
        # variable_liststore.set(i, 3, "ipv4")
        # variable_liststore.set(i, 4, "initial value : 192.168.0.6")
        # i = variable_liststore.append()
        # variable_liststore.set(i, 0, "variable2")
        # variable_liststore.set(i, 1, "symbolToto")
        # variable_liststore.set(i, 2, "re{g1006.8]ex")
        # variable_liststore.set(i, 3, "binary")
        # variable_liststore.set(i, 4, "initial value : 0110, min bits : 2, max bits : 8")"""
        # ##

        result = dialog.run()

        if (result == 0):
            dialog.destroy()
Example #30
0
 def relationsViewer_activate_cb(self, action):
     if self.getCurrentProject() is None:
         NetzobErrorMessage(_("No project selected."))
         return
     relations = RelationsController(self)
     relations.show()