aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/show_packet_bytes_dialog.cpp
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2016-02-10 09:07:13 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-02-10 09:32:06 +0000
commite2bb302a794ea9b801f8f6f08fd3866452a2bcf1 (patch)
tree9d4126973232d6ec7359ca8a84feed3a92923d01 /ui/qt/show_packet_bytes_dialog.cpp
parentec70af4b6a1882289fc8aa554bcaf49fae6eaf35 (diff)
Qt: Add Show as Hex Dump in Show Packet Bytes
Change-Id: I81a42ef263d87880cfe0d1230dbbcb692e473d6f Reviewed-on: https://code.wireshark.org/review/13868 Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui/qt/show_packet_bytes_dialog.cpp')
-rw-r--r--ui/qt/show_packet_bytes_dialog.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/ui/qt/show_packet_bytes_dialog.cpp b/ui/qt/show_packet_bytes_dialog.cpp
index 65cbbfe83b..d09c7ac9b3 100644
--- a/ui/qt/show_packet_bytes_dialog.cpp
+++ b/ui/qt/show_packet_bytes_dialog.cpp
@@ -38,6 +38,7 @@
// - Add show as custom protocol in a Packet Details view
// - Add show as PDF or handle PDF as Image
// - Add decode from BASE64
+// - Use ByteViewText to ShowAsHexDump and supplementary view for custom protocol
// - Handle large data blocks
ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
@@ -66,6 +67,7 @@ ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
ui->cbShowAs->blockSignals(true);
ui->cbShowAs->addItem(tr("ASCII"), ShowAsASCII);
ui->cbShowAs->addItem(tr("EBCDIC"), ShowAsEBCDIC);
+ ui->cbShowAs->addItem(tr("Hex Dump"), ShowAsHexDump);
ui->cbShowAs->addItem(tr("HTML"), ShowAsHTML);
ui->cbShowAs->addItem(tr("Image"), ShowAsImage);
ui->cbShowAs->addItem(tr("ISO 8859-1"), ShowAsISO8859_1);
@@ -144,6 +146,7 @@ void ShowPacketBytesDialog::copyBytes()
case ShowAsASCII:
case ShowAsEBCDIC:
+ case ShowAsHexDump:
case ShowAsISO8859_1:
case ShowAsRAW:
wsApp->clipboard()->setText(ui->tePacketBytes->toPlainText());
@@ -177,6 +180,7 @@ void ShowPacketBytesDialog::saveAs()
case ShowAsASCII:
case ShowAsEBCDIC:
+ case ShowAsHexDump:
case ShowAsISO8859_1:
{
QTextStream out(&file);
@@ -289,6 +293,7 @@ void ShowPacketBytesDialog::updatePacketBytes(void)
{
ui->tePacketBytes->clear();
ui->tePacketBytes->setCurrentFont(wsApp->monospaceFont());
+ ui->tePacketBytes->setLineWrapMode(QTextEdit::WidgetWidth);
switch (show_as_) {
@@ -309,6 +314,50 @@ void ShowPacketBytesDialog::updatePacketBytes(void)
break;
}
+ case ShowAsHexDump:
+ {
+ static const gchar hexchars[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
+ int pos = 0;
+
+ while (pos < field_bytes_.length()) {
+ char hexbuf[256];
+ char *cur = hexbuf;
+ int i;
+
+ // Dump offset
+ cur += g_snprintf(cur, 20, "%08X ", pos);
+
+ // Dump bytes as hex
+ for (i = 0; i < 16 && pos + i < field_bytes_.length(); i++) {
+ *cur++ = hexchars[(field_bytes_[pos + i] & 0xf0) >> 4];
+ *cur++ = hexchars[field_bytes_[pos + i] & 0x0f];
+ *cur++ = ' ';
+ if (i == 7)
+ *cur++ = ' ';
+ }
+
+ while (cur < hexbuf + 61)
+ *cur++ = ' '; // Fill it up with space to column 61
+
+ // Dump bytes as text
+ for (i = 0; i < 16 && pos + i < field_bytes_.length(); i++) {
+ if (g_ascii_isprint(field_bytes_[pos + i]))
+ *cur++ = field_bytes_[pos + i];
+ else
+ *cur++ = '.';
+ if (i == 7)
+ *cur++ = ' ';
+ }
+ pos += i;
+ *cur++ = '\n';
+ *cur = 0;
+
+ ui->tePacketBytes->insertPlainText(hexbuf);
+ }
+ ui->tePacketBytes->setLineWrapMode(QTextEdit::NoWrap);
+ break;
+ }
+
case ShowAsHTML:
ui->tePacketBytes->setHtml(field_bytes_);
break;