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>
This commit is contained in:
parent
ec70af4b6a
commit
e2bb302a79
|
@ -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;
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
enum ShowAsType {
|
||||
ShowAsASCII,
|
||||
ShowAsEBCDIC,
|
||||
ShowAsHexDump,
|
||||
ShowAsHTML,
|
||||
ShowAsImage,
|
||||
ShowAsISO8859_1,
|
||||
|
|
Loading…
Reference in New Issue