コード例 #1
0
    def __on_field_selected(self, tree, packet=None, proto=None, field=None):
        if not proto or not field:
            return

        if packet in self.notify:
            for cb in self.notify[packet]:
                cb(packet, proto, field, False)

        # We should select also the bounds in HexView
        page = ServiceBus().call('pm.sessions', 'get_current_session')

        if page:
            start = backend.get_field_offset(packet, proto, field)
            length = backend.get_field_size(proto, field)

            log.debug('Field %s start at %d and finish at %d' %
                      (field, start, length))

            if length == 0:
                # Deselect all
                page.packet_page.hexview.select_block(0, 0)
                return

            page.packet_page.hexview.select_block(start / 8,
                                                  max(length / 8, 1))
コード例 #2
0
    def __on_field_selected(self, tree, packet=None, proto=None, field=None):
        if not proto or not field:
            return

        if packet in self.notify:
            for cb in self.notify[packet]:
                cb(packet, proto, field, False)

        # We should select also the bounds in HexView
        page = ServiceBus().call('pm.sessions', 'get_current_session')

        if page:
            start  = backend.get_field_offset(packet, proto, field)
            length = backend.get_field_size(proto, field)

            log.debug('Field %s start at %d and finish at %d' % (field, start,
                                                                 length))

            if length == 0:
                # Deselect all
                page.packet_page.hexview.select_block(0, 0)
                return

            page.packet_page.hexview.select_block(start / 8, max(length / 8, 1))
コード例 #3
0
ファイル: plotter.py プロジェクト: Paulxia/PacketManipulator
    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
コード例 #4
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