diff options
-rw-r--r-- | epan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/dissectors/Makefile.common | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-bencode.c | 327 | ||||
-rw-r--r-- | epan/dissectors/packet-bittorrent.c | 300 | ||||
-rw-r--r-- | epan/dissectors/packet-bzr.c | 18 |
5 files changed, 344 insertions, 303 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 7c77914e6b..f710de7cfc 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -392,6 +392,7 @@ set(DISSECTOR_SRC dissectors/packet-batadv.c dissectors/packet-bctp.c dissectors/packet-beep.c + dissectors/packet-bencode.c dissectors/packet-ber.c dissectors/packet-bfcp.c dissectors/packet-bfd.c diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index 9d3b916b70..08586e4bcb 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -312,6 +312,7 @@ DISSECTOR_SRC = \ packet-batadv.c \ packet-bctp.c \ packet-beep.c \ + packet-bencode.c \ packet-ber.c \ packet-bfcp.c \ packet-bfd.c \ diff --git a/epan/dissectors/packet-bencode.c b/epan/dissectors/packet-bencode.c new file mode 100644 index 0000000000..f4f61c71dd --- /dev/null +++ b/epan/dissectors/packet-bencode.c @@ -0,0 +1,327 @@ +/* packet-bencode.c + * Routines for bencode dissection + * Copyright (C) 2004,2013 Jelmer Vernooij <jelmer@samba.org> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * Copied from packet-pop.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include <glib.h> +#include <epan/prefs.h> +#include <epan/conversation.h> +#include <epan/packet.h> +#include <epan/strutil.h> + +#include "packet-tcp.h" + +static int proto_bencode = -1; + +static gint hf_bencode_str_length = -1; +static gint hf_bencode_str = -1; +static gint hf_bencode_int = -1; +static gint hf_bencode_dict = -1; +static gint hf_bencode_dict_entry = -1; +static gint hf_bencode_list = -1; + +static gint ett_bencode_dict = -1; +static gint ett_bencode_dict_entry = -1; +static gint ett_bencode_list = -1; + +static int dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo _U_, + int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) +{ + guint8 ch; + int stringlen = 0, nextstringlen; + int used; + int izero = 0; + + if (length<2) { + proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String"); + return -1; + } + + used = 0; + + while (length>=1) { + ch = tvb_get_guint8(tvb, offset+used); + length--; + used++; + + if (ch==':' && used>1) { + if (stringlen>length || stringlen<0) { + proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String Length"); + return -1; + } + if (tree) { + proto_tree_add_uint(tree, hf_bencode_str_length, tvb, offset, used, stringlen); + proto_tree_add_item(tree, hf_bencode_str, tvb, offset+used, stringlen, ENC_ASCII|ENC_NA); + + if (treeadd==1) { + proto_item_append_text(ti, " Key: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); + } + if (treeadd==2) { + proto_item_append_text(ti, " Value: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); + } + } + return used+stringlen; + } + + if (!izero && ch>='0' && ch<='9') { + if (ch=='0' && used==1) { + izero = 1; + } + + nextstringlen = (stringlen * 10) + (ch - '0'); + if (nextstringlen>=stringlen) { + stringlen = nextstringlen; + continue; + } + } + + proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String"); + return -1; + } + + proto_tree_add_text(tree, tvb, offset, length, "Truncated Data"); + return -1; +} + +static int dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_, + int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) +{ + gint32 ival=0; + int neg = 0; + int izero = 0; + int used; + guint8 ch; + + if (length<3) { + proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer"); + return -1; + } + + length--; + used = 1; + + while (length>=1) { + ch = tvb_get_guint8(tvb, offset+used); + length--; + used++; + + switch (ch) { + case 'e': + if (tree) { + if (neg) ival = -ival; + proto_tree_add_int(tree, hf_bencode_int, tvb, offset, used, ival); + if (treeadd==2) { + proto_item_append_text(ti, " Value: %d", ival); + } + } + return used; + + case '-': + if (used==2) { + neg = 1; + break; + } + /* Fall through */ + + default: + if (!(ch=='0' && used==3 && neg)) { /* -0 is invalid */ + if (ch=='0' && used==2) { /* as is 0[0-9]+ */ + izero = 1; + break; + } + if (!izero && ch>='0' && ch<='9') { + ival = (ival * 10) + (ch - '0'); + break; + } + } + + proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer"); + return -1; + } + } + + proto_tree_add_text(tree, tvb, offset, length, "Truncated Data"); + return -1; +} + +static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, + int offset, int length, proto_tree *tree, int level, proto_item *treei, int treeadd) +{ + guint8 op; + int oplen = 0, op1len, op2len; + int used; + + proto_item *ti = NULL, *td = NULL; + proto_tree *itree = NULL, *dtree = NULL; + + if (level>10) { + proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Nested Too Deep"); + return -1; + } + if (length<1) { + proto_tree_add_text(tree, tvb, offset, -1, "Truncated Data"); + return length; + } + + op = tvb_get_guint8(tvb, offset); + if (tree) { + oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level, NULL, 0); + if (oplen<0) oplen = length; + } + + switch (op) { + case 'd': + if (tree) { + td = proto_tree_add_item(tree, hf_bencode_dict, tvb, offset, oplen, ENC_NA); + dtree = proto_item_add_subtree(td, ett_bencode_dict); + } + + used = 1; + length--; + + while (length>=1) { + op = tvb_get_guint8(tvb, offset+used); + + if (op=='e') { + return used+1; + } + + op1len = dissect_bencoding_str(tvb, pinfo, offset+used, length, NULL, NULL, 0); + if (op1len<0) { + if (dtree) { + proto_tree_add_text(dtree, tvb, offset+used, -1, "Decode Aborted: Invalid Dictionary Key"); + } + return op1len; + } + + op2len = -1; + if (length-op1len>2) + op2len = dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, NULL, level+1, NULL, 0); + if (op2len<0) { + if (dtree) { + proto_tree_add_text(dtree, tvb, offset+used+op1len, -1, "Decode Aborted: Invalid Dictionary Value"); + } + return op2len; + } + + if (dtree) { + ti = proto_tree_add_item(dtree, hf_bencode_dict_entry, tvb, offset+used, op1len+op2len, ENC_NA); + itree = proto_item_add_subtree(ti, ett_bencode_dict_entry); + + dissect_bencoding_str(tvb, pinfo, offset+used, length, itree, ti, 1); + dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, itree, level+1, ti, 2); + } + + used += op1len+op2len; + length -= op1len+op2len; + } + if (dtree) { + proto_tree_add_text(dtree, tvb, offset+used, -1, "Truncated Data"); + } + return -1; + + case 'l': + if (tree) { + ti = proto_tree_add_item(tree, hf_bencode_list, tvb, offset, oplen, ENC_NA); + itree = proto_item_add_subtree(ti, ett_bencode_list); + } + + used = 1; + length--; + + while (length>=1) { + op = tvb_get_guint8(tvb, offset+used); + + if (op=='e') { + return used+1; + } + + oplen = dissect_bencoding_rec(tvb, pinfo, offset+used, length, itree, level+1, ti, 0); + if (oplen<1) return oplen; + + used += oplen; + length -= oplen; + } + if (itree) { + proto_tree_add_text(itree, tvb, offset+used, -1, "Truncated Data"); + } + return -1; + + case 'i': + return dissect_bencoding_int(tvb, pinfo, offset, length, tree, treei, treeadd); + + default: + if (op>='1' && op<='9') { + return dissect_bencoding_str(tvb, pinfo, offset, length, tree, treei, treeadd); + } + + proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Invalid Bencoding"); + } + + return -1; +} + +static void dissect_bencoding(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + dissect_bencoding_rec(tvb, pinfo, 0, tvb_length(tvb), tree, 0, NULL, 0); +} + +void +proto_register_bencode(void) +{ + static hf_register_info hf[] = { + { &hf_bencode_str_length, + { "String Length", "bencode.str.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, + { &hf_bencode_str, + { "String", "bencode.str", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_bencode_int, + { "Integer", "bencode.int", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, + { &hf_bencode_dict, + { "Dictionary", "bencode.dict", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_bencode_dict_entry, + { "Entry", "bencode.dict.entry", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_bencode_list, + { "List", "bencode.list", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + }; + + static gint *ett[] = { + &ett_bencode_dict, + &ett_bencode_dict_entry, + &ett_bencode_list, + }; + + proto_bencode = proto_register_protocol("Bencode", "Bencode", "bencode"); + register_dissector("bencode", dissect_bencoding, proto_bencode); + proto_register_field_array(proto_bencode, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); +} diff --git a/epan/dissectors/packet-bittorrent.c b/epan/dissectors/packet-bittorrent.c index f1999d2c81..251bc2f6df 100644 --- a/epan/dissectors/packet-bittorrent.c +++ b/epan/dissectors/packet-bittorrent.c @@ -130,6 +130,7 @@ static const struct amp_message amp_messages[] = { }; static dissector_handle_t dissector_handle; +static dissector_handle_t bencode_handle; static int proto_bittorrent = -1; /* static gint hf_bittorrent_field_length = -1; */ @@ -150,12 +151,6 @@ static gint hf_bittorrent_piece_index = -1; static gint hf_bittorrent_piece_begin = -1; static gint hf_bittorrent_piece_length = -1; static gint hf_bittorrent_piece_data = -1; -static gint hf_bittorrent_bstr_length = -1; -static gint hf_bittorrent_bstr = -1; -static gint hf_bittorrent_bint = -1; -static gint hf_bittorrent_bdict = -1; -static gint hf_bittorrent_bdict_entry = -1; -static gint hf_bittorrent_blist = -1; static gint hf_azureus_jpc_addrlen = -1; static gint hf_azureus_jpc_addr = -1; static gint hf_azureus_jpc_port = -1; @@ -166,9 +161,6 @@ static gint hf_bittorrent_extended = -1; static gint ett_bittorrent = -1; static gint ett_bittorrent_msg = -1; static gint ett_peer_id = -1; -static gint ett_bittorrent_bdict = -1; -static gint ett_bittorrent_bdict_entry = -1; -static gint ett_bittorrent_blist = -1; static gboolean bittorrent_desegment = TRUE; static gboolean decode_client_information = FALSE; @@ -314,269 +306,6 @@ get_bittorrent_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) } } -static int -dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo _U_, - int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) -{ - guint8 ch; - int stringlen = 0, nextstringlen; - int used; - int izero = 0; - - if (length<2) { - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String"); - } - return -1; - } - - used = 0; - - while (length>=1) { - ch = tvb_get_guint8(tvb, offset+used); - length--; - used++; - - if (ch==':' && used>1) { - if (stringlen>length || stringlen<0) { - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String Length"); - } - return -1; - } - if (tree) { - proto_tree_add_uint(tree, hf_bittorrent_bstr_length, tvb, offset, used, stringlen); - proto_tree_add_item(tree, hf_bittorrent_bstr, tvb, offset+used, stringlen, ENC_ASCII|ENC_NA); - - if (treeadd==1) { - proto_item_append_text(ti, " Key: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); - } - if (treeadd==2) { - proto_item_append_text(ti, " Value: %s", format_text((guchar *)tvb_memdup(wmem_packet_scope(), tvb, offset+used, stringlen), stringlen)); - } - } - return used+stringlen; - } - - if (!izero && ch>='0' && ch<='9') { - if (ch=='0' && used==1) { - izero = 1; - } - - nextstringlen = (stringlen * 10) + (ch - '0'); - if (nextstringlen>=stringlen) { - stringlen = nextstringlen; - continue; - } - } - - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String"); - } - return -1; - } - - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Truncated Data"); - } - return -1; -} - -static int -dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_, - int offset, int length, proto_tree *tree, proto_item *ti, int treeadd) -{ - gint32 ival=0; - int neg = 0; - int izero = 0; - int used; - guint8 ch; - - if (length<3) { - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer"); - } - return -1; - } - - length--; - used = 1; - - while (length>=1) { - ch = tvb_get_guint8(tvb, offset+used); - length--; - used++; - - switch (ch) { - case 'e': - if (tree) { - if (neg) ival = -ival; - proto_tree_add_int(tree, hf_bittorrent_bint, tvb, offset, used, ival); - if (treeadd==2) { - proto_item_append_text(ti, " Value: %d", ival); - } - } - return used; - - case '-': - if (used==2) { - neg = 1; - break; - } - /* Fall through */ - - default: - if (!(ch=='0' && used==3 && neg)) { /* -0 is invalid */ - if (ch=='0' && used==2) { /* as is 0[0-9]+ */ - izero = 1; - break; - } - if (!izero && ch>='0' && ch<='9') { - ival = (ival * 10) + (ch - '0'); - break; - } - } - - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer"); - } - return -1; - } - } - - if (tree) { - proto_tree_add_text(tree, tvb, offset, length, "Truncated Data"); - } - return -1; -} - -static int -dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_, - int offset, int length, proto_tree *tree, int level, proto_item *treei, int treeadd) -{ - guint8 op; - int oplen = 0, op1len, op2len; - int used; - - proto_item *ti = NULL, *td = NULL; - proto_tree *itree = NULL, *dtree = NULL; - - if (level>10) { - proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Nested Too Deep"); - return -1; - } - if (length<1) { - proto_tree_add_text(tree, tvb, offset, -1, "Truncated Data"); - return length; - } - - op = tvb_get_guint8(tvb, offset); - if (tree) { - oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level, NULL, 0); - if (oplen<0) oplen = length; - } - - switch (op) { - case 'd': - if (tree) { - td = proto_tree_add_item(tree, hf_bittorrent_bdict, tvb, offset, oplen, ENC_NA); - dtree = proto_item_add_subtree(td, ett_bittorrent_bdict); - } - - used = 1; - length--; - - while (length>=1) { - op = tvb_get_guint8(tvb, offset+used); - - if (op=='e') { - return used+1; - } - - op1len = dissect_bencoding_str(tvb, pinfo, offset+used, length, NULL, NULL, 0); - if (op1len<0) { - if (dtree) { - proto_tree_add_text(dtree, tvb, offset+used, -1, "Decode Aborted: Invalid Dictionary Key"); - } - return op1len; - } - - op2len = -1; - if (length-op1len>2) - op2len = dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, NULL, level+1, NULL, 0); - if (op2len<0) { - if (dtree) { - proto_tree_add_text(dtree, tvb, offset+used+op1len, -1, "Decode Aborted: Invalid Dictionary Value"); - } - return op2len; - } - - if (dtree) { - ti = proto_tree_add_item(dtree, hf_bittorrent_bdict_entry, tvb, offset+used, op1len+op2len, ENC_NA); - itree = proto_item_add_subtree(ti, ett_bittorrent_bdict_entry); - - dissect_bencoding_str(tvb, pinfo, offset+used, length, itree, ti, 1); - dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, itree, level+1, ti, 2); - } - - used += op1len+op2len; - length -= op1len+op2len; - } - if (dtree) { - proto_tree_add_text(dtree, tvb, offset+used, -1, "Truncated Data"); - } - return -1; - - case 'l': - if (tree) { - ti = proto_tree_add_item(tree, hf_bittorrent_blist, tvb, offset, oplen, ENC_NA); - itree = proto_item_add_subtree(ti, ett_bittorrent_blist); - } - - used = 1; - length--; - - while (length>=1) { - op = tvb_get_guint8(tvb, offset+used); - - if (op=='e') { - return used+1; - } - - oplen = dissect_bencoding_rec(tvb, pinfo, offset+used, length, itree, level+1, ti, 0); - if (oplen<1) return oplen; - - used += oplen; - length -= oplen; - } - if (itree) { - proto_tree_add_text(itree, tvb, offset+used, -1, "Truncated Data"); - } - return -1; - - case 'i': - return dissect_bencoding_int(tvb, pinfo, offset, length, tree, treei, treeadd); - - default: - if (op>='1' && op<='9') { - return dissect_bencoding_str(tvb, pinfo, offset, length, tree, treei, treeadd); - } - - if (tree) { - proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Invalid Bencoding"); - } - } - - return -1; -} - -static void -dissect_bencoding(tvbuff_t *tvb, packet_info *pinfo _U_, - int offset, int length, proto_tree *tree) -{ - dissect_bencoding_rec(tvb, pinfo, offset, length, tree, 0, NULL, 0); -} - static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -592,6 +321,7 @@ dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_item *ti; guint32 piece_index, piece_begin, piece_length; guint32 stringlen; + tvbuff_t *subtvb; if (tvb_bytes_exist(tvb, offset + BITTORRENT_HEADER_LENGTH, 1)) { /* Check for data from the middle of a message. */ @@ -742,7 +472,8 @@ dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) case AZUREUS_MESSAGE_HANDSHAKE: case AZUREUS_MESSAGE_PEER_EXCHANGE: - dissect_bencoding(tvb, pinfo, offset, length, mtree); + subtvb = tvb_new_subset(tvb, offset, length, length); + call_dissector(bencode_handle, subtvb, pinfo, mtree); break; case AZUREUS_MESSAGE_JPC_HELLO: @@ -909,24 +640,6 @@ proto_register_bittorrent(void) { &hf_bittorrent_piece_length, { "Piece Length", "bittorrent.piece.length", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } }, - { &hf_bittorrent_bstr_length, - { "String Length", "bittorrent.bstr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, - { &hf_bittorrent_bstr, - { "String", "bittorrent.bstr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_bittorrent_bint, - { "Integer", "bittorrent.bint", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, - { &hf_bittorrent_bdict, - { "Dictionary", "bittorrent.bdict", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_bittorrent_bdict_entry, - { "Entry", "bittorrent.bdict.entry", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_bittorrent_blist, - { "List", "bittorrent.blist", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, { &hf_azureus_jpc_addrlen, { "Cache Address Length", "bittorrent.jpc.addr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } }, @@ -951,9 +664,6 @@ proto_register_bittorrent(void) &ett_bittorrent, &ett_bittorrent_msg, &ett_peer_id, - &ett_bittorrent_bdict, - &ett_bittorrent_bdict_entry, - &ett_bittorrent_blist }; module_t *bittorrent_module; @@ -980,6 +690,8 @@ proto_register_bittorrent(void) void proto_reg_handoff_bittorrent(void) { + bencode_handle = find_dissector("bencode"); + dissector_handle = find_dissector("bittorrent.tcp"); #if 0 dissector_add_uint("tcp.port", 6881, dissector_handle); diff --git a/epan/dissectors/packet-bzr.c b/epan/dissectors/packet-bzr.c index 1b89a086b2..709ca04c70 100644 --- a/epan/dissectors/packet-bzr.c +++ b/epan/dissectors/packet-bzr.c @@ -1,6 +1,6 @@ /* packet-bzr.c * Routines for Bazaar packet dissection - * Copyright 2011, Jelmer Vernooij <jelmer@samba.org> + * Copyright 2011,2013 Jelmer Vernooij <jelmer@samba.org> * * http://doc.bazaar.canonical.com/developers/network-protocol.html * @@ -45,7 +45,6 @@ static gint ett_prefixed_bytes = -1; static gint hf_bzr_prefixed_bencode = -1; static gint hf_bzr_prefixed_bencode_len = -1; -static gint hf_bzr_prefixed_bencode_data = -1; static gint hf_bzr_bytes = -1; static gint hf_bzr_bytes_data = -1; static gint hf_bzr_bytes_length = -1; @@ -53,6 +52,8 @@ static gint hf_bzr_result = -1; static gint hf_bzr_packet_protocol_version = -1; static gint hf_bzr_packet_kind = -1; +static dissector_handle_t bencode_handle; + #define REQUEST_VERSION_TWO "bzr request 2\n" #define RESPONSE_VERSION_TWO "bzr response 2\n" #define MESSAGE_VERSION_THREE "bzr message 3 (bzr 1.6)\n" @@ -123,7 +124,7 @@ get_bzr_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) } static gint -dissect_prefixed_bencode(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, +dissect_prefixed_bencode(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *tree) { guint32 plen; @@ -138,11 +139,12 @@ dissect_prefixed_bencode(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, if (prefixed_bencode_tree) { + tvbuff_t *subtvb; proto_tree_add_item(prefixed_bencode_tree, hf_bzr_prefixed_bencode_len, tvb, offset, 4, ENC_BIG_ENDIAN); - proto_tree_add_item(prefixed_bencode_tree, hf_bzr_prefixed_bencode_data, - tvb, offset+4, plen, ENC_NA); + subtvb = tvb_new_subset(tvb, offset+4, plen, plen); + call_dissector(bencode_handle, subtvb, pinfo, prefixed_bencode_tree); } return 4 + plen; @@ -277,10 +279,6 @@ proto_register_bzr(void) { "Bencode packet length", "bzr.bencode.length", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }, }, - { &hf_bzr_prefixed_bencode_data, - { "Bencode packet data", "bzr.bencode.data", FT_BYTES, BASE_NONE, - NULL, 0x0, NULL, HFILL }, - }, { &hf_bzr_bytes, { "Prefixed bytes", "bzr.bytes", FT_BYTES, BASE_NONE, NULL, 0x0, "Bytes field with prefixed 32-bit length", HFILL }, @@ -328,6 +326,8 @@ proto_reg_handoff_bzr(void) { dissector_handle_t bzr_handle; + bencode_handle = find_dissector("bencode"); + bzr_handle = find_dissector("bzr"); dissector_add_uint("tcp.port", TCP_PORT_BZR, bzr_handle); } |