Protobuf: Provide an option to add plugin subdissectore for fields of all types

As of now a plugin subdissector can register itself for byte or string type only.
This change adds an option to allow a plugin to register a subdissector for any protbuf field.
this subdissector will be able to dissect a protobuf field on top of the existing dissector for that field.
This commit is contained in:
ranjetsih 2021-03-20 14:25:00 +05:30 committed by Wireshark GitLab Utility
parent f10ebb959d
commit 387ebc955f
1 changed files with 9 additions and 1 deletions

View File

@ -150,6 +150,7 @@ static gboolean dissect_bytes_as_string = FALSE;
static gboolean old_dissect_bytes_as_string = FALSE;
static gboolean show_details = FALSE;
static gboolean pbf_as_hf = FALSE; /* dissect protobuf fields as header fields of wireshark */
static gboolean subdissect_all_pbf_types = FALSE; /* Allow subdissector for all protobuf fields */
static gboolean preload_protos = FALSE;
enum add_default_value_policy_t {
@ -504,7 +505,7 @@ protobuf_dissect_field_value(proto_tree *value_tree, tvbuff_t *tvb, guint offset
proto_tree* field_parent_tree = proto_tree_get_parent_tree(field_tree);
proto_tree* pbf_tree = field_tree;
nstime_t timestamp = { 0 };
dissector_handle_t field_dissector = (field_full_name && (field_type == PROTOBUF_TYPE_BYTES || field_type == PROTOBUF_TYPE_STRING)) ?
dissector_handle_t field_dissector = (field_full_name && (subdissect_all_pbf_types || field_type == PROTOBUF_TYPE_BYTES || field_type == PROTOBUF_TYPE_STRING)) ?
dissector_get_string_handle(protobuf_field_subdissector_table, field_full_name) : NULL;
if (pbf_as_hf && field_full_name) {
@ -2053,6 +2054,13 @@ proto_register_protobuf(void)
register_dissector_table("protobuf_field", "Protobuf field subdissector table",
proto_protobuf, FT_STRING, BASE_NONE);
prefs_register_bool_preference(protobuf_module, "subdissect_all_pbf_types",
"Subdissector all Fields.",
"Subdissector can be register itself for Protobuf fields of all types if this option is turned on.",
&subdissect_all_pbf_types);
prefs_set_preference_effect_fields(protobuf_module, "subdissect_all_pbf_types");
expert_protobuf = expert_register_protocol(proto_protobuf);
expert_register_field_array(expert_protobuf, ei, array_length(ei));