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 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <epan/packet.h>
14 #include <epan/prefs.h>
15 #include <epan/to_str.h>
16 #include <wsutil/wsgcrypt.h>
17 #include <wsutil/str_util.h>
19 #include "packet-tls.h"
20 #include "packet-dtls.h"
22 void proto_register_data(void);
23 void proto_reg_handoff_data(void);
26 static int proto_data
;
28 static int hf_data_data
;
29 static int hf_data_len
;
30 static int hf_data_md5_hash
;
31 static int hf_data_text
;
32 static int hf_data_uncompressed_data
;
33 static int hf_data_uncompressed_len
;
36 static bool uncompress_data
;
37 static bool show_as_text
;
38 static bool generate_md5_hash
;
42 static dissector_handle_t data_handle
;
45 dissect_data(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
51 bytes
= tvb_captured_length(tvb
);
54 tvbuff_t
*uncompr_tvb
= NULL
;
57 proto_tree
*data_tree
;
59 uint8_t *real_data
= (uint8_t *)tvb_memdup(pinfo
->pool
, tvb
, 0, bytes
);
60 data_tvb
= tvb_new_child_real_data(tvb
,real_data
,bytes
,bytes
);
61 add_new_data_source(pinfo
, data_tvb
, "Not dissected data bytes");
65 ti
= proto_tree_add_protocol_format(tree
, proto_data
, tvb
,
67 bytes
, "Data (%d byte%s)", bytes
,
68 plurality(bytes
, "", "s"));
69 data_tree
= proto_item_add_subtree(ti
, ett_data
);
71 proto_tree_add_item(data_tree
, hf_data_data
, data_tvb
, 0, bytes
, ENC_NA
);
73 if (uncompress_data
) {
74 uncompr_tvb
= tvb_child_uncompress_zlib(data_tvb
, data_tvb
, 0, tvb_reported_length(data_tvb
));
77 uncompr_len
= tvb_reported_length(uncompr_tvb
);
78 add_new_data_source(pinfo
, uncompr_tvb
, "Uncompressed Data");
79 proto_tree_add_item(data_tree
, hf_data_uncompressed_data
, uncompr_tvb
, 0, uncompr_len
, ENC_NA
);
80 ti
= proto_tree_add_int(data_tree
, hf_data_uncompressed_len
, uncompr_tvb
, 0, 0, uncompr_len
);
81 proto_item_set_generated (ti
);
88 if (uncompr_tvb
&& uncompr_len
> 0) {
89 text_tvb
= uncompr_tvb
;
90 text_length
= uncompr_len
;
95 proto_tree_add_item_ret_display_string(data_tree
, hf_data_text
, text_tvb
, 0, text_length
, ENC_UTF_8
, pinfo
->pool
, &display_str
);
96 col_add_str(pinfo
->cinfo
, COL_INFO
, display_str
);
99 if(generate_md5_hash
) {
101 uint8_t digest
[HASH_MD5_LENGTH
];
102 const char *digest_string
;
104 cp
= tvb_get_ptr(tvb
, 0, bytes
);
106 gcry_md_hash_buffer(GCRY_MD_MD5
, digest
, cp
, bytes
);
107 digest_string
= bytes_to_str_punct(pinfo
->pool
, digest
, HASH_MD5_LENGTH
, '\0');
108 ti
= proto_tree_add_string(data_tree
, hf_data_md5_hash
, tvb
, 0, 0, digest_string
);
109 proto_item_set_generated(ti
);
112 ti
= proto_tree_add_int(data_tree
, hf_data_len
, data_tvb
, 0, 0, bytes
);
113 proto_item_set_generated (ti
);
116 return tvb_captured_length(tvb
);
120 proto_register_data(void)
122 static hf_register_info hf
[] = {
124 { "Data", "data.data",
125 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
129 { "Text", "data.text",
130 FT_STRING
, BASE_NONE
, NULL
, 0x0,
133 { &hf_data_uncompressed_data
,
134 { "Uncompressed Data", "data.uncompressed.data",
135 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
138 { &hf_data_uncompressed_len
,
139 { "Uncompressed Length", "data.uncompressed.len",
140 FT_INT32
, BASE_DEC
, NULL
, 0x0,
144 { "Length", "data.len",
145 FT_INT32
, BASE_DEC
, NULL
, 0x0,
149 { "Payload MD5 hash", "data.md5_hash",
150 FT_STRING
, BASE_NONE
, NULL
, 0x0,
155 static int *ett
[] = {
159 module_t
*module_data
;
161 proto_data
= proto_register_protocol (
163 "Data", /* short name */
167 data_handle
= register_dissector("data", dissect_data
, proto_data
);
169 proto_register_field_array(proto_data
, hf
, array_length(hf
));
170 proto_register_subtree_array(ett
, array_length(ett
));
172 module_data
= prefs_register_protocol( proto_data
, NULL
);
173 prefs_register_bool_preference(module_data
,
175 "Show not dissected data on new Packet Bytes pane",
176 "Show not dissected data on new Packet Bytes pane",
178 #if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG)
179 prefs_register_bool_preference(module_data
,
181 "Try to uncompress zlib compressed data",
182 "Try to uncompress zlib compressed data and show as uncompressed if successful",
185 prefs_register_bool_preference(module_data
,
188 "Show data as text in the Packet Details pane",
190 prefs_register_bool_preference(module_data
,
193 "Whether or not MD5 hashes should be generated and shown for each payload.",
197 * "Data" is used to dissect something whose normal dissector
198 * is disabled, so it cannot itself be disabled.
200 proto_set_cant_toggle(proto_data
);
204 add_foreach_decode_as(const char *table_name
, const char *ui_name _U_
, void *user_data
)
206 dissector_handle_t handle
= (dissector_handle_t
) user_data
;
207 dissector_table_t dissector_table
= find_dissector_table(table_name
);
210 if (dissector_table_supports_decode_as(dissector_table
))
211 dissector_add_for_decode_as(table_name
, handle
);
215 proto_reg_handoff_data(void)
217 dissector_add_string("media_type", "application/octet-stream", data_handle
);
218 ssl_dissector_add(0, data_handle
);
219 dtls_dissector_add(0, data_handle
);
221 dissector_all_tables_foreach_table(add_foreach_decode_as
, (void *)data_handle
, NULL
);
225 * Editor modelines - https://www.wireshark.org/tools/modelines.html
230 * indent-tabs-mode: t
233 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
234 * :indentSize=8:tabSize=8:noTabs=false: