From a5456c6f803df40aa32f05a12504c60a4894b199 Mon Sep 17 00:00:00 2001 From: stig Date: Sat, 30 Jan 2010 17:44:45 +0000 Subject: Added an option to try decoding unknown primitives as BER encoded data. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31740 f5534014-38df-0310-8fa8-9805f1628bb7 --- epan/dissectors/packet-ber.c | 77 +++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 22 deletions(-) (limited to 'epan/dissectors/packet-ber.c') diff --git a/epan/dissectors/packet-ber.c b/epan/dissectors/packet-ber.c index d9838974f7..33fe3f3806 100644 --- a/epan/dissectors/packet-ber.c +++ b/epan/dissectors/packet-ber.c @@ -92,6 +92,7 @@ static gint hf_ber_unknown_OID = -1; static gint hf_ber_unknown_BOOLEAN = -1; static gint hf_ber_unknown_OCTETSTRING = -1; static gint hf_ber_unknown_BER_OCTETSTRING = -1; +static gint hf_ber_unknown_BER_primitive = -1; static gint hf_ber_unknown_GraphicString = -1; static gint hf_ber_unknown_NumericString = -1; static gint hf_ber_unknown_PrintableString = -1; @@ -119,6 +120,7 @@ static gint hf_ber_octet_aligned = -1; /* OCTET_STRING */ static gint hf_ber_arbitrary = -1; /* BIT_STRING */ static gint ett_ber_octet_string = -1; +static gint ett_ber_primitive = -1; static gint ett_ber_unknown = -1; static gint ett_ber_SEQUENCE = -1; static gint ett_ber_EXTERNAL = -1; @@ -126,6 +128,7 @@ static gint ett_ber_T_encoding = -1; static gboolean show_internal_ber_fields = FALSE; static gboolean decode_octetstring_as_ber = FALSE; +static gboolean decode_primitive_as_ber = FALSE; static gboolean decode_unexpected = FALSE; static gchar *decode_as_syntax = NULL; @@ -425,7 +428,7 @@ int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tre proto_tree *next_tree=NULL; guint8 c; guint32 i; - gboolean is_printable; + gboolean is_printable, is_decoded_as; proto_item *pi, *cause; asn1_ctx_t asn1_ctx; @@ -474,6 +477,7 @@ int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tre offset = dissect_ber_octet_string(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_GraphicString, NULL); break; case BER_UNI_TAG_OCTETSTRING: + is_decoded_as = FALSE; if (decode_octetstring_as_ber) { int ber_offset; guint32 ber_len; @@ -483,6 +487,7 @@ int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tre /* Decoded a constructed ASN.1 tag with a length indicating this * could be BER encoded data. Try dissecting as unknown BER. */ + is_decoded_as = TRUE; if (show_internal_ber_fields) { offset = dissect_ber_identifier(pinfo, tree, tvb, start_offset, NULL, NULL, NULL); offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL); @@ -490,10 +495,9 @@ int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tre item = proto_tree_add_item(tree, hf_ber_unknown_BER_OCTETSTRING, tvb, offset, len, FALSE); next_tree = proto_item_add_subtree(item, ett_ber_octet_string); offset = dissect_unknown_ber(pinfo, tvb, offset, next_tree); - } else { - offset = dissect_ber_octet_string(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_OCTETSTRING, NULL); } - } else { + } + if (!is_decoded_as) { offset = dissect_ber_octet_string(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_OCTETSTRING, NULL); } break; @@ -552,35 +556,55 @@ int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tre case BER_CLASS_CON: case BER_CLASS_PRI: default: - /* we can't dissect this directly as it is specific */ - /* we dissect again if show_internal_ber_fields is set */ if(show_internal_ber_fields) { offset=dissect_ber_identifier(pinfo, tree, tvb, start_offset, &class, &pc, &tag); offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL); } - pi = proto_tree_add_text(tree, tvb, offset, len, "[%s %d] ", val_to_str(class,ber_class_codes,"Unknown"), tag); - /* we may want to do better and show the bytes */ - is_printable = TRUE; - for(i=0;i 0) && (ber_len + (ber_offset - offset) == len)) { + /* Decoded a constructed ASN.1 tag with a length indicating this + * could be BER encoded data. Try dissecting as unknown BER. + */ + is_decoded_as = TRUE; + proto_item_append_text (pi, "[BER encoded]"); + next_tree = proto_item_add_subtree(pi, ett_ber_primitive); + offset = dissect_unknown_ber(pinfo, tvb, offset, next_tree); + } } - if(is_printable) { /* give a nicer representation if it looks like a string */ - proto_item_append_text(pi," ("); + if (!is_decoded_as && len) { + /* we may want to do better and show the bytes */ + is_printable = TRUE; for(i=0;i