aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorThibaut Vandervelden <thvdveld@vub.be>2022-01-13 14:48:21 +0100
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-01-16 08:07:44 +0000
commitc9e08b7be317e0e7e0cf95baa64f52d33b392964 (patch)
treeceea39158806b24ca518a49e55e7d35dc5a837b1 /ui
parent6ce15b9521d2af5e65ac989d0f8a119c10247781 (diff)
Add ShowAsRustArray option
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/show_packet_bytes_dialog.cpp41
-rw-r--r--ui/qt/show_packet_bytes_dialog.h1
2 files changed, 42 insertions, 0 deletions
diff --git a/ui/qt/show_packet_bytes_dialog.cpp b/ui/qt/show_packet_bytes_dialog.cpp
index 8285802677..a2f4311891 100644
--- a/ui/qt/show_packet_bytes_dialog.cpp
+++ b/ui/qt/show_packet_bytes_dialog.cpp
@@ -73,6 +73,7 @@ ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
ui->cbShowAs->addItem(tr("HTML"), ShowAsHTML);
ui->cbShowAs->addItem(tr("Image"), ShowAsImage);
ui->cbShowAs->addItem(tr("Raw"), ShowAsRAW);
+ ui->cbShowAs->addItem(tr("Rust Array"), ShowAsRustArray);
// UTF-8 is guaranteed to exist as a QTextCodec
ui->cbShowAs->addItem(tr("UTF-8"), ShowAsCodec);
ui->cbShowAs->addItem(tr("YAML"), ShowAsYAML);
@@ -286,6 +287,7 @@ void ShowPacketBytesDialog::copyBytes()
case ShowAsASCIIandControl:
case ShowAsCArray:
+ case ShowAsRustArray:
case ShowAsEBCDIC:
case ShowAsHexDump:
case ShowAsRAW:
@@ -319,6 +321,7 @@ void ShowPacketBytesDialog::saveAs()
case ShowAsASCII:
case ShowAsASCIIandControl:
case ShowAsCArray:
+ case ShowAsRustArray:
// We always save as UTF-8, so set text mode as we would for UTF-8
case ShowAsCodec:
case ShowAsHexDump:
@@ -344,6 +347,7 @@ void ShowPacketBytesDialog::saveAs()
case ShowAsASCIIandControl:
case ShowAsCArray:
+ case ShowAsRustArray:
case ShowAsEBCDIC:
case ShowAsHexDump:
case ShowAsYAML:
@@ -646,6 +650,43 @@ void ShowPacketBytesDialog::updatePacketBytes(void)
break;
}
+ case ShowAsRustArray:
+ {
+ int pos = 0, len = field_bytes_.length();
+ QString text("let packet_bytes: [u8; _] = [\n");
+
+ while (pos < len) {
+ gchar hexbuf[256];
+ char *cur = hexbuf;
+ int i;
+
+ *cur++ = ' ';
+ for (i = 0; i < 8 && pos + i < len; i++) {
+ // Prepend entries with " 0x"
+ *cur++ = ' ';
+ *cur++ = '0';
+ *cur++ = 'x';
+ *cur++ = hexchars[(field_bytes_[pos + i] & 0xf0) >> 4];
+ *cur++ = hexchars[field_bytes_[pos + i] & 0x0f];
+
+ // Delimit array entries with a comma
+ if (pos + i + 1 < len)
+ *cur++ = ',';
+ }
+
+ pos += i;
+ *cur++ = '\n';
+ *cur = 0;
+
+ text.append(hexbuf);
+ }
+
+ text.append("];\n");
+ ui->tePacketBytes->setLineWrapMode(QTextEdit::NoWrap);
+ ui->tePacketBytes->setPlainText(text);
+ break;
+ }
+
case ShowAsCodec:
{
// The QTextCodecs docs say that there's a flag to cause invalid
diff --git a/ui/qt/show_packet_bytes_dialog.h b/ui/qt/show_packet_bytes_dialog.h
index d3a16bc826..cc76b264a7 100644
--- a/ui/qt/show_packet_bytes_dialog.h
+++ b/ui/qt/show_packet_bytes_dialog.h
@@ -77,6 +77,7 @@ private:
ShowAsASCII,
ShowAsASCIIandControl,
ShowAsCArray,
+ ShowAsRustArray,
ShowAsEBCDIC,
ShowAsHexDump,
ShowAsHTML,