2 * Routines for raw data (default case)
3 * Gilbert Ramirez <gram@alumni.rice.edu>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/crypt/crypt-md5.h>
34 #include "packet-data.h"
36 /* proto_data cannot be static because it's referenced in the
41 static int hf_data_data = -1;
42 static int hf_data_text = -1;
43 static int hf_data_len = -1;
44 static int hf_data_md5_hash = -1;
46 static gboolean new_pane = FALSE;
47 static gboolean show_as_text = FALSE;
48 static gboolean generate_md5_hash = FALSE;
50 static gint ett_data = -1;
52 void proto_reg_handoff_data(void);
55 dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
60 bytes = tvb_length_remaining(tvb, 0);
64 proto_tree *data_tree;
66 guint8 *real_data = tvb_memdup(tvb, 0, bytes);
67 data_tvb = tvb_new_child_real_data(tvb,real_data,bytes,bytes);
68 tvb_set_free_cb(data_tvb, g_free);
69 add_new_data_source(pinfo, data_tvb, "Not dissected data bytes");
73 ti = proto_tree_add_protocol_format(tree, proto_data, tvb,
75 bytes, "Data (%d byte%s)", bytes,
76 plurality(bytes, "", "s"));
77 data_tree = proto_item_add_subtree(ti, ett_data);
79 proto_tree_add_item(data_tree, hf_data_data, data_tvb, 0, bytes, ENC_NA);
82 proto_tree_add_item(data_tree, hf_data_text, data_tvb, 0, bytes, ENC_ASCII|ENC_NA);
85 if(generate_md5_hash) {
88 md5_byte_t digest[16];
91 cp = tvb_get_ptr(tvb, 0, bytes);
94 md5_append(&md_ctx, cp, bytes);
95 md5_finish(&md_ctx, digest);
97 digest_string = bytestring_to_str(digest, 16, '\0');
98 ti = proto_tree_add_string(data_tree, hf_data_md5_hash, tvb, 0, 0, digest_string);
99 PROTO_ITEM_SET_GENERATED(ti);
102 ti = proto_tree_add_int(data_tree, hf_data_len, data_tvb, 0, 0, bytes);
103 PROTO_ITEM_SET_GENERATED (ti);
109 proto_register_data(void)
111 static hf_register_info hf[] = {
113 { "Data", "data.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
115 { "Text", "data.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
117 { "Payload MD5 hash", "data.md5_hash", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
119 { "Length", "data.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } }
122 static gint *ett[] = {
126 module_t *module_data;
128 proto_data = proto_register_protocol (
130 "Data", /* short name */
134 register_dissector("data", dissect_data, proto_data);
136 proto_register_field_array(proto_data, hf, array_length(hf));
137 proto_register_subtree_array(ett, array_length(ett));
139 module_data = prefs_register_protocol( proto_data, proto_reg_handoff_data);
140 prefs_register_bool_preference(module_data,
142 "Show not dissected data on new Packet Bytes pane",
143 "Show not dissected data on new Packet Bytes pane",
145 prefs_register_bool_preference(module_data,
148 "Show data as text in the Packet Details pane",
150 prefs_register_bool_preference(module_data,
153 "Whether or not MD5 hashes should be generated and shown for each payload.",
157 * "Data" is used to dissect something whose normal dissector
158 * is disabled, so it cannot itself be disabled.
160 proto_set_cant_toggle(proto_data);
164 proto_reg_handoff_data(void)