Verify find/replace mask works for all field types

This commit is contained in:
Srivats P 2021-12-09 08:26:35 +05:30
parent 4c6d8f35d6
commit dc7ac89c30
5 changed files with 38 additions and 5 deletions

View File

@ -35,18 +35,26 @@ void FieldEdit::setType(FieldType type)
switch (type_) {
case kUInt64:
setValidator(&uint64Validator_);
if (isMask_)
setText("0xFFFFFFFFFFFFFFFF");
break;
case kMacAddress:
setValidator(&macValidator_);
setPlaceholderText("00:00:00:00:00:00");
if (isMask_)
setText("FF:FF:FF:FF:FF:FF");
break;
case kIp4Address:
setValidator(&ip4Validator_);
setPlaceholderText("0.0.0.0");
if (isMask_)
setText("255.255.255.255");
break;
case kIp6Address:
setValidator(&ip6Validator_);
setPlaceholderText("::");
if (isMask_)
setText("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
break;
default:
setValidator(nullptr);
@ -58,8 +66,16 @@ void FieldEdit::setType(FieldType type)
void FieldEdit::setRange(quint64 min, quint64 max)
{
uint64Validator_.setRange(min, max);
if (type_ == kUInt64)
if (type_ == kUInt64) {
setPlaceholderText(QString("%1 - %2").arg(min).arg(max));
if (isMask_)
setText(QString::number(max, 16).toUpper().prepend("0x"));
}
}
void FieldEdit::setMask(bool isMask)
{
isMask_ = isMask;
}
QString FieldEdit::text() const

View File

@ -42,10 +42,13 @@ public:
void setType(FieldType type);
void setRange(quint64 min, quint64 max);
void setMask(bool isMask); // FIXME: rename
QString text() const;
private:
FieldType type_{kUInt64};
bool isMask_{false};
IPv4AddressValidator ip4Validator_;
IPv6AddressValidator ip6Validator_;

View File

@ -34,6 +34,9 @@ FindReplaceDialog::FindReplaceDialog(Action *action, QWidget *parent)
{
setupUi(this);
findMask->setMask(true);
replaceMask->setMask(true);
// Keep things simple and don't use mask(s) (default)
useFindMask->setChecked(false);
useReplaceMask->setChecked(false);
@ -97,28 +100,38 @@ void FindReplaceDialog::on_field_currentIndexChanged(int index)
// Use heuristics to determine field type
if (fieldAttrib.bitSize == 48) {
findMask->setType(FieldEdit::kMacAddress);
findValue->setType(FieldEdit::kMacAddress);
replaceMask->setType(FieldEdit::kMacAddress);
replaceValue->setType(FieldEdit::kMacAddress);
} else if ((fieldAttrib.bitSize == 32)
&& (fieldName.contains(QRegularExpression(
"address|source|destination",
QRegularExpression::CaseInsensitiveOption)))) {
findMask->setType(FieldEdit::kIp4Address);
findValue->setType(FieldEdit::kIp4Address);
replaceMask->setType(FieldEdit::kIp4Address);
replaceValue->setType(FieldEdit::kIp4Address);
} else if ((fieldAttrib.bitSize == 128)
&& (fieldName.contains(QRegularExpression(
"address|source|destination",
QRegularExpression::CaseInsensitiveOption)))) {
findMask->setType(FieldEdit::kIp6Address);
findValue->setType(FieldEdit::kIp6Address);
replaceMask->setType(FieldEdit::kIp6Address);
replaceValue->setType(FieldEdit::kIp6Address);
} else {
qDebug("XXXXXX %s bitSize %d max %llx",
qPrintable(field->currentText()),
fieldAttrib.bitSize, fieldAttrib.max);
findMask->setType(FieldEdit::kUInt64);
findMask->setRange(0, fieldAttrib.max);
findValue->setType(FieldEdit::kUInt64);
findValue->setRange(0, fieldAttrib.max);
replaceMask->setType(FieldEdit::kUInt64);
replaceMask->setRange(0, fieldAttrib.max);
replaceValue->setType(FieldEdit::kUInt64);
replaceValue->setRange(0, fieldAttrib.max);
}
@ -164,7 +177,7 @@ void FindReplaceDialog::on_buttonBox_accepted()
} else {
action_->findMask.setValue(QString::number(
useFindMask->isChecked() ?
findMask->text().toULongLong(nullptr, BASE_HEX) :
findMask->text().toULongLong(nullptr, 0) :
quint64(~0)));
action_->findValue.setValue(QString::number(
findValue->text().toULongLong(nullptr, 0)));
@ -172,7 +185,7 @@ void FindReplaceDialog::on_buttonBox_accepted()
action_->replaceMask.setValue(QString::number(
useReplaceMask->isChecked() ?
replaceMask->text().toULongLong(nullptr, BASE_HEX) :
replaceMask->text().toULongLong(nullptr, 0) :
quint64(~0)));
action_->replaceValue.setValue(QString::number(
replaceValue->text().toULongLong(nullptr, 0)));

View File

@ -35,7 +35,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="findMask"/>
<widget class="FieldEdit" name="findMask"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="matchAny">
@ -120,7 +120,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="replaceMask"/>
<widget class="FieldEdit" name="replaceMask"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label">

View File

@ -620,6 +620,7 @@ int StreamBase::findReplace(quint32 protocolNumber, int fieldIndex,
T fieldValue = proto->fieldData(fieldIndex,
AbstractProtocol::FieldValue).value<T>();
qDebug() << "findReplace:"
<< "stream" << mStreamId->id()
<< "field" << fieldValue
<< "findMask" << hex << findMask.value<T>() << dec
<< "findValue" << findValue.value<T>();