예제 #1
0
    def updateDisplayFollowingSplitPosition(self):
        messages = self.field.getCells()
        # Colorize text according to position
        self.view.buffer.get_buffer().set_text("")

        for m in messages:
            # Crate padding in case of right alignment
            if self.split_align == "right":
                padding = " " * (self.split_max_len - len(m))
                self.view.buffer.get_buffer().insert_with_tags_by_name(
                    self.view.buffer.get_buffer().get_end_iter(), padding,
                    "greenTag")
                split_index = -self.split_position
            else:
                split_index = self.split_position

            leftContent = m[:split_index]
            rightContent = m[split_index:]

            self.view.buffer.get_buffer().insert_with_tags_by_name(
                self.view.buffer.get_buffer().get_end_iter(),
                TypeConvertor.encodeNetzobRawToGivenType(
                    leftContent, self.field.getFormat()) + "  ", "redTag")
            self.view.buffer.get_buffer().insert_with_tags_by_name(
                self.view.buffer.get_buffer().get_end_iter(),
                TypeConvertor.encodeNetzobRawToGivenType(
                    rightContent, self.field.getFormat()) + "\n", "greenTag")

        value = self.split_position * (self.view.getMaxSizeOfHBuffer() /
                                       self.split_max_len)
        self.view.adjustHPositionOfBuffer(value)
예제 #2
0
    def changeAlignment_clicked_cb(self, widget):
        if self.split_align == "left":
            self.split_align = "right"
            self.view.invertScale(True)
        else:
            self.split_align = "left"
            self.view.invertScale(False)

        messages = self.field.getCells()

        # Adapt alignment
        self.view.buffer.get_buffer().set_text("")
        for m in messages:
            # Crate padding in case of right alignment
            if self.split_align == "right":
                padding = ""
                messageLen = len(m)
                for i in range(self.split_max_len - messageLen):
                    padding += " "
                self.view.buffer.get_buffer().insert_with_tags_by_name(
                    self.view.buffer.get_buffer().get_end_iter(), padding,
                    "greenTag")
                split_index = -self.split_position
            else:
                split_index = self.split_position
            self.view.buffer.get_buffer().insert_with_tags_by_name(
                self.view.buffer.get_buffer().get_end_iter(),
                TypeConvertor.encodeNetzobRawToGivenType(
                    m[:split_index], self.field.getFormat()) + "  ", "redTag")
            self.view.buffer.get_buffer().insert_with_tags_by_name(
                self.view.buffer.get_buffer().get_end_iter(),
                TypeConvertor.encodeNetzobRawToGivenType(
                    m[split_index:], self.field.getFormat()) + "\n",
                "greenTag")

        value = self.split_position * (self.view.getMaxSizeOfHBuffer() /
                                       self.split_max_len)
        self.view.adjustHPositionOfBuffer(value)
    def populateData(self):
        # Fieldname
        self.view.fieldName.set_text(self.field.getName())

        # Definition domain
        cells = self.field.getUniqValuesByField()
        tmpDomain = set()
        for cell in cells:
            tmpDomain.add(TypeConvertor.encodeNetzobRawToGivenType(cell, self.field.getFormat()))
        domain = sorted(tmpDomain)
        for elt in domain:
            self.view.domainListstore.append([elt])

        # Type guessing
        types = self.field.getPossibleTypes()
        for t in types:
            self.view.typeListstore.append([t])
예제 #4
0
    def populateData(self):
        # Fieldname
        self.view.fieldName.set_text(self.field.getName())

        # Definition domain
        cells = self.field.getUniqValuesByField()
        tmpDomain = set()
        for cell in cells:
            tmpDomain.add(
                TypeConvertor.encodeNetzobRawToGivenType(
                    cell, self.field.getFormat()))
        domain = sorted(tmpDomain)
        for elt in domain:
            self.view.domainListstore.append([elt])

        # Type guessing
        types = self.field.getPossibleTypes()
        for t in types:
            self.view.typeListstore.append([t])
예제 #5
0
    def apply(self, message):

        if self.unitsize != UnitSize.NONE:
            # First we apply the unit size
            # Default modulo = 2 => 8BITS
            if self.unitsize == UnitSize.BIT:
                modulo = 1
            else:
                modulo = UnitSize.getSizeInBits(self.unitsize) / 4

            splittedData = []
            tmpResult = ""
            for i in range(0, len(message)):
                if i > 0 and i % modulo == 0:
                    splittedData.append(tmpResult)
                    tmpResult = ""
                tmpResult = tmpResult + message[i]
            splittedData.append(tmpResult)
        else:
            splittedData = [message]

        encodedSplittedData = []
        # Now we have the message splitted per unit size
        # we apply endianess on it
        # we consider the normal mode is big-endian
        for i in range(0, len(splittedData)):
            origNetzobRaw = splittedData[i]

            # SPECIAL CASE : ASCII we do not compute endianess neither signed/unsigned
            if not self.formatType == Format.STRING and UnitSize.getSizeInBits(self.unitsize) >= 8 and not self.formatType == Format.BINARY:
                tmpVal = UnitSize.getSizeInBits(self.unitsize) / 4 - len(origNetzobRaw)
                if self.endianness == Endianess.BIG:
                    netzobRaw = (tmpVal * "0") + origNetzobRaw
                else:
                    netzobRaw = origNetzobRaw + (tmpVal * "0")

                # Convert in Python raw
                pythonraw = TypeConvertor.netzobRawToPythonRaw(netzobRaw)

                # Create transformer
                # - ENDIANESS
                transformer = ">"
                if self.endianness == Endianess.LITTLE:
                    transformer = "<"
                # - SIGNED/UNISGNED
                if self.sign == Sign.SIGNED:
                    transformer = transformer + (UnitSize.getPackDefiniton(self.unitsize)).lower()
                else:
                    transformer = transformer + (UnitSize.getPackDefiniton(self.unitsize)).upper()

                # Apply the transformation
                (unpackRaw,) = struct.unpack(transformer, pythonraw)

                localResult = ""
                fmt = "%" + str(UnitSize.getMaxDigitForTypeAndUnitSize(self.formatType, self.unitsize))
                if self.formatType == Format.OCTAL:
                    localResult = (fmt + "o") % unpackRaw
                elif self.formatType == Format.DECIMAL:
                    localResult = (fmt + "d") % unpackRaw
                elif self.formatType == Format.HEX:
                    localResult = (fmt + "s") % origNetzobRaw
                encodedSplittedData.append(localResult)
            elif self.formatType == Format.STRING:
                encodedSplittedData.append(TypeConvertor.netzobRawToString(origNetzobRaw))
            elif self.formatType == Format.BINARY:
                encodedSplittedData.append(TypeConvertor.netzobRawToBinary(origNetzobRaw))
            elif self.formatType == Format.IPv4:
                encodedSplittedData.append(TypeConvertor.netzobRawToIPv4(origNetzobRaw))
            elif UnitSize.getSizeInBits(self.unitsize) < UnitSize.getSizeInBits(UnitSize.BITS8):
                encodedSplittedData.append(TypeConvertor.encodeNetzobRawToGivenType(origNetzobRaw, self.formatType))

        # Before sending back (;D) we join everything
        return " ".join(encodedSplittedData)
    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
예제 #7
0
    def apply(self, message):

        if self.unitsize != UnitSize.NONE:
            # First we apply the unit size
            # Default modulo = 2 => 8BITS
            if self.unitsize == UnitSize.BIT:
                modulo = 1
            else:
                modulo = UnitSize.getSizeInBits(self.unitsize) / 4

            splittedData = []
            tmpResult = ""
            for i in range(0, len(message)):
                if i > 0 and i % modulo == 0:
                    splittedData.append(tmpResult)
                    tmpResult = ""
                tmpResult = tmpResult + message[i]
            splittedData.append(tmpResult)
        else:
            splittedData = [message]

        encodedSplittedData = []
        # Now we have the message splitted per unit size
        # we apply endianess on it
        # we consider the normal mode is big-endian
        for i in range(0, len(splittedData)):
            origNetzobRaw = splittedData[i]

            # SPECIAL CASE : ASCII we do not compute endianess neither signed/unsigned
            if not self.formatType == Format.STRING and UnitSize.getSizeInBits(
                    self.unitsize
            ) >= 8 and not self.formatType == Format.BINARY:
                tmpVal = UnitSize.getSizeInBits(
                    self.unitsize) / 4 - len(origNetzobRaw)
                if self.endianness == Endianess.BIG:
                    netzobRaw = (tmpVal * "0") + origNetzobRaw
                else:
                    netzobRaw = origNetzobRaw + (tmpVal * "0")

                # Convert in Python raw
                pythonraw = TypeConvertor.netzobRawToPythonRaw(netzobRaw)

                # Create transformer
                # - ENDIANESS
                transformer = ">"
                if self.endianness == Endianess.LITTLE:
                    transformer = "<"
                # - SIGNED/UNISGNED
                if self.sign == Sign.SIGNED:
                    transformer = transformer + (UnitSize.getPackDefiniton(
                        self.unitsize)).lower()
                else:
                    transformer = transformer + (UnitSize.getPackDefiniton(
                        self.unitsize)).upper()

                # Apply the transformation
                (unpackRaw, ) = struct.unpack(transformer, pythonraw)

                localResult = ""
                fmt = "%" + str(
                    UnitSize.getMaxDigitForTypeAndUnitSize(
                        self.formatType, self.unitsize))
                if self.formatType == Format.OCTAL:
                    localResult = (fmt + "o") % unpackRaw
                elif self.formatType == Format.DECIMAL:
                    localResult = (fmt + "d") % unpackRaw
                elif self.formatType == Format.HEX:
                    localResult = (fmt + "s") % origNetzobRaw
                encodedSplittedData.append(localResult)
            elif self.formatType == Format.STRING:
                encodedSplittedData.append(
                    TypeConvertor.netzobRawToString(origNetzobRaw))
            elif self.formatType == Format.BINARY:
                encodedSplittedData.append(
                    TypeConvertor.netzobRawToBinary(origNetzobRaw))
            elif self.formatType == Format.IPv4:
                encodedSplittedData.append(
                    TypeConvertor.netzobRawToIPv4(origNetzobRaw))
            elif UnitSize.getSizeInBits(
                    self.unitsize) < UnitSize.getSizeInBits(UnitSize.BITS8):
                encodedSplittedData.append(
                    TypeConvertor.encodeNetzobRawToGivenType(
                        origNetzobRaw, self.formatType))

        # Before sending back (;D) we join everything
        return " ".join(encodedSplittedData)
예제 #8
0
    def changeAlignment_clicked_cb(self, widget):
        if self.split_align == "left":
            self.split_align = "right"
            self.view.invertScale(True)
        else:
            self.split_align = "left"
            self.view.invertScale(False)

        messages = self.field.getCells()

        # Adapt alignment
        self.view.buffer.get_buffer().set_text("")
        for m in messages:
            # Crate padding in case of right alignment
            if self.split_align == "right":
                padding = ""
                messageLen = len(m)
                for i in range(self.split_max_len - messageLen):
                    padding += " "
                self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), padding, "greenTag")
                split_index = -self.split_position
            else:
                split_index = self.split_position
            self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), TypeConvertor.encodeNetzobRawToGivenType(m[:split_index], self.field.getFormat()) + "  ", "redTag")
            self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), TypeConvertor.encodeNetzobRawToGivenType(m[split_index:], self.field.getFormat()) + "\n", "greenTag")

        value = self.split_position * (self.view.getMaxSizeOfHBuffer() / self.split_max_len)
        self.view.adjustHPositionOfBuffer(value)
예제 #9
0
    def updateDisplayFollowingSplitPosition(self):
        messages = self.field.getCells()
        # Colorize text according to position
        self.view.buffer.get_buffer().set_text("")

        for m in messages:
            # Crate padding in case of right alignment
            if self.split_align == "right":
                padding = " " * (self.split_max_len - len(m))
                self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), padding, "greenTag")
                split_index = -self.split_position
            else:
                split_index = self.split_position

            leftContent = m[:split_index]
            rightContent = m[split_index:]

            self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), TypeConvertor.encodeNetzobRawToGivenType(leftContent, self.field.getFormat()) + "  ", "redTag")
            self.view.buffer.get_buffer().insert_with_tags_by_name(self.view.buffer.get_buffer().get_end_iter(), TypeConvertor.encodeNetzobRawToGivenType(rightContent, self.field.getFormat()) + "\n", "greenTag")

        value = self.split_position * (self.view.getMaxSizeOfHBuffer() / self.split_max_len)
        self.view.adjustHPositionOfBuffer(value)
예제 #10
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