2 * Routines for raw data (default case)
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #define NEW_PROTO_TREE_API
30 #include <wsutil/md5.h>
32 #include <epan/packet.h>
33 #include <epan/prefs.h>
34 #include <epan/to_str.h>
35 #include "packet-data.h"
37 /* proto_data cannot be static because it's referenced in the
40 void proto_register_data(void);
44 #define DATA_HFI_INIT HFI_INIT(proto_data)
46 static header_field_info hfi_data_data DATA_HFI_INIT =
47 { "Data", "data.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL };
49 static header_field_info hfi_data_text DATA_HFI_INIT =
50 { "Text", "data.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
52 static header_field_info hfi_data_len DATA_HFI_INIT =
53 { "Length", "data.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL };
55 static header_field_info hfi_data_md5_hash DATA_HFI_INIT =
56 { "Payload MD5 hash", "data.md5_hash", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
58 static gboolean new_pane = FALSE;
59 static gboolean show_as_text = FALSE;
60 static gboolean generate_md5_hash = FALSE;
62 static gint ett_data = -1;
65 dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
70 bytes = tvb_length_remaining(tvb, 0);
74 proto_tree *data_tree;
76 guint8 *real_data = (guint8 *)tvb_memdup(NULL, tvb, 0, bytes);
77 data_tvb = tvb_new_child_real_data(tvb,real_data,bytes,bytes);
78 tvb_set_free_cb(data_tvb, g_free);
79 add_new_data_source(pinfo, data_tvb, "Not dissected data bytes");
83 ti = proto_tree_add_protocol_format(tree, proto_data, tvb,
85 bytes, "Data (%d byte%s)", bytes,
86 plurality(bytes, "", "s"));
87 data_tree = proto_item_add_subtree(ti, ett_data);
89 proto_tree_add_item(data_tree, &hfi_data_data, data_tvb, 0, bytes, ENC_NA);
92 proto_tree_add_item(data_tree, &hfi_data_text, data_tvb, 0, bytes, ENC_ASCII|ENC_NA);
95 if(generate_md5_hash) {
98 md5_byte_t digest[16];
99 const gchar *digest_string;
101 cp = tvb_get_ptr(tvb, 0, bytes);
104 md5_append(&md_ctx, cp, bytes);
105 md5_finish(&md_ctx, digest);
107 digest_string = bytestring_to_str(wmem_packet_scope(), digest, 16, '\0');
108 ti = proto_tree_add_string(data_tree, &hfi_data_md5_hash, tvb, 0, 0, digest_string);
109 PROTO_ITEM_SET_GENERATED(ti);
112 ti = proto_tree_add_int(data_tree, &hfi_data_len, data_tvb, 0, 0, bytes);
113 PROTO_ITEM_SET_GENERATED (ti);
119 proto_register_data(void)
121 #ifndef HAVE_HFI_SECTION_INIT
122 static header_field_info *hfi[] = {
130 static gint *ett[] = {
134 module_t *module_data;
136 proto_data = proto_register_protocol (
138 "Data", /* short name */
142 register_dissector("data", dissect_data, proto_data);
144 proto_register_fields(proto_data, hfi, array_length(hfi));
145 proto_register_subtree_array(ett, array_length(ett));
147 module_data = prefs_register_protocol( proto_data, NULL);
148 prefs_register_bool_preference(module_data,
150 "Show not dissected data on new Packet Bytes pane",
151 "Show not dissected data on new Packet Bytes pane",
153 prefs_register_bool_preference(module_data,
156 "Show data as text in the Packet Details pane",
158 prefs_register_bool_preference(module_data,
161 "Whether or not MD5 hashes should be generated and shown for each payload.",
165 * "Data" is used to dissect something whose normal dissector
166 * is disabled, so it cannot itself be disabled.
168 proto_set_cant_toggle(proto_data);