示例#1
0
 def loadFromCSV(fileToImport):
     result = []
     with open(fileToImport, 'rb') as csvFile:
         # We use the sniffer to compute which dialect is used in current CSV
         dialect = csv.Sniffer().sniff(csvFile.read(1024))
         csvFile.seek(0)
         dataReader = csv.reader(csvFile, dialect)
         errorMessage = None
         idLine = 0
         for row in dataReader:
             idLine += 1
             if len(row) != 3:
                 errorMessage = _("line {0} in CSV has not 3 columns, format must be : Name, Type, Value".format(idLine))
                 break
             else:
                 try:
                     if len(row[2]) > 0:
                         formatData = str.lower(row[1])
                         if formatData in Format.getExtendedSupportedFormats():
                             data = ApplicativeData(uuid.uuid4(), row[0], formatData, row[2])
                             result.append(data)
                         else:
                             logging.warning("Cannot import data with format : {0}, only {1} available".format(formatData, Format.getExtendedSupportedFormats()))
                     else:
                         logging.warning("Don't consider empty applicative data.")
                 except ApplicativeDataException, e:
                     errorMessage = _("line {0} in CSV, invalid format of data : {1}".format(idLine, e))
                     break
示例#2
0
    def _initializeComboBoxes(self):
        """This function permits to update the several combobox in the
        dialog box."""

        vocabParameters = self.currentProject.getConfiguration(
        ).getVocabularyInferenceParameter

        formats = Format.getSupportedFormats()
        projectFormat = vocabParameters(
            ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)

        sizes = [
            UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16,
            UnitSize.BITS32, UnitSize.BITS64
        ]
        projectSize = vocabParameters(
            ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE)

        signs = [Sign.SIGNED, Sign.UNSIGNED]
        projectSign = vocabParameters(
            ProjectConfiguration.VOCABULARY_GLOBAL_SIGN)

        endianesses = [Endianess.BIG, Endianess.LITTLE]
        projectEndianess = vocabParameters(
            ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS)

        self.view.initializeComboBoxes(formats, projectFormat, sizes,
                                       projectSize, signs, projectSign,
                                       endianesses, projectEndianess)
示例#3
0
    def getProperties(self):
        properties = PropertyList()
        configuration = self.getConfiguration()
        properties.append(Property('workspace', Format.STRING, self.getPath()))
        prop = Property('name', Format.STRING, self.getName())
        prop.setIsEditable(True)
        properties.append(prop)

        prop = Property('description', Format.STRING, self.getDescription())
        prop.setIsEditable(True)
        properties.append(prop)

        properties.append(
            Property('date', Format.STRING, self.getCreationDate()))
        properties.append(
            Property('symbols', Format.DECIMAL,
                     len(self.getVocabulary().getSymbols())))
        properties.append(
            Property('messages', Format.DECIMAL,
                     len(self.getVocabulary().getMessages())))
        fields = 0
        for sym in self.getVocabulary().getSymbols():
            fields = fields + len(sym.getField().getExtendedFields())
        properties.append(Property('fields', Format.DECIMAL, fields))

        prop = Property(
            configuration.VOCABULARY_GLOBAL_FORMAT, Format.STRING,
            configuration.getVocabularyInferenceParameter(
                configuration.VOCABULARY_GLOBAL_FORMAT))
        prop.setIsEditable(True)
        prop.setPossibleValues(Format.getSupportedFormats())
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_UNITSIZE, Format.STRING,
            configuration.getVocabularyInferenceParameter(
                configuration.VOCABULARY_GLOBAL_UNITSIZE))
        prop.setIsEditable(True)
        prop.setPossibleValues([
            UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16,
            UnitSize.BITS32, UnitSize.BITS64
        ])
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_SIGN, Format.STRING,
            configuration.getVocabularyInferenceParameter(
                configuration.VOCABULARY_GLOBAL_SIGN))
        prop.setIsEditable(True)
        prop.setPossibleValues([Sign.SIGNED, Sign.UNSIGNED])
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_ENDIANESS, Format.STRING,
            configuration.getVocabularyInferenceParameter(
                configuration.VOCABULARY_GLOBAL_ENDIANESS))
        prop.setIsEditable(True)
        prop.setPossibleValues([Endianess.BIG, Endianess.LITTLE])
        properties.append(prop)
        return properties
示例#4
0
 def formatEventBox_button_press_event_cb(self, *args):
     supportedFormats = Format.getSupportedFormats()
     currentFormat = self.field.getFormat()
     currentFormatIdx = supportedFormats.index(currentFormat)
     newFormat = supportedFormats[(currentFormatIdx + 1) % len(supportedFormats)]
     self.field.setFormat(newFormat)
     self.setFormat(newFormat)
     self.messageTableView.updateMessageTableListStore()
示例#5
0
文件: Project.py 项目: otetard/netzob
    def getProperties(self):
        properties = PropertyList()
        configuration = self.getConfiguration()
        properties.append(Property("workspace", Format.STRING, self.getPath()))
        prop = Property("name", Format.STRING, self.getName())
        prop.setIsEditable(True)
        properties.append(prop)

        prop = Property("description", Format.STRING, self.getDescription())
        prop.setIsEditable(True)
        properties.append(prop)

        properties.append(Property("date", Format.STRING, self.getCreationDate()))
        properties.append(Property("symbols", Format.DECIMAL, len(self.getVocabulary().getSymbols())))
        properties.append(Property("messages", Format.DECIMAL, len(self.getVocabulary().getMessages())))
        fields = 0
        for sym in self.getVocabulary().getSymbols():
            fields = fields + len(sym.getField().getExtendedFields())
        properties.append(Property("fields", Format.DECIMAL, fields))

        prop = Property(
            configuration.VOCABULARY_GLOBAL_FORMAT,
            Format.STRING,
            configuration.getVocabularyInferenceParameter(configuration.VOCABULARY_GLOBAL_FORMAT),
        )
        prop.setIsEditable(True)
        prop.setPossibleValues(Format.getSupportedFormats())
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_UNITSIZE,
            Format.STRING,
            configuration.getVocabularyInferenceParameter(configuration.VOCABULARY_GLOBAL_UNITSIZE),
        )
        prop.setIsEditable(True)
        prop.setPossibleValues(
            [UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16, UnitSize.BITS32, UnitSize.BITS64]
        )
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_SIGN,
            Format.STRING,
            configuration.getVocabularyInferenceParameter(configuration.VOCABULARY_GLOBAL_SIGN),
        )
        prop.setIsEditable(True)
        prop.setPossibleValues([Sign.SIGNED, Sign.UNSIGNED])
        properties.append(prop)

        prop = Property(
            configuration.VOCABULARY_GLOBAL_ENDIANESS,
            Format.STRING,
            configuration.getVocabularyInferenceParameter(configuration.VOCABULARY_GLOBAL_ENDIANESS),
        )
        prop.setIsEditable(True)
        prop.setPossibleValues([Endianess.BIG, Endianess.LITTLE])
        properties.append(prop)
        return properties
示例#6
0
 def formatEventBox_button_press_event_cb(self, *args):
     supportedFormats = Format.getSupportedFormats()
     currentFormat = self.field.getFormat()
     currentFormatIdx = supportedFormats.index(currentFormat)
     newFormat = supportedFormats[(currentFormatIdx + 1) %
                                  len(supportedFormats)]
     self.field.setFormat(newFormat)
     self.setFormat(newFormat)
     self.messageTableView.updateMessageTableListStore()
示例#7
0
 def loadFromCSV(fileToImport):
     result = []
     with open(fileToImport, 'rb') as csvFile:
         # We use the sniffer to compute which dialect is used in current CSV
         dialect = csv.Sniffer().sniff(csvFile.read(1024))
         csvFile.seek(0)
         dataReader = csv.reader(csvFile, dialect)
         errorMessage = None
         idLine = 0
         for row in dataReader:
             idLine += 1
             if len(row) != 3:
                 errorMessage = _(
                     "line {0} in CSV has not 3 columns, format must be : Name, Type, Value"
                     .format(idLine))
                 break
             else:
                 try:
                     if len(row[2]) > 0:
                         formatData = str.lower(row[1])
                         if formatData in Format.getExtendedSupportedFormats(
                         ):
                             data = ApplicativeData(uuid.uuid4(), row[0],
                                                    formatData, row[2])
                             result.append(data)
                         else:
                             logging.warning(
                                 "Cannot import data with format : {0}, only {1} available"
                                 .format(
                                     formatData,
                                     Format.getExtendedSupportedFormats()))
                     else:
                         logging.warning(
                             "Don't consider empty applicative data.")
                 except ApplicativeDataException, e:
                     errorMessage = _(
                         "line {0} in CSV, invalid format of data : {1}".
                         format(idLine, e))
                     break
    def _initializeComboBoxes(self):
        """This function permits to update the several combobox in the
        dialog box."""

        vocabParameters = self.currentProject.getConfiguration().getVocabularyInferenceParameter

        formats = Format.getSupportedFormats()
        projectFormat = vocabParameters(ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)

        sizes = [UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16, UnitSize.BITS32, UnitSize.BITS64]
        projectSize = vocabParameters(ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE)

        signs = [Sign.SIGNED, Sign.UNSIGNED]
        projectSign = vocabParameters(ProjectConfiguration.VOCABULARY_GLOBAL_SIGN)

        endianesses = [Endianess.BIG, Endianess.LITTLE]
        projectEndianess = vocabParameters(ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS)

        self.view.initializeComboBoxes(formats, projectFormat,
                                       sizes, projectSize,
                                       signs, projectSign,
                                       endianesses, projectEndianess)
    def build_encoding_submenu(self):
        menu = Gtk.Menu()

        field = self.controller.field

        # Retrieve all the values in the current field
        cells = field.getUniqValuesByField()

        # Retrieve the selected message and field content
        if len(self.controller.messages) > 0 and self.controller.messages[0] is not None:
            # Retrieve content of the field
            field_content = self.controller.messages[0].applyAlignment()[self.controller.field.getIndex()]
        else:
            field_content = None

        # Format submenu
        possible_choices = Format.getPossibleFormats(cells)
        subMenu = Gtk.Menu()
        for value in possible_choices:
            label = value

            # Compute if its activated
            toggled = False
            if field.getFormat() == value:
                toggled = True

            # Compute the label
            if field_content is not None:
                # Get preview of field content
                text_preview = TypeConvertor.encodeNetzobRawToGivenType(field_content, value)
                # TRANSLATORS: {0} is the value of the format (binary,
                # hex, decimal, etc.) and {1} is the preview of the
                # convertion.
                label = _("{0} ({1}…)").format(value, text_preview[:10])

            # Create the check item
            item = Gtk.CheckMenuItem(label)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeFormat_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Format"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Unitsize submenu
        possible_choices = [UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16, UnitSize.BITS32, UnitSize.BITS64]
        subMenu = Gtk.Menu()
        for value in possible_choices:

            # Compute if its activated
            toggled = False
            if field.getUnitSize() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeUnitSize_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("UnitSize"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Sign submenu
        possible_choices = [Sign.SIGNED, Sign.UNSIGNED]
        subMenu = Gtk.Menu()
        for value in possible_choices:

            # Compute if its activated
            toggled = False
            if field.getSign() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeSign_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Sign"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Endianess submenu
        possible_choices = [Endianess.BIG, Endianess.LITTLE]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if field.getEndianess() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeEndianess_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Endianess"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)
        return menu
    def build_encoding_submenu(self):
        """Create a GTK menu which contains
        entries to edit the visualizations formats of
        selected layer"""
        menu = Gtk.Menu()

        # Format submenu
        possible_choices = Format.getSupportedFormats()
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getFormat() == value:
                    toggled = True

            # Create the check item
            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeFormat_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Format"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Unitsize submenu
        possible_choices = [
            UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16,
            UnitSize.BITS32, UnitSize.BITS64
        ]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getUnitSize() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeUnitSize_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("UnitSize"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Sign submenu
        possible_choices = [Sign.SIGNED, Sign.UNSIGNED]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getSign() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeSign_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Sign"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Endianess submenu
        possible_choices = [Endianess.BIG, Endianess.LITTLE]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getEndianess() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeEndianess_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Endianess"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)
        return menu
    def build_encoding_submenu(self):
        """Create a GTK menu which contains
        entries to edit the visualizations formats of
        selected layer"""
        menu = Gtk.Menu()

        # Format submenu
        possible_choices = Format.getSupportedFormats()
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getFormat() == value:
                    toggled = True

            # Create the check item
            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeFormat_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Format"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Unitsize submenu
        possible_choices = [UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16, UnitSize.BITS32, UnitSize.BITS64]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getUnitSize() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeUnitSize_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("UnitSize"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Sign submenu
        possible_choices = [Sign.SIGNED, Sign.UNSIGNED]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getSign() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeSign_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Sign"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Endianess submenu
        possible_choices = [Endianess.BIG, Endianess.LITTLE]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if self.multipleLayers is False:
                if self.controller.layers[0].getEndianess() == value:
                    toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeEndianess_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Endianess"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)
        return menu
示例#12
0
    def build_encoding_submenu(self):
        menu = Gtk.Menu()

        field = self.controller.field

        # Retrieve all the values in the current field
        cells = field.getUniqValuesByField()

        # Retrieve the selected message and field content
        if len(self.controller.messages
               ) > 0 and self.controller.messages[0] is not None:
            # Retrieve content of the field
            field_content = self.controller.messages[0].applyAlignment()[
                self.controller.field.getIndex()]
        else:
            field_content = None

        # Format submenu
        possible_choices = Format.getPossibleFormats(cells)
        subMenu = Gtk.Menu()
        for value in possible_choices:
            label = value

            # Compute if its activated
            toggled = False
            if field.getFormat() == value:
                toggled = True

            # Compute the label
            if field_content is not None:
                # Get preview of field content
                text_preview = TypeConvertor.encodeNetzobRawToGivenType(
                    field_content, value)
                # TRANSLATORS: {0} is the value of the format (binary,
                # hex, decimal, etc.) and {1} is the preview of the
                # convertion.
                label = _("{0} ({1}…)").format(value, text_preview[:10])

            # Create the check item
            item = Gtk.CheckMenuItem(label)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeFormat_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Format"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Unitsize submenu
        possible_choices = [
            UnitSize.NONE, UnitSize.BITS4, UnitSize.BITS8, UnitSize.BITS16,
            UnitSize.BITS32, UnitSize.BITS64
        ]
        subMenu = Gtk.Menu()
        for value in possible_choices:

            # Compute if its activated
            toggled = False
            if field.getUnitSize() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeUnitSize_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("UnitSize"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Sign submenu
        possible_choices = [Sign.SIGNED, Sign.UNSIGNED]
        subMenu = Gtk.Menu()
        for value in possible_choices:

            # Compute if its activated
            toggled = False
            if field.getSign() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)

            item.show()
            item.connect("activate", self.controller.changeSign_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Sign"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)

        # Endianess submenu
        possible_choices = [Endianess.BIG, Endianess.LITTLE]
        subMenu = Gtk.Menu()
        for value in possible_choices:
            # Compute if its activated
            toggled = False
            if field.getEndianess() == value:
                toggled = True

            item = Gtk.CheckMenuItem(value)
            item.set_active(toggled)
            item.show()
            item.connect("activate", self.controller.changeEndianess_cb, value)
            subMenu.append(item)
        item = Gtk.MenuItem(_("Endianess"))
        item.set_submenu(subMenu)
        item.show()
        menu.append(item)
        return menu