Decode As: Enable disabling a default dissector

Make it possible to use Decode As to set the current dissector
for an entry in a dissector table to NULL even if there is a
default dissector registered for that entry. (none) means (none)

This is different than disabling the dissector entirely, because
a dissector might be registered as default for multiple entries/ports,
and a user might want only to disable it for one entry, not in general.
Or, a dissector might have multiple registered dissectors and a
heuristic dissector, and a user might want to disable one dissector
registered value while still having the heuristic dissector enabled.

This is different than setting the dissector for the entry to Data,
because it still allows heuristic dissectors to get a chance.

This is different than setting a "Try heuristic sub-dissectors first"
preference, because it only affects the single entry in the tables,
instead of trying heuristic sub-dissectors first for all entries in
the table (and it works for all tables, even those that lack such a
preference.)

Move the default dissector to the top of the combobox so it is
still easy to reset to the default.

Fix #12098
This commit is contained in:
John Thacker 2023-05-22 08:30:10 -04:00
parent cef49cd887
commit 5f51c4bb33
4 changed files with 47 additions and 36 deletions

View File

@ -44,6 +44,13 @@ with support for relative RPATHs).
Support for building an NSIS Windows installer using the MinGW-w64 toolchain
and https://www.msys2.org/[MSYS2]. Read README.msys2 in the distribution for more information.
When changing the dissector via the Decode As table for values that
have default dissectors registered, selecting "(none)" will select
no dissection (while still allowing heuristic dissectors to attempt to
dissect.) The previous behavior was to reset the dissector to the default.
To facilitate resetting the dissector, the default dissector is now sorted
at the top of the list of possible dissector options.
Many other improvements have been made.
See the “New and Updated Features” section below for more details.

View File

@ -151,30 +151,26 @@ gboolean decode_as_default_reset(const gchar *name, gconstpointer pattern)
gboolean decode_as_default_change(const gchar *name, gconstpointer pattern, gconstpointer handle, const gchar *list_name _U_)
{
const dissector_handle_t dissector = (const dissector_handle_t)handle;
if (dissector != NULL) {
switch (get_dissector_table_selector_type(name)) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
dissector_change_uint(name, GPOINTER_TO_UINT(pattern), dissector);
return TRUE;
case FT_NONE:
dissector_change_payload(name, dissector);
return TRUE;
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
case FT_STRINGZPAD:
case FT_STRINGZTRUNC:
dissector_change_string(name, (!pattern)?"":(const gchar *) pattern, dissector);
return TRUE;
default:
return FALSE;
};
switch (get_dissector_table_selector_type(name)) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
dissector_change_uint(name, GPOINTER_TO_UINT(pattern), dissector);
return TRUE;
case FT_NONE:
dissector_change_payload(name, dissector);
return TRUE;
case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
case FT_STRINGZPAD:
case FT_STRINGZTRUNC:
dissector_change_string(name, (!pattern)?"":(const gchar *) pattern, dissector);
return TRUE;
default:
return FALSE;
}
};
return TRUE;
}

View File

@ -271,7 +271,12 @@ QWidget* DecodeAsDelegate::createEditor(QWidget *parentWidget, const QStyleOptio
for (dissector_info_t* protocol : protocols)
{
cb_editor->addItem(protocol->proto_name, VariantPointer<dissector_info_t>::asQVariant(protocol));
// Make it easy to reset to the default dissector
if (protocol->proto_name == item->defaultDissector()) {
cb_editor->insertItem(0, protocol->proto_name, VariantPointer<dissector_info_t>::asQVariant(protocol));
} else {
cb_editor->addItem(protocol->proto_name, VariantPointer<dissector_info_t>::asQVariant(protocol));
}
}
//Make sure the combo box is at least as wide as the column

View File

@ -93,13 +93,14 @@ void DecodeAsItem::init(const char* table_name, gconstpointer selector)
if (default_handle != NULL) {
default_dissector_ = dissector_handle_get_description(default_handle);
// When adding a new record, we leave dissector_handle_ NULL,
// which means reset "current" to "default", and let "current" equal
// default, so the user can explicitly change it and easily reset
// the value.
// When adding a new record, we set the "current" values equal to
// the default, so the user can easily reset the value.
// The existing value read from the prefs file should already
// be added to the table from reading the prefs file.
// When reading existing values the current dissector should be
// set explicitly.
// set explicitly to the actual current value.
current_dissector_ = default_dissector_;
dissector_handle_ = default_handle;
}
}
@ -807,7 +808,7 @@ void DecodeAsModel::applyChanges()
continue;
}
if ((item->currentDissector() == DECODE_AS_NONE) || !item->dissectorHandle()) {
if ((item->currentDissector() == item->defaultDissector())) {
decode_as_entry->reset_value(decode_as_entry->table_name, selector_value);
sub_dissectors = find_dissector_table(decode_as_entry->table_name);
@ -828,12 +829,14 @@ void DecodeAsModel::applyChanges()
sub_dissectors = find_dissector_table(decode_as_entry->table_name);
/* For now, only numeric dissector tables can use preferences */
if (IS_FT_UINT(dissector_table_get_type(sub_dissectors))) {
module = prefs_find_module(proto_get_protocol_filter_name(dissector_handle_get_protocol_index(item->dissectorHandle())));
pref_value = prefs_find_preference(module, decode_as_entry->table_name);
if (pref_value != NULL) {
module->prefs_changed_flags |= prefs_get_effect_flags(pref_value);
prefs_add_decode_as_value(pref_value, item->selectorUint(), FALSE);
if (item->dissectorHandle() != NULL) {
if (IS_FT_UINT(dissector_table_get_type(sub_dissectors))) {
module = prefs_find_module(proto_get_protocol_filter_name(dissector_handle_get_protocol_index(item->dissectorHandle())));
pref_value = prefs_find_preference(module, decode_as_entry->table_name);
if (pref_value != NULL) {
module->prefs_changed_flags |= prefs_get_effect_flags(pref_value);
prefs_add_decode_as_value(pref_value, item->selectorUint(), FALSE);
}
}
}
break;