diff options
author | Gilbert Ramirez <gram@alumni.rice.edu> | 2016-09-13 22:33:54 -0500 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-09-15 04:13:59 +0000 |
commit | e8e193694a35779eaf506120ecd2567c98f652ac (patch) | |
tree | ac0d7dec782f7fee88129700dae81e06dcd9b191 /ui | |
parent | c711bc64573e20e343f343a53ad4d1d50add433d (diff) | |
download | wireshark-e8e193694a35779eaf506120ecd2567c98f652ac.tar.gz |
Qt: Option to copy bytes to clipboard as Escaped String
Some users need to copy the bytes to a Python script for
sending out through a raw socket. While they can modify a
plain hex dump, having Wireshark copy directly as a Python
string makes their work easier. This format also works
with Bash, so it is called "Escaped String". E.g.:
"\x55\xb5\xd4\x67\x03"
Change-Id: I0b6a5eb2e348f686397afda76095aaa2fb85c18d
Reviewed-on: https://code.wireshark.org/review/17696
Petri-Dish: Gilbert Ramirez <gram@alumni.rice.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/byte_view_tab.cpp | 28 | ||||
-rw-r--r-- | ui/qt/byte_view_tab.h | 4 | ||||
-rw-r--r-- | ui/qt/main_window.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window.ui | 10 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 10 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 3 | ||||
-rw-r--r-- | ui/qt/proto_tree.cpp | 3 |
7 files changed, 57 insertions, 2 deletions
diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 9d21e70cbf..4ec3d88a43 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -176,6 +176,31 @@ void ByteViewTab::copyBinary(const guint8 *data_p, int data_len) } } +void ByteViewTab::copyEscapedString(const guint8 *data_p, int data_len) +{ + QString clipboard_text; + + // Beginning quote + clipboard_text += QString("\""); + + for (int i = 0; i < data_len; i++) { + // Terminate this line if it has reached 16 bytes, + // unless it is also the very last byte in the data, + // as the termination after this for loop will take + // care of that. + if (i % 16 == 0 && i != 0 && i != data_len - 1) { + clipboard_text += QString("\" \\\n\""); + } + clipboard_text += QString("\\x%1").arg(data_p[i], 2, 16, QChar('0')); + } + // End quote + clipboard_text += QString("\"\n"); + + if (!clipboard_text.isEmpty()) { + qApp->clipboard()->setText(clipboard_text); + } +} + void ByteViewTab::copyData(ByteViewTab::copyDataType copy_type, field_info *fi) { int i = 0; @@ -219,6 +244,9 @@ void ByteViewTab::copyData(ByteViewTab::copyDataType copy_type, field_info *fi) case copyDataBinary: copyBinary(data_p, data_len); break; + case copyDataEscapedString: + copyEscapedString(data_p, data_len); + break; default: break; } diff --git a/ui/qt/byte_view_tab.h b/ui/qt/byte_view_tab.h index 31860fb935..041832809c 100644 --- a/ui/qt/byte_view_tab.h +++ b/ui/qt/byte_view_tab.h @@ -44,7 +44,8 @@ public: copyDataHexDump, copyDataPrintableText, copyDataHexStream, - copyDataBinary + copyDataBinary, + copyDataEscapedString }; explicit ByteViewTab(QWidget *parent = 0); @@ -61,6 +62,7 @@ private: void copyPrintableText(const guint8 *data_p, int data_len); void copyHexStream(const guint8 *data_p, int data_len); void copyBinary(const guint8 *data_p, int data_len); + void copyEscapedString(const guint8 *data_p, int data_len); protected: void tabInserted(int index); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index bc333dc9ec..04832a0e0d 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -616,6 +616,7 @@ private slots: void on_actionContextCopyBytesPrintableText_triggered(); void on_actionContextCopyBytesHexStream_triggered(); void on_actionContextCopyBytesBinary_triggered(); + void on_actionContextCopyBytesEscapedString_triggered(); void on_actionContextShowPacketBytes_triggered(); diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 8126d4a35d..bcbfb9e8c5 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -141,7 +141,7 @@ <x>0</x> <y>0</y> <width>960</width> - <height>22</height> + <height>21</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -2925,6 +2925,14 @@ <string>Create firewall ACL rules</string> </property> </action> + <action name="actionContextCopyBytesEscapedString"> + <property name="text"> + <string>…as Escaped String</string> + </property> + <property name="toolTip"> + <string>Copy packet bytes as a Escaped string</string> + </property> + </action> </widget> <layoutdefault spacing="6" margin="11"/> <customwidgets> diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 6a06b0a888..7da031d92a 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -3788,6 +3788,16 @@ void MainWindow::on_actionContextCopyBytesBinary_triggered() byte_view_tab_->copyData(ByteViewTab::copyDataBinary, fi); } +void MainWindow::on_actionContextCopyBytesEscapedString_triggered() +{ + QAction *ca = qobject_cast<QAction*>(sender()); + if (!ca) return; + + field_info *fi = ca->data().value<field_info *>(); + + byte_view_tab_->copyData(ByteViewTab::copyDataEscapedString, fi); +} + void MainWindow::on_actionContextWikiProtocolPage_triggered() { QAction *wa = qobject_cast<QAction*>(sender()); diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 5266af072c..7b71866e08 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -369,6 +369,9 @@ PacketList::PacketList(QWidget *parent) : action = window()->findChild<QAction *>("actionContextCopyBytesBinary"); submenu->addAction(action); copy_actions_ << action; + action = window()->findChild<QAction *>("actionContextCopyBytesEscapedString"); + submenu->addAction(action); + copy_actions_ << action; ctx_menu_.addSeparator(); ctx_menu_.addMenu(&proto_prefs_menu_); diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 93c2ad41fb..1527172834 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -241,6 +241,9 @@ ProtoTree::ProtoTree(QWidget *parent) : action = window()->findChild<QAction *>("actionContextCopyBytesBinary"); submenu->addAction(action); copy_actions_ << action; + action = window()->findChild<QAction *>("actionContextCopyBytesEscapedString"); + submenu->addAction(action); + copy_actions_ << action; action = window()->findChild<QAction *>("actionContextShowPacketBytes"); ctx_menu_.addAction(action); |