2015-02-11 23:00:27 +00:00
|
|
|
/* packet_dialog.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2015-02-11 23:00:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "packet_dialog.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_packet_dialog.h>
|
2015-02-11 23:00:27 +00:00
|
|
|
|
2015-02-12 23:35:59 +00:00
|
|
|
#include "file.h"
|
|
|
|
|
2015-02-11 23:00:27 +00:00
|
|
|
#include "epan/column.h"
|
|
|
|
#include "epan/ftypes/ftypes.h"
|
|
|
|
|
|
|
|
#include "frame_tvbuff.h"
|
|
|
|
|
2015-10-04 17:10:29 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2015-02-12 18:17:05 +00:00
|
|
|
|
2015-02-11 23:00:27 +00:00
|
|
|
#include "byte_view_tab.h"
|
|
|
|
#include "proto_tree.h"
|
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
2017-10-30 12:58:28 +00:00
|
|
|
#include <ui/qt/utils/field_information.h>
|
2015-02-11 23:00:27 +00:00
|
|
|
#include <QTreeWidgetItemIterator>
|
|
|
|
|
|
|
|
// To do:
|
|
|
|
// - Copy over experimental packet editing code.
|
|
|
|
// - Fix ElidedText width.
|
|
|
|
|
2015-03-02 04:01:17 +00:00
|
|
|
PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, frame_data *fdata) :
|
2015-02-11 23:00:27 +00:00
|
|
|
WiresharkDialog(parent, cf),
|
|
|
|
ui(new Ui::PacketDialog),
|
2018-01-22 08:42:09 +00:00
|
|
|
proto_tree_(NULL),
|
2019-04-11 22:08:23 +00:00
|
|
|
byte_view_tab_(NULL)
|
2015-02-11 23:00:27 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-02-28 18:23:20 +00:00
|
|
|
loadGeometry(parent.width() * 4 / 5, parent.height() * 4 / 5);
|
2015-02-12 18:17:05 +00:00
|
|
|
ui->hintLabel->setSmallText();
|
2019-04-11 22:08:23 +00:00
|
|
|
|
|
|
|
wtap_rec_init(&rec_);
|
|
|
|
ws_buffer_init(&buf_, 1514);
|
|
|
|
|
2018-01-22 08:42:09 +00:00
|
|
|
edt_.session = NULL;
|
|
|
|
edt_.tvb = NULL;
|
|
|
|
edt_.tree = NULL;
|
|
|
|
|
|
|
|
memset(&edt_.pi, 0x0, sizeof(edt_.pi));
|
2015-02-11 23:00:27 +00:00
|
|
|
|
|
|
|
setWindowSubtitle(tr("Packet %1").arg(fdata->num));
|
|
|
|
|
2019-04-15 05:14:15 +00:00
|
|
|
if (!cf_read_record(cap_file_.capFile(), fdata, &rec_, &buf_)) {
|
2018-01-16 13:40:06 +00:00
|
|
|
reject();
|
|
|
|
return;
|
|
|
|
}
|
2016-06-29 23:12:12 +00:00
|
|
|
|
2019-04-11 22:08:23 +00:00
|
|
|
/* proto tree, visible. We need a proto tree if there are custom columns */
|
2015-02-11 23:00:27 +00:00
|
|
|
epan_dissect_init(&edt_, cap_file_.capFile()->epan, TRUE, TRUE);
|
|
|
|
col_custom_prime_edt(&edt_, &(cap_file_.capFile()->cinfo));
|
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
epan_dissect_run(&edt_, cap_file_.capFile()->cd_t, &rec_,
|
2019-04-11 22:08:23 +00:00
|
|
|
frame_tvbuff_new_buffer(&cap_file_.capFile()->provider, fdata, &buf_),
|
2015-02-11 23:00:27 +00:00
|
|
|
fdata, &(cap_file_.capFile()->cinfo));
|
|
|
|
epan_dissect_fill_in_columns(&edt_, TRUE, TRUE);
|
|
|
|
|
2018-04-26 11:13:54 +00:00
|
|
|
proto_tree_ = new ProtoTree(ui->packetSplitter, &edt_);
|
|
|
|
// Do not call proto_tree_->setCaptureFile, ProtoTree only needs the
|
|
|
|
// dissection context.
|
2017-12-07 16:15:30 +00:00
|
|
|
proto_tree_->setRootNode(edt_.tree);
|
2015-02-11 23:00:27 +00:00
|
|
|
|
2018-01-23 16:56:42 +00:00
|
|
|
byte_view_tab_ = new ByteViewTab(ui->packetSplitter, &edt_);
|
2015-02-11 23:00:27 +00:00
|
|
|
byte_view_tab_->setCaptureFile(cap_file_.capFile());
|
2019-11-21 09:50:41 +00:00
|
|
|
byte_view_tab_->selectedFrameChanged(QList<int>() << 0);
|
2015-02-11 23:00:27 +00:00
|
|
|
|
2014-12-13 00:51:40 +00:00
|
|
|
ui->packetSplitter->setStretchFactor(1, 0);
|
2015-02-11 23:00:27 +00:00
|
|
|
|
|
|
|
QStringList col_parts;
|
|
|
|
for (int i = 0; i < cap_file_.capFile()->cinfo.num_cols; ++i) {
|
2015-02-12 18:17:05 +00:00
|
|
|
// ElidedLabel doesn't support rich text / HTML
|
|
|
|
col_parts << QString("%1: %2")
|
|
|
|
.arg(get_column_title(i))
|
2015-06-27 03:00:33 +00:00
|
|
|
.arg(cap_file_.capFile()->cinfo.columns[i].col_data);
|
2015-02-11 23:00:27 +00:00
|
|
|
}
|
2015-02-12 18:17:05 +00:00
|
|
|
col_info_ = col_parts.join(" " UTF8_MIDDLE_DOT " ");
|
2017-10-25 13:39:35 +00:00
|
|
|
|
|
|
|
ui->hintLabel->setText(col_info_);
|
2015-02-11 23:00:27 +00:00
|
|
|
|
2017-10-30 12:58:28 +00:00
|
|
|
connect(wsApp, SIGNAL(zoomMonospaceFont(QFont)),
|
2015-02-11 23:00:27 +00:00
|
|
|
proto_tree_, SLOT(setMonospaceFont(QFont)));
|
2017-10-30 12:58:28 +00:00
|
|
|
|
|
|
|
connect(byte_view_tab_, SIGNAL(fieldSelected(FieldInformation *)),
|
|
|
|
proto_tree_, SLOT(selectedFieldChanged(FieldInformation *)));
|
|
|
|
connect(proto_tree_, SIGNAL(fieldSelected(FieldInformation *)),
|
|
|
|
byte_view_tab_, SLOT(selectedFieldChanged(FieldInformation *)));
|
|
|
|
|
|
|
|
connect(byte_view_tab_, SIGNAL(fieldHighlight(FieldInformation *)),
|
|
|
|
this, SLOT(setHintText(FieldInformation *)));
|
|
|
|
|
2019-07-28 19:24:24 +00:00
|
|
|
connect(proto_tree_, SIGNAL(showProtocolPreferences(QString)),
|
|
|
|
this, SIGNAL(showProtocolPreferences(QString)));
|
|
|
|
connect(proto_tree_, SIGNAL(editProtocolPreference(preference*,pref_module*)),
|
|
|
|
this, SIGNAL(editProtocolPreference(preference*,pref_module*)));
|
2015-02-11 23:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PacketDialog::~PacketDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
epan_dissect_cleanup(&edt_);
|
2019-04-11 22:08:23 +00:00
|
|
|
wtap_rec_cleanup(&rec_);
|
|
|
|
ws_buffer_free(&buf_);
|
2015-02-11 23:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PacketDialog::captureFileClosing()
|
|
|
|
{
|
2015-05-22 21:01:31 +00:00
|
|
|
QString closed_title = tr("[%1 closed] " UTF8_MIDDLE_DOT " %2")
|
|
|
|
.arg(cap_file_.fileName())
|
|
|
|
.arg(col_info_);
|
2017-10-25 13:39:35 +00:00
|
|
|
ui->hintLabel->setText(closed_title);
|
2015-02-11 23:00:27 +00:00
|
|
|
WiresharkDialog::captureFileClosing();
|
|
|
|
}
|
|
|
|
|
2017-10-30 12:58:28 +00:00
|
|
|
void PacketDialog::on_buttonBox_helpRequested()
|
2015-02-11 23:00:27 +00:00
|
|
|
{
|
2017-10-30 12:58:28 +00:00
|
|
|
wsApp->helpTopicAction(HELP_NEW_PACKET_DIALOG);
|
2015-02-11 23:00:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 12:58:28 +00:00
|
|
|
void PacketDialog::setHintText(FieldInformation * finfo)
|
2015-02-11 23:00:27 +00:00
|
|
|
{
|
2017-10-30 12:58:28 +00:00
|
|
|
QString hint;
|
|
|
|
|
2019-11-17 19:02:20 +00:00
|
|
|
if (finfo)
|
2017-10-30 12:58:28 +00:00
|
|
|
{
|
|
|
|
FieldInformation::Position pos = finfo->position();
|
|
|
|
QString field_str;
|
|
|
|
|
|
|
|
if (pos.length < 2) {
|
|
|
|
hint = QString(tr("Byte %1")).arg(pos.start);
|
|
|
|
} else {
|
|
|
|
hint = QString(tr("Bytes %1-%2")).arg(pos.start).arg(pos.start + pos.length - 1);
|
|
|
|
}
|
|
|
|
hint += QString(": %1 (%2)")
|
|
|
|
.arg(finfo->headerInfo().name)
|
|
|
|
.arg(finfo->headerInfo().abbreviation);
|
|
|
|
}
|
|
|
|
ui->hintLabel->setText(hint);
|
2015-02-11 23:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|