From 0a28fb8f6a354aa9a446b6bf70733c305534e074 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 30 Oct 2012 19:21:24 +0000 Subject: Update the Qt byte view widget to reflect the recent changes in the GTK+ byte view. Move the packet_char_enc enum from packet.h to frame_data.h. Make the encoding flag a packet_char_enc and make it one bit. Get rid of the "cfile" global in a few places. C++-ize some of the font code. Clean up some variable names. svn path=/trunk/; revision=45838 --- ui/qt/byte_view_tab.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 12 deletions(-) (limited to 'ui/qt/byte_view_tab.cpp') diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 7828e572a2..6c84fb5ccb 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -33,11 +33,11 @@ ByteViewTab::ByteViewTab(QWidget *parent) : addTab(); } -void ByteViewTab::addTab(const char *name, tvbuff_t *tvb, proto_tree *tree, QTreeWidget *protoTree, unsigned int encoding) { - ByteViewText *byteViewText = new ByteViewText(this, tvb, tree, protoTree, encoding); +void ByteViewTab::addTab(const char *name, tvbuff_t *tvb, proto_tree *tree, QTreeWidget *protoTree, packet_char_enc encoding) { + ByteViewText *byte_view_text = new ByteViewText(this, tvb, tree, protoTree, encoding); - byteViewText->setAccessibleName(name); - QTabWidget::addTab(byteViewText, name); + byte_view_text->setAccessibleName(name); + QTabWidget::addTab(byte_view_text, name); } void ByteViewTab::tabInserted(int index) { @@ -58,18 +58,27 @@ void ByteViewTab::setTabsVisible() { } void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { - if (current) { + if (current && cap_file_) { field_info *fi; fi = current->data(0, Qt::UserRole).value(); // g_log(NULL, G_LOG_LEVEL_DEBUG, "fi selected %p", fi); int i = 0; - ByteViewText *byteViewText = dynamic_cast(widget(i)); - while (byteViewText) { - if (byteViewText->hasDataSource(fi->ds_tvb)) { + ByteViewText *byte_view_text = dynamic_cast(widget(i)); + while (byte_view_text) { + if (byte_view_text->hasDataSource(fi->ds_tvb)) { QTreeWidgetItem *parent = current->parent(); field_info *parent_fi = NULL; + int f_start = -1, f_end = -1, f_len = -1; + guint32 bmask = 0x00; + int bmask_le = 0; + int fa_start = -1, fa_end = -1, fa_len = -1; + int p_start = -1, p_end = -1, p_len = -1; + guint len = tvb_length(fi->ds_tvb); + +// byte_view_text->setEncoding(cap_file_->current_frame->flags.encoding); + // Find and highlight the protocol bytes while (parent && parent->parent()) { parent = parent->parent(); } @@ -77,18 +86,98 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { parent_fi = parent->data(0, Qt::UserRole).value(); } if (parent_fi && parent_fi->ds_tvb == fi->ds_tvb) { - byteViewText->highlight(parent_fi->start, parent_fi->length, true); + p_start = parent_fi->start; + p_len = parent_fi->length; + } + + if (cap_file_->search_in_progress && (cap_file_->hex || (cap_file_->string && cap_file_->packet_data))) { + /* In the hex view, only highlight the target bytes or string. The entire + field can then be displayed by clicking on any of the bytes in the field. */ + if (cap_file_->hex) { + f_len = (int)strlen(cap_file_->sfilter)/2; + } else { + f_len = (int)strlen(cap_file_->sfilter); + } + f_start = cap_file_->search_pos - (f_len-1); } else { - byteViewText->highlight(0, 0, true); + f_start = fi->start; + f_len = fi->length; + } + + /* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */ + if (fi->hfinfo) bmask = fi->hfinfo->bitmask; + fa_start = fi->appendix_start; + fa_len = fi->appendix_length; + + if (FI_GET_FLAG(fi, FI_LITTLE_ENDIAN)) + bmask_le = 1; + else if (FI_GET_FLAG(fi, FI_BIG_ENDIAN)) + bmask_le = 0; + else { /* unknown endianess - disable mask + bmask_le = (G_BYTE_ORDER == G_LITTLE_ENDIAN); + */ + bmask = 0x00; + } + + if (bmask == 0x00) { + int bito = FI_GET_BITS_OFFSET(fi); + int bitc = FI_GET_BITS_SIZE(fi); + int bitt = bito + bitc; + + /* construct mask using bito & bitc */ + /* XXX, mask has only 32 bit, later we can store bito&bitc, and use them (which should be faster) */ + if (bitt > 0 && bitt < 32) { + + bmask = ((1 << bitc) - 1) << ((8-bitt) & 7); + bmask_le = 0; /* ? */ + } + } + + if (p_start >= 0 && p_len > 0 && (guint)p_start < len) { + p_end = p_start + p_len; + } + if (f_start >= 0 && f_len > 0 && (guint)f_start < len) { + f_end = f_start + f_len; } - byteViewText->highlight(fi->start, fi->length); + if (fa_start >= 0 && fa_len > 0 && (guint)fa_start < len) { + fa_end = fa_start + fa_len; + } + + if (f_end == -1 && fa_end != -1) { + f_start = fa_start; + bmask = 0x00; + f_end = fa_end; + fa_start = fa_end = -1; + } + + /* don't exceed the end of available data */ + if (p_end != -1 && (guint)p_end > len) p_end = len; + if (f_end != -1 && (guint)f_end > len) f_end = len; + if (fa_end != -1 && (guint)fa_end > len) fa_end = len; + + // Protocol + byte_view_text->setProtocolHighlight(p_start, p_end); + + // Field bytes + byte_view_text->setFieldHighlight(f_start, f_end); + + // Appendix (trailer) bytes + byte_view_text->setFieldAppendixHighlight(fa_start, fa_end); + setCurrentIndex(i); + + byte_view_text->render(); } - byteViewText = dynamic_cast(widget(++i)); + byte_view_text = dynamic_cast(widget(++i)); } } } +void ByteViewTab::setCaptureFile(capture_file *cf) +{ + cap_file_ = cf; +} + /* * Editor modelines * -- cgit v1.2.1