1998-09-16 02:39:15 +00:00
|
|
|
/* packet-data.c
|
|
|
|
* Routines for raw data (default case)
|
2001-11-13 23:55:44 +00:00
|
|
|
* Gilbert Ramirez <gram@alumni.rice.edu>
|
1998-09-16 02:39:15 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
1998-09-16 02:39:15 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2018-02-12 11:23:27 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
1998-09-16 02:39:15 +00:00
|
|
|
*/
|
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
#define NEW_PROTO_TREE_API
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2009-06-29 22:22:30 +00:00
|
|
|
#include <epan/prefs.h>
|
2013-12-21 17:23:17 +00:00
|
|
|
#include <epan/to_str.h>
|
2017-02-13 18:31:26 +00:00
|
|
|
#include <wsutil/wsgcrypt.h>
|
2015-11-04 08:45:54 +00:00
|
|
|
#include <wsutil/str_util.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2013-03-16 08:52:09 +00:00
|
|
|
void proto_register_data(void);
|
2018-05-24 19:02:26 +00:00
|
|
|
void proto_reg_handoff_data(void);
|
2013-03-16 08:52:09 +00:00
|
|
|
|
2018-06-05 00:21:26 +00:00
|
|
|
/* proto_data cannot be static because it's referenced in the
|
|
|
|
* print routines
|
|
|
|
*/
|
1999-07-07 22:52:57 +00:00
|
|
|
int proto_data = -1;
|
2009-01-16 11:51:19 +00:00
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
#define DATA_HFI_INIT HFI_INIT(proto_data)
|
|
|
|
|
|
|
|
static header_field_info hfi_data_data DATA_HFI_INIT =
|
|
|
|
{ "Data", "data.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
|
|
|
static header_field_info hfi_data_text DATA_HFI_INIT =
|
|
|
|
{ "Text", "data.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
2018-02-12 19:00:34 +00:00
|
|
|
static header_field_info hfi_data_uncompressed_data DATA_HFI_INIT =
|
|
|
|
{ "Uncompressed Data", "data.uncompressed.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
|
|
|
static header_field_info hfi_data_uncompressed_len DATA_HFI_INIT =
|
|
|
|
{ "Uncompressed Length", "data.uncompressed.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
static header_field_info hfi_data_len DATA_HFI_INIT =
|
|
|
|
{ "Length", "data.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL };
|
|
|
|
|
|
|
|
static header_field_info hfi_data_md5_hash DATA_HFI_INIT =
|
|
|
|
{ "Payload MD5 hash", "data.md5_hash", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
|
2010-05-19 07:21:55 +00:00
|
|
|
|
|
|
|
static gboolean new_pane = FALSE;
|
2018-02-12 19:00:34 +00:00
|
|
|
static gboolean uncompress_data = FALSE;
|
2010-05-19 07:21:55 +00:00
|
|
|
static gboolean show_as_text = FALSE;
|
2010-09-24 23:05:30 +00:00
|
|
|
static gboolean generate_md5_hash = FALSE;
|
2009-01-16 11:51:19 +00:00
|
|
|
|
|
|
|
static gint ett_data = -1;
|
1999-07-07 22:52:57 +00:00
|
|
|
|
2018-05-24 19:02:26 +00:00
|
|
|
static dissector_handle_t data_handle;
|
|
|
|
|
2015-11-23 03:59:08 +00:00
|
|
|
static int
|
2016-03-28 19:02:17 +00:00
|
|
|
dissect_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2000-05-11 22:04:18 +00:00
|
|
|
{
|
2009-01-16 11:51:19 +00:00
|
|
|
gint bytes;
|
2000-05-11 22:04:18 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2015-04-16 11:31:57 +00:00
|
|
|
bytes = tvb_captured_length(tvb);
|
2000-05-12 06:23:33 +00:00
|
|
|
if (bytes > 0) {
|
2012-05-07 13:13:49 +00:00
|
|
|
tvbuff_t *data_tvb;
|
2018-02-12 19:00:34 +00:00
|
|
|
tvbuff_t *uncompr_tvb = NULL;
|
2018-06-05 00:21:26 +00:00
|
|
|
gint uncompr_len = 0;
|
2009-06-29 22:22:30 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *data_tree;
|
2010-05-19 07:21:55 +00:00
|
|
|
if (new_pane) {
|
2016-04-21 17:12:26 +00:00
|
|
|
guint8 *real_data = (guint8 *)tvb_memdup(pinfo->pool, tvb, 0, bytes);
|
2009-06-29 22:22:30 +00:00
|
|
|
data_tvb = tvb_new_child_real_data(tvb,real_data,bytes,bytes);
|
|
|
|
add_new_data_source(pinfo, data_tvb, "Not dissected data bytes");
|
|
|
|
} else {
|
|
|
|
data_tvb = tvb;
|
|
|
|
}
|
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_data, tvb,
|
2001-11-26 05:41:15 +00:00
|
|
|
0,
|
2000-05-12 06:23:33 +00:00
|
|
|
bytes, "Data (%d byte%s)", bytes,
|
|
|
|
plurality(bytes, "", "s"));
|
2009-06-29 22:22:30 +00:00
|
|
|
data_tree = proto_item_add_subtree(ti, ett_data);
|
2007-09-28 19:16:05 +00:00
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
proto_tree_add_item(data_tree, &hfi_data_data, data_tvb, 0, bytes, ENC_NA);
|
2009-01-16 11:51:19 +00:00
|
|
|
|
2018-02-12 19:00:34 +00:00
|
|
|
if (uncompress_data) {
|
|
|
|
uncompr_tvb = tvb_child_uncompress(data_tvb, data_tvb, 0, tvb_reported_length(data_tvb));
|
|
|
|
|
|
|
|
if (uncompr_tvb) {
|
|
|
|
uncompr_len = tvb_reported_length(uncompr_tvb);
|
|
|
|
add_new_data_source(pinfo, uncompr_tvb, "Uncompressed Data");
|
|
|
|
proto_tree_add_item(data_tree, &hfi_data_uncompressed_data, uncompr_tvb, 0, uncompr_len, ENC_NA);
|
|
|
|
ti = proto_tree_add_int(data_tree, &hfi_data_uncompressed_len, uncompr_tvb, 0, 0, uncompr_len);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated (ti);
|
2018-02-12 19:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:21:55 +00:00
|
|
|
if (show_as_text) {
|
2018-02-12 19:00:34 +00:00
|
|
|
if (uncompr_tvb && uncompr_len > 0) {
|
|
|
|
proto_tree_add_item(data_tree, &hfi_data_text, uncompr_tvb, 0, uncompr_len, ENC_ASCII|ENC_NA);
|
|
|
|
} else {
|
|
|
|
proto_tree_add_item(data_tree, &hfi_data_text, data_tvb, 0, bytes, ENC_ASCII|ENC_NA);
|
|
|
|
}
|
2010-05-19 07:21:55 +00:00
|
|
|
}
|
|
|
|
|
2010-09-24 23:05:30 +00:00
|
|
|
if(generate_md5_hash) {
|
|
|
|
const guint8 *cp;
|
2018-06-05 00:21:26 +00:00
|
|
|
guint8 digest[HASH_MD5_LENGTH];
|
2012-12-26 05:57:06 +00:00
|
|
|
const gchar *digest_string;
|
2010-09-24 23:05:30 +00:00
|
|
|
|
|
|
|
cp = tvb_get_ptr(tvb, 0, bytes);
|
|
|
|
|
2017-02-13 18:31:26 +00:00
|
|
|
gcry_md_hash_buffer(GCRY_MD_MD5, digest, cp, bytes);
|
|
|
|
digest_string = bytestring_to_str(wmem_packet_scope(), digest, HASH_MD5_LENGTH, '\0');
|
2013-08-22 20:54:50 +00:00
|
|
|
ti = proto_tree_add_string(data_tree, &hfi_data_md5_hash, tvb, 0, 0, digest_string);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated(ti);
|
2010-09-24 23:05:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
ti = proto_tree_add_int(data_tree, &hfi_data_len, data_tvb, 0, 0, bytes);
|
2019-04-03 21:32:30 +00:00
|
|
|
proto_item_set_generated (ti);
|
2000-05-12 06:23:33 +00:00
|
|
|
}
|
2000-05-11 22:04:18 +00:00
|
|
|
}
|
2015-11-23 03:59:08 +00:00
|
|
|
return tvb_captured_length(tvb);
|
2000-05-11 22:04:18 +00:00
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
void
|
|
|
|
proto_register_data(void)
|
|
|
|
{
|
2013-11-07 20:14:18 +00:00
|
|
|
#ifndef HAVE_HFI_SECTION_INIT
|
2013-08-22 20:54:50 +00:00
|
|
|
static header_field_info *hfi[] = {
|
|
|
|
&hfi_data_data,
|
2018-02-12 19:00:34 +00:00
|
|
|
&hfi_data_uncompressed_data,
|
|
|
|
&hfi_data_uncompressed_len,
|
2013-08-22 20:54:50 +00:00
|
|
|
&hfi_data_text,
|
|
|
|
&hfi_data_md5_hash,
|
|
|
|
&hfi_data_len,
|
2007-09-28 19:16:05 +00:00
|
|
|
};
|
2013-11-07 20:14:18 +00:00
|
|
|
#endif
|
2007-09-28 19:16:05 +00:00
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_data
|
|
|
|
};
|
2012-05-07 13:13:49 +00:00
|
|
|
|
2009-06-29 22:22:30 +00:00
|
|
|
module_t *module_data;
|
2012-05-07 13:13:49 +00:00
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
proto_data = proto_register_protocol (
|
2001-01-03 06:56:03 +00:00
|
|
|
"Data", /* name */
|
|
|
|
"Data", /* short name */
|
|
|
|
"data" /* abbrev */
|
|
|
|
);
|
|
|
|
|
2018-05-24 19:02:26 +00:00
|
|
|
data_handle = register_dissector("data", dissect_data, proto_data);
|
2001-11-25 21:44:57 +00:00
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
proto_register_fields(proto_data, hfi, array_length(hfi));
|
2007-09-28 19:16:05 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2012-05-07 13:13:49 +00:00
|
|
|
|
|
|
|
module_data = prefs_register_protocol( proto_data, NULL);
|
2009-06-29 22:22:30 +00:00
|
|
|
prefs_register_bool_preference(module_data,
|
|
|
|
"datapref.newpane",
|
|
|
|
"Show not dissected data on new Packet Bytes pane",
|
|
|
|
"Show not dissected data on new Packet Bytes pane",
|
2010-05-19 07:21:55 +00:00
|
|
|
&new_pane);
|
2018-02-12 19:00:34 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
prefs_register_bool_preference(module_data,
|
|
|
|
"uncompress_data",
|
|
|
|
"Try to uncompress zlib compressed data",
|
|
|
|
"Try to uncompress zlib compressed data and show as uncompressed if successful",
|
|
|
|
&uncompress_data);
|
|
|
|
#endif
|
2010-05-19 07:21:55 +00:00
|
|
|
prefs_register_bool_preference(module_data,
|
|
|
|
"show_as_text",
|
|
|
|
"Show data as text",
|
|
|
|
"Show data as text in the Packet Details pane",
|
|
|
|
&show_as_text);
|
2010-09-24 23:05:30 +00:00
|
|
|
prefs_register_bool_preference(module_data,
|
|
|
|
"md5_hash",
|
|
|
|
"Generate MD5 hash",
|
|
|
|
"Whether or not MD5 hashes should be generated and shown for each payload.",
|
|
|
|
&generate_md5_hash);
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
/*
|
|
|
|
* "Data" is used to dissect something whose normal dissector
|
|
|
|
* is disabled, so it cannot itself be disabled.
|
|
|
|
*/
|
2004-01-03 18:40:08 +00:00
|
|
|
proto_set_cant_toggle(proto_data);
|
1999-07-07 22:52:57 +00:00
|
|
|
}
|
2014-10-05 19:57:05 +00:00
|
|
|
|
2018-05-24 19:02:26 +00:00
|
|
|
void
|
|
|
|
proto_reg_handoff_data(void)
|
|
|
|
{
|
|
|
|
dissector_add_string("media_type", "application/octet-stream", data_handle);
|
|
|
|
}
|
|
|
|
|
2014-10-05 19:57:05 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-10-05 19:57:05 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|