Exemple #1
0
    def populate(self, packet, proto_inst):
        """
        Populate the store with the fields of Protocol
        @param packet a Packet that cointains the proto_inst
               or None if not parent is setted
        @param proto_inst a Protocol object instance
        """

        if not proto_inst:
            return

        self.packet = packet
        root_iter = self.store.append(None, [proto_inst])

        # We have to use the get_fields method
        for field in backend.get_proto_fields(proto_inst):

            if not backend.is_showable_field(field, packet):
                continue

            tfield = TField(field, proto_inst)
            flag_iter = self.store.append(root_iter, [tfield])

            if backend.is_flags(field):
                for flag in backend.get_flag_keys(field):
                    self.store.append(flag_iter, [TFlag(flag, tfield)])

        self.tree.expand_row((0, ), False)
Exemple #2
0
    def get_requested_size(self):
        # Get the requested size of the hex view part
        layout = self.create_pango_layout('FF')
        layout.set_font_description(pango.FontDescription(self.hex_font))

        atom_w, atom_h = layout.get_pixel_size()

        req_w = (atom_w + 4) * (16 + 1)
        req_h = (atom_h + 4) * (16 + 1)

        layout.set_font_description(pango.FontDescription(self.attr_font))
        layout.set_text('A')

        atom_w, atom_h = layout.get_pixel_size()

        fields = 0
        protos = [proto for proto in self.packet.get_protocols()]

        for proto in protos:
            for field in backend.get_proto_fields(proto):
                fields += 1

        protos = len(protos)

        req_w += 10 + (atom_w * 35) # 35 characters for attributes
        req_h = max(req_h, (fields + protos) * (atom_h + 4))

        return int(req_w), int(req_h)
    def get_requested_size(self):
        # Get the requested size of the hex view part
        layout = self.create_pango_layout('FF')
        layout.set_font_description(pango.FontDescription(self.hex_font))

        atom_w, atom_h = layout.get_pixel_size()

        req_w = (atom_w + 4) * (16 + 1)
        req_h = (atom_h + 4) * (16 + 1)

        layout.set_font_description(pango.FontDescription(self.attr_font))
        layout.set_text('A')

        atom_w, atom_h = layout.get_pixel_size()

        fields = 0
        protos = [proto for proto in self.packet.get_protocols()]

        for proto in protos:
            for field in backend.get_proto_fields(proto):
                fields += 1

        protos = len(protos)

        req_w += 10 + (atom_w * 35)  # 35 characters for attributes
        req_h = max(req_h, (fields + protos) * (atom_h + 4))

        return int(req_w), int(req_h)
    def draw_left(self, cr):
        layout = self.create_pango_layout('')
        layout.set_font_description(pango.FontDescription(self.title_font))

        attr_layout = self.create_pango_layout('')
        attr_layout.set_font_description(pango.FontDescription(self.attr_font))

        cr.move_to(4, 4)

        for protocol, color in self.protocols:
            name = backend.get_proto_name(protocol)
            layout.set_text(name)

            w, h = self.draw_box(cr, layout, fill=color)

            cr.rel_move_to(0, h + 4)

            x, y = cr.get_current_point()
            cr.move_to(x + 10, y)

            for field in backend.get_proto_fields(protocol):

                if not backend.is_showable_field(field, self.packet):
                    continue

                name = backend.get_field_name(field)
                value = str(backend.get_field_value_repr(protocol, field))

                text = '%s: %s' % (name, value)

                if len(text) > 35:
                    text = text[0:32] + "..."

                attr_layout.set_text(text)

                f_w, f_h = self.draw_text(cr, attr_layout)

                # Start point
                x, y = cr.get_current_point()
                self.fields[(protocol, name)] = [(x + f_w + 4, y + (f_h / 2.0))
                                                 ]

                cr.rel_move_to(0, f_h)

            cr.rel_move_to(-10, 10)
Exemple #5
0
    def draw_left(self, cr):
        layout = self.create_pango_layout('')
        layout.set_font_description(pango.FontDescription(self.title_font))

        attr_layout = self.create_pango_layout('')
        attr_layout.set_font_description(pango.FontDescription(self.attr_font))

        cr.move_to(4, 4)

        for protocol, color in self.protocols:
            name = backend.get_proto_name(protocol)
            layout.set_text(name)

            w, h = self.draw_box(cr, layout, fill=color)

            cr.rel_move_to(0, h + 4)

            x, y = cr.get_current_point()
            cr.move_to(x + 10, y)

            for field in backend.get_proto_fields(protocol):

                if not backend.is_showable_field(field, self.packet):
                    continue

                name = backend.get_field_name(field)
                value = str(backend.get_field_value_repr(protocol, field))

                text = '%s: %s' % (name, value)

                if len(text) > 35:
                    text = text[0:32] + "..."

                attr_layout.set_text(text)

                f_w, f_h = self.draw_text(cr, attr_layout)

                # Start point
                x, y = cr.get_current_point()
                self.fields[(protocol, name)] = [(x + f_w + 4, y + (f_h / 2.0))]

                cr.rel_move_to(0, f_h)

            cr.rel_move_to(-10, 10)
Exemple #6
0
    def draw_payload(self, cr):
        payload = self.packet.get_raw()

        layout = self.create_pango_layout('')
        layout.set_font_description(pango.FontDescription(self.hex_font))

        layout.set_text("FF")
        atom_x, atom_y = layout.get_pixel_size()

        atom_x += atom_x / 2.0
        atom_y += atom_y / 2.0

        start_x = self.allocation.width - (atom_x * 16) - 10

        cr.move_to(start_x, 4)

        # We should have space to place 16 bytes in hex

        dct = defaultdict(list)

        protocol_idx = 0

        for protocol, color in self.protocols:

            for field in backend.get_proto_fields(protocol):

                if not backend.is_showable_field(field, self.packet):
                    continue

                start = backend.get_field_offset(self.packet, protocol, field)
                end = backend.get_field_size(protocol, field)

                start /= 8

                dct[start].append((end, field))

            # Now we have the dict so we have to transform to
            # a sorted list

            lst = dct.items()
            lst.sort()

            tot_w = 0
            tot_h = 0

            for offset, child_list in lst:

                # We have also a child list to iterate
                size = 0

                if len(child_list) == 1 and child_list[0][0] == 0:
                    continue
                else:
                    for end, field in child_list:
                        size += end

                    size /= 8

                current_field = child_list[-1][1]
                field_name = backend.get_field_name(current_field)
                fill_color = self.__get_color(field_name)
                border_color = color

                line_x = offset % 16
                line_y = offset / 16

                txt = payload[offset:offset + size]

                if size + line_x > 16:
                    start = 16 - line_x

                    top_right = txt[0:start]

                    top_right = " ".join(["%02X" % ord(x) for x in top_right])
                    layout.set_text(top_right)

                    cr.move_to(start_x + (line_x * atom_x),
                               (line_y + protocol_idx) * atom_y + 4)

                    # Here we should write <==
                    self.draw_box(cr, layout, fill=fill_color,
                                  border=border_color, right=False)

                    w, h = 0, 0
                    txt = txt[start:]
                    lines = (len(txt) / 16) + 1

                    for i in xrange(lines):
                        right, left = False, False

                        if len(txt) > 16:
                            # here ===
                            part = txt[i * 16:(i * 16) + 16]
                        else:
                            right = True
                            part = txt[i * 16:]

                        if i == lines - 1:
                            right = True

                        cr.move_to(start_x,
                                   (line_y + protocol_idx + i + 1) * atom_y + 4)

                        part = " ".join(["%02X" % ord(x) for x in part])
                        layout.set_text(part)


                        w, h = self.draw_box(cr, layout, fill=fill_color,
                                             border=border_color,
                                             right=right, left=left)

                    # End point
                    self.fields[(protocol, field_name)].append(
                            (start_x + (w / 2.0),
                            (line_y + protocol_idx + lines + 1) * atom_y + 8))
                else:
                    txt = " ".join(["%02X" % ord(x) for x in txt])
                    layout.set_text(txt)

                    cr.move_to(start_x + (line_x * atom_x),
                               (line_y + protocol_idx) * atom_y + 4)

                    w, h = self.draw_box(cr, layout, fill=fill_color,
                                         border=border_color)

                    tot_w += w + 4
                    tot_h = max(tot_h, h)

                    # End point
                    self.fields[(protocol, field_name)].append(
                                (start_x + (line_x * atom_x) + (w / 2.0),
                                (tot_h + (protocol_idx + line_y) * atom_y + 8)))

                self.draw_line(cr, protocol, field_name)

            cr.rel_move_to(0, tot_h + 4)

            dct = defaultdict(list)

            protocol_idx += 1
    def draw_payload(self, cr):
        payload = self.packet.get_raw()

        layout = self.create_pango_layout('')
        layout.set_font_description(pango.FontDescription(self.hex_font))

        layout.set_text("FF")
        atom_x, atom_y = layout.get_pixel_size()

        atom_x += atom_x / 2.0
        atom_y += atom_y / 2.0

        start_x = self.allocation.width - (atom_x * 16) - 10

        cr.move_to(start_x, 4)

        # We should have space to place 16 bytes in hex

        dct = defaultdict(list)

        protocol_idx = 0

        for protocol, color in self.protocols:

            for field in backend.get_proto_fields(protocol):

                if not backend.is_showable_field(field, self.packet):
                    continue

                start = backend.get_field_offset(self.packet, protocol, field)
                end = backend.get_field_size(protocol, field)

                start /= 8

                dct[start].append((end, field))

            # Now we have the dict so we have to transform to
            # a sorted list

            lst = dct.items()
            lst.sort()

            tot_w = 0
            tot_h = 0

            for offset, child_list in lst:

                # We have also a child list to iterate
                size = 0

                if len(child_list) == 1 and child_list[0][0] == 0:
                    continue
                else:
                    for end, field in child_list:
                        size += end

                    size /= 8

                current_field = child_list[-1][1]
                field_name = backend.get_field_name(current_field)
                fill_color = self.__get_color(field_name)
                border_color = color

                line_x = offset % 16
                line_y = offset / 16

                txt = payload[offset:offset + size]

                if size + line_x > 16:
                    start = 16 - line_x

                    top_right = txt[0:start]

                    top_right = " ".join(["%02X" % ord(x) for x in top_right])
                    layout.set_text(top_right)

                    cr.move_to(start_x + (line_x * atom_x),
                               (line_y + protocol_idx) * atom_y + 4)

                    # Here we should write <==
                    self.draw_box(cr,
                                  layout,
                                  fill=fill_color,
                                  border=border_color,
                                  right=False)

                    w, h = 0, 0
                    txt = txt[start:]
                    lines = (len(txt) / 16) + 1

                    for i in xrange(lines):
                        right, left = False, False

                        if len(txt) > 16:
                            # here ===
                            part = txt[i * 16:(i * 16) + 16]
                        else:
                            right = True
                            part = txt[i * 16:]

                        if i == lines - 1:
                            right = True

                        cr.move_to(start_x,
                                   (line_y + protocol_idx + i + 1) * atom_y +
                                   4)

                        part = " ".join(["%02X" % ord(x) for x in part])
                        layout.set_text(part)

                        w, h = self.draw_box(cr,
                                             layout,
                                             fill=fill_color,
                                             border=border_color,
                                             right=right,
                                             left=left)

                    # End point
                    self.fields[(protocol, field_name)].append(
                        (start_x + (w / 2.0),
                         (line_y + protocol_idx + lines + 1) * atom_y + 8))
                else:
                    txt = " ".join(["%02X" % ord(x) for x in txt])
                    layout.set_text(txt)

                    cr.move_to(start_x + (line_x * atom_x),
                               (line_y + protocol_idx) * atom_y + 4)

                    w, h = self.draw_box(cr,
                                         layout,
                                         fill=fill_color,
                                         border=border_color)

                    tot_w += w + 4
                    tot_h = max(tot_h, h)

                    # End point
                    self.fields[(protocol, field_name)].append(
                        (start_x + (line_x * atom_x) + (w / 2.0),
                         (tot_h + (protocol_idx + line_y) * atom_y + 8)))

                self.draw_line(cr, protocol, field_name)

            cr.rel_move_to(0, tot_h + 4)

            dct = defaultdict(list)

            protocol_idx += 1