diff options
-rw-r--r-- | cfile.h | 1 | ||||
-rw-r--r-- | file.c | 8 | ||||
-rw-r--r-- | ui/qt/byte_view_tab.cpp | 18 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 24 | ||||
-rw-r--r-- | ui/qt/proto_tree.cpp | 13 | ||||
-rw-r--r-- | ui/qt/proto_tree.h | 1 |
6 files changed, 50 insertions, 15 deletions
@@ -102,6 +102,7 @@ typedef struct _capture_file { gboolean decode_data; /* TRUE if "String" search in "Packet details" was last selected */ gboolean packet_data; /* TRUE if "String" search in "Packet data" was last selected */ guint32 search_pos; /* Byte position of last byte found in a hex search */ + guint32 search_len; /* Length of bytes matching the search */ gboolean case_type; /* TRUE if case-insensitive text search */ GRegex *regex; /* Set if regular expression search */ search_charset_t scs_type; /* Character set for text search */ @@ -3084,6 +3084,7 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion) result = MR_MATCHED; cf->search_pos = i; /* Save the position of the last character for highlighting the field. */ + cf->search_len = (guint32)textlen; break; } } @@ -3131,6 +3132,7 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion) result = MR_MATCHED; cf->search_pos = i; /* Save the position of the last character for highlighting the field. */ + cf->search_len = (guint32)textlen; break; } } @@ -3178,6 +3180,7 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion) result = MR_MATCHED; cf->search_pos = i; /* Save the position of the last character for highlighting the field. */ + cf->search_len = (guint32)textlen; break; } i += 1; @@ -3221,6 +3224,7 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion) result = MR_MATCHED; cf->search_pos = i; /* Save the position of the last character for highlighting the field. */ + cf->search_len = (guint32)datalen; break; } } @@ -3251,7 +3255,8 @@ match_regex(capture_file *cf, frame_data *fdata, void *criterion _U_) { gint start_pos = 0, end_pos = 0; g_match_info_fetch_pos (match_info, 0, &start_pos, &end_pos); - cf->search_pos = end_pos; /* TODO: use start_pos to show correct length for regex */ + cf->search_pos = end_pos - 1; + cf->search_len = end_pos - start_pos; result = MR_MATCHED; } return result; @@ -3493,6 +3498,7 @@ find_packet(capture_file *cf, found = packet_list_select_row_from_data(new_fd); cf->search_in_progress = FALSE; cf->search_pos = 0; /* Reset the position */ + cf->search_len = 0; /* Reset length */ if (!found) { /* We didn't find a row corresponding to this frame. This means that the frame isn't being displayed currently, diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 128cc68523..cf405081a4 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -267,20 +267,10 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { } 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) { - const char *p = cap_file_->sfilter; - f_len = 0; - while (*p) { - if (g_ascii_isxdigit(*p++)) - f_len++; - } - f_len = (f_len + 1) / 2; - } else { - f_len = (int)strlen(cap_file_->sfilter); - } - f_start = cap_file_->search_pos - (f_len-1); + // 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. + f_start = cap_file_->search_pos - cap_file_->search_len + 1; + f_len = cap_file_->search_len; } else { f_start = fi->start; f_len = fi->length; diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index ae4bb53d18..dba7f54f7f 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -35,6 +35,7 @@ #include <epan/ipproto.h> #include <epan/packet.h> #include <epan/prefs.h> +#include <epan/proto.h> #include "ui/main_statusbar.h" #include "ui/packet_list_utils.h" @@ -480,6 +481,29 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS } byte_view_tab_->setCurrentIndex(0); } + + if (cap_file_->search_in_progress && + (cap_file_->search_pos != 0 || (cap_file_->string && cap_file_->decode_data))) + { + match_data mdata; + field_info *fi = NULL; + + if (cap_file_->string && cap_file_->decode_data) { + // The tree where the target string matched one of the labels was discarded in + // match_protocol_tree() so we have to search again in the latest tree. + if (cf_find_string_protocol_tree(cap_file_, cap_file_->edt->tree, &mdata)) { + fi = mdata.finfo; + } + } else { + // Find the finfo that corresponds to our byte. + fi = proto_find_field_from_offset(cap_file_->edt->tree, cap_file_->search_pos, + cap_file_->edt->tvb); + } + + if (fi && proto_tree_) { + proto_tree_->selectField(fi); + } + } } void PacketList::contextMenuEvent(QContextMenuEvent *event) diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index f4ecdc86d7..22e411fe88 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -545,6 +545,19 @@ void ProtoTree::itemDoubleClick(QTreeWidgetItem *item, int) { } } +void ProtoTree::selectField(field_info *fi) +{ + QTreeWidgetItemIterator iter(this); + while (*iter) { + if (fi == (*iter)->data(0, Qt::UserRole).value<field_info *>()) { + setCurrentItem(*iter); + scrollToItem(*iter); + break; + } + iter++; + } +} + /* * Editor modelines * diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index 298782cf36..a97f69c6a5 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -42,6 +42,7 @@ public: void fillProtocolTree(proto_tree *protocol_tree); void emitRelatedFrame(int related_frame, ft_framenum_type_t framenum_type = FT_FRAMENUM_NONE); void goToField(int hf_id); + void selectField(field_info *fi); void closeContextMenu(); void clear(); |