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
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2013-08-01 23:34:47 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <wsutil/md5.h>
|
|
|
|
|
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>
|
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
|
|
|
|
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 };
|
|
|
|
|
|
|
|
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;
|
|
|
|
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) {
|
2014-06-19 17:18:16 +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-09-22 15:50:55 +00:00
|
|
|
guint8 *real_data = (guint8 *)tvb_memdup(NULL, 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
|
|
|
|
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
|
|
|
|
2010-05-19 07:21:55 +00:00
|
|
|
if (show_as_text) {
|
2013-08-22 20:54:50 +00:00
|
|
|
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;
|
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);
|
|
|
|
|
2013-12-19 20:53:44 +00:00
|
|
|
digest_string = bytestring_to_str(wmem_packet_scope(), digest, 16, '\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);
|
2010-09-24 23:05:30 +00:00
|
|
|
PROTO_ITEM_SET_GENERATED(ti);
|
|
|
|
}
|
|
|
|
|
2013-08-22 20:54:50 +00:00
|
|
|
ti = proto_tree_add_int(data_tree, &hfi_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)
|
|
|
|
{
|
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,
|
|
|
|
&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 */
|
|
|
|
);
|
|
|
|
|
2002-04-04 05:16:15 +00:00
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*/
|