def __group_cell_func(self, col, cell, model, iter): obj = model.get_value(iter, 0) color, markup = self.style.mid[gtk.STATE_NORMAL], None if isinstance(obj, TFlag): color = None markup = '<b>%s</b>' % gobject.markup_escape_text(obj.ref) elif isinstance(obj, TField): # This is a property name = gobject.markup_escape_text(backend.get_field_name(obj.ref)) proto = obj.proto if not backend.is_flags(obj.ref): color = None if backend.is_field_autofilled(obj.ref): markup = '<i>%s</i>' % name else: markup = '<b>%s</b>' % name else: # Ok. This is the protocol name = gobject.markup_escape_text(backend.get_proto_name(obj)) markup = '<b>%s</b>' % name # Setting the values cell.set_property('cell-background-gdk', color) cell.set_property('markup', markup)
def __search_func(self, model, col, key, iter): field = model.get_value(iter, 0) if not field or backend.is_proto(field): return True if isinstance(field, TFlag): return not key in field.ref name = backend.get_field_name(field.ref) return not key in name
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)
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)
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