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
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1998-09-16 03:22:19 +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
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
1998-09-16 02:39:15 +00:00
|
|
|
*/
|
|
|
|
|
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>
|
2012-01-15 12:29:44 +00:00
|
|
|
#include <epan/crypt/md5.h>
|
2002-05-10 23:20:38 +00:00
|
|
|
#include "packet-data.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-07-29 05:47:07 +00:00
|
|
|
/* proto_data cannot be static because it's referenced in the
|
|
|
|
* print routines
|
|
|
|
*/
|
2013-03-16 08:52:09 +00:00
|
|
|
void proto_register_data(void);
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
int proto_data = -1;
|
2009-01-16 11:51:19 +00:00
|
|
|
|
|
|
|
static int hf_data_data = -1;
|
2010-05-19 07:21:55 +00:00
|
|
|
static int hf_data_text = -1;
|
2009-01-16 11:51:19 +00:00
|
|
|
static int hf_data_len = -1;
|
2010-09-24 23:05:30 +00:00
|
|
|
static int hf_data_md5_hash = -1;
|
2010-05-19 07:21:55 +00:00
|
|
|
|
|
|
|
static gboolean new_pane = FALSE;
|
|
|
|
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
|
|
|
|
2002-04-04 05:16:15 +00:00
|
|
|
static void
|
2003-04-22 13:47:38 +00:00
|
|
|
dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
|
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) {
|
2001-11-26 05:41:15 +00:00
|
|
|
bytes = tvb_length_remaining(tvb, 0);
|
2000-05-12 06:23:33 +00:00
|
|
|
if (bytes > 0) {
|
2012-05-07 13:13:49 +00:00
|
|
|
tvbuff_t *data_tvb;
|
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) {
|
2013-03-16 08:52:09 +00:00
|
|
|
guint8 *real_data = (guint8 *)tvb_memdup(tvb, 0, bytes);
|
2009-06-29 22:22:30 +00:00
|
|
|
data_tvb = tvb_new_child_real_data(tvb,real_data,bytes,bytes);
|
|
|
|
tvb_set_free_cb(data_tvb, g_free);
|
|
|
|
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
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(data_tree, hf_data_data, data_tvb, 0, bytes, ENC_NA);
|
2009-01-16 11:51:19 +00:00
|
|
|
|
2010-05-19 07:21:55 +00:00
|
|
|
if (show_as_text) {
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item(data_tree, hf_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;
|
2012-05-07 13:13:49 +00:00
|
|
|
md5_state_t md_ctx;
|
|
|
|
md5_byte_t digest[16];
|
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);
|
|
|
|
|
|
|
|
md5_init(&md_ctx);
|
|
|
|
md5_append(&md_ctx, cp, bytes);
|
|
|
|
md5_finish(&md_ctx, digest);
|
|
|
|
|
|
|
|
digest_string = bytestring_to_str(digest, 16, '\0');
|
|
|
|
ti = proto_tree_add_string(data_tree, hf_data_md5_hash, tvb, 0, 0, digest_string);
|
|
|
|
PROTO_ITEM_SET_GENERATED(ti);
|
|
|
|
}
|
|
|
|
|
2009-06-29 22:22:30 +00:00
|
|
|
ti = proto_tree_add_int(data_tree, hf_data_len, data_tvb, 0, 0, bytes);
|
2009-01-16 11:51:19 +00:00
|
|
|
PROTO_ITEM_SET_GENERATED (ti);
|
2000-05-12 06:23:33 +00:00
|
|
|
}
|
2000-05-11 22:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-07 22:52:57 +00:00
|
|
|
void
|
|
|
|
proto_register_data(void)
|
|
|
|
{
|
2007-09-28 19:16:05 +00:00
|
|
|
static hf_register_info hf[] = {
|
2009-01-16 11:51:19 +00:00
|
|
|
{ &hf_data_data,
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
{ "Data", "data.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
|
2010-05-19 07:21:55 +00:00
|
|
|
{ &hf_data_text,
|
|
|
|
{ "Text", "data.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
|
2010-09-24 23:05:30 +00:00
|
|
|
{ &hf_data_md5_hash,
|
|
|
|
{ "Payload MD5 hash", "data.md5_hash", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
|
2009-01-16 11:51:19 +00:00
|
|
|
{ &hf_data_len,
|
|
|
|
{ "Length", "data.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } }
|
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 */
|
|
|
|
);
|
|
|
|
|
2002-04-04 05:16:15 +00:00
|
|
|
register_dissector("data", dissect_data, proto_data);
|
2001-11-25 21:44:57 +00:00
|
|
|
|
2007-09-28 19:16:05 +00:00
|
|
|
proto_register_field_array(proto_data, hf, array_length(hf));
|
|
|
|
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);
|
|
|
|
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
|
|
|
}
|