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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #define NEW_PROTO_TREE_API
32 #include <wsutil/md5.h>
34 #include <epan/packet.h>
35 #include <epan/prefs.h>
36 #include "packet-data.h"
38 /* proto_data cannot be static because it's referenced in the
41 void proto_register_data(void);
45 #define DATA_HFI_INIT HFI_INIT(proto_data)
47 static header_field_info hfi_data_data DATA_HFI_INIT
=
48 { "Data", "data.data", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
};
50 static header_field_info hfi_data_text DATA_HFI_INIT
=
51 { "Text", "data.text", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
};
53 static header_field_info hfi_data_len DATA_HFI_INIT
=
54 { "Length", "data.len", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
};
56 static header_field_info hfi_data_md5_hash DATA_HFI_INIT
=
57 { "Payload MD5 hash", "data.md5_hash", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
};
59 static gboolean new_pane
= FALSE
;
60 static gboolean show_as_text
= FALSE
;
61 static gboolean generate_md5_hash
= FALSE
;
63 static gint ett_data
= -1;
66 dissect_data(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
)
71 bytes
= tvb_length_remaining(tvb
, 0);
75 proto_tree
*data_tree
;
77 guint8
*real_data
= (guint8
*)tvb_memdup(NULL
, tvb
, 0, bytes
);
78 data_tvb
= tvb_new_child_real_data(tvb
,real_data
,bytes
,bytes
);
79 tvb_set_free_cb(data_tvb
, g_free
);
80 add_new_data_source(pinfo
, data_tvb
, "Not dissected data bytes");
84 ti
= proto_tree_add_protocol_format(tree
, proto_data
, tvb
,
86 bytes
, "Data (%d byte%s)", bytes
,
87 plurality(bytes
, "", "s"));
88 data_tree
= proto_item_add_subtree(ti
, ett_data
);
90 proto_tree_add_item(data_tree
, &hfi_data_data
, data_tvb
, 0, bytes
, ENC_NA
);
93 proto_tree_add_item(data_tree
, &hfi_data_text
, data_tvb
, 0, bytes
, ENC_ASCII
|ENC_NA
);
96 if(generate_md5_hash
) {
99 md5_byte_t digest
[16];
100 const gchar
*digest_string
;
102 cp
= tvb_get_ptr(tvb
, 0, bytes
);
105 md5_append(&md_ctx
, cp
, bytes
);
106 md5_finish(&md_ctx
, digest
);
108 digest_string
= bytestring_to_str(digest
, 16, '\0');
109 ti
= proto_tree_add_string(data_tree
, &hfi_data_md5_hash
, tvb
, 0, 0, digest_string
);
110 PROTO_ITEM_SET_GENERATED(ti
);
113 ti
= proto_tree_add_int(data_tree
, &hfi_data_len
, data_tvb
, 0, 0, bytes
);
114 PROTO_ITEM_SET_GENERATED (ti
);
120 proto_register_data(void)
122 #ifndef HAVE_HFI_SECTION_INIT
123 static header_field_info
*hfi
[] = {
131 static gint
*ett
[] = {
135 module_t
*module_data
;
137 proto_data
= proto_register_protocol (
139 "Data", /* short name */
143 register_dissector("data", dissect_data
, proto_data
);
145 proto_register_fields(proto_data
, hfi
, array_length(hfi
));
146 proto_register_subtree_array(ett
, array_length(ett
));
148 module_data
= prefs_register_protocol( proto_data
, NULL
);
149 prefs_register_bool_preference(module_data
,
151 "Show not dissected data on new Packet Bytes pane",
152 "Show not dissected data on new Packet Bytes pane",
154 prefs_register_bool_preference(module_data
,
157 "Show data as text in the Packet Details pane",
159 prefs_register_bool_preference(module_data
,
162 "Whether or not MD5 hashes should be generated and shown for each payload.",
166 * "Data" is used to dissect something whose normal dissector
167 * is disabled, so it cannot itself be disabled.
169 proto_set_cant_toggle(proto_data
);