forked from osmocom/wireshark
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>
This commit is contained in:
parent
c711bc6457
commit
e8e193694a
|
@ -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)
|
void ByteViewTab::copyData(ByteViewTab::copyDataType copy_type, field_info *fi)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -219,6 +244,9 @@ void ByteViewTab::copyData(ByteViewTab::copyDataType copy_type, field_info *fi)
|
||||||
case copyDataBinary:
|
case copyDataBinary:
|
||||||
copyBinary(data_p, data_len);
|
copyBinary(data_p, data_len);
|
||||||
break;
|
break;
|
||||||
|
case copyDataEscapedString:
|
||||||
|
copyEscapedString(data_p, data_len);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ public:
|
||||||
copyDataHexDump,
|
copyDataHexDump,
|
||||||
copyDataPrintableText,
|
copyDataPrintableText,
|
||||||
copyDataHexStream,
|
copyDataHexStream,
|
||||||
copyDataBinary
|
copyDataBinary,
|
||||||
|
copyDataEscapedString
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ByteViewTab(QWidget *parent = 0);
|
explicit ByteViewTab(QWidget *parent = 0);
|
||||||
|
@ -61,6 +62,7 @@ private:
|
||||||
void copyPrintableText(const guint8 *data_p, int data_len);
|
void copyPrintableText(const guint8 *data_p, int data_len);
|
||||||
void copyHexStream(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 copyBinary(const guint8 *data_p, int data_len);
|
||||||
|
void copyEscapedString(const guint8 *data_p, int data_len);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void tabInserted(int index);
|
void tabInserted(int index);
|
||||||
|
|
|
@ -616,6 +616,7 @@ private slots:
|
||||||
void on_actionContextCopyBytesPrintableText_triggered();
|
void on_actionContextCopyBytesPrintableText_triggered();
|
||||||
void on_actionContextCopyBytesHexStream_triggered();
|
void on_actionContextCopyBytesHexStream_triggered();
|
||||||
void on_actionContextCopyBytesBinary_triggered();
|
void on_actionContextCopyBytesBinary_triggered();
|
||||||
|
void on_actionContextCopyBytesEscapedString_triggered();
|
||||||
|
|
||||||
void on_actionContextShowPacketBytes_triggered();
|
void on_actionContextShowPacketBytes_triggered();
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>960</width>
|
<width>960</width>
|
||||||
<height>22</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -2925,6 +2925,14 @@
|
||||||
<string>Create firewall ACL rules</string>
|
<string>Create firewall ACL rules</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -3788,6 +3788,16 @@ void MainWindow::on_actionContextCopyBytesBinary_triggered()
|
||||||
byte_view_tab_->copyData(ByteViewTab::copyDataBinary, fi);
|
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()
|
void MainWindow::on_actionContextWikiProtocolPage_triggered()
|
||||||
{
|
{
|
||||||
QAction *wa = qobject_cast<QAction*>(sender());
|
QAction *wa = qobject_cast<QAction*>(sender());
|
||||||
|
|
|
@ -369,6 +369,9 @@ PacketList::PacketList(QWidget *parent) :
|
||||||
action = window()->findChild<QAction *>("actionContextCopyBytesBinary");
|
action = window()->findChild<QAction *>("actionContextCopyBytesBinary");
|
||||||
submenu->addAction(action);
|
submenu->addAction(action);
|
||||||
copy_actions_ << action;
|
copy_actions_ << action;
|
||||||
|
action = window()->findChild<QAction *>("actionContextCopyBytesEscapedString");
|
||||||
|
submenu->addAction(action);
|
||||||
|
copy_actions_ << action;
|
||||||
|
|
||||||
ctx_menu_.addSeparator();
|
ctx_menu_.addSeparator();
|
||||||
ctx_menu_.addMenu(&proto_prefs_menu_);
|
ctx_menu_.addMenu(&proto_prefs_menu_);
|
||||||
|
|
|
@ -241,6 +241,9 @@ ProtoTree::ProtoTree(QWidget *parent) :
|
||||||
action = window()->findChild<QAction *>("actionContextCopyBytesBinary");
|
action = window()->findChild<QAction *>("actionContextCopyBytesBinary");
|
||||||
submenu->addAction(action);
|
submenu->addAction(action);
|
||||||
copy_actions_ << action;
|
copy_actions_ << action;
|
||||||
|
action = window()->findChild<QAction *>("actionContextCopyBytesEscapedString");
|
||||||
|
submenu->addAction(action);
|
||||||
|
copy_actions_ << action;
|
||||||
|
|
||||||
action = window()->findChild<QAction *>("actionContextShowPacketBytes");
|
action = window()->findChild<QAction *>("actionContextShowPacketBytes");
|
||||||
ctx_menu_.addAction(action);
|
ctx_menu_.addAction(action);
|
||||||
|
|
Loading…
Reference in New Issue