2013-11-20 19:17:08 +00:00
|
|
|
/* decode_as.c
|
|
|
|
* Routines for dissector Decode As handlers
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "decode_as.h"
|
2013-11-22 00:20:23 +00:00
|
|
|
#include "packet.h"
|
2015-10-29 13:23:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-11-20 19:17:08 +00:00
|
|
|
|
|
|
|
GList *decode_as_list = NULL;
|
|
|
|
|
|
|
|
void register_decode_as(decode_as_t* reg)
|
|
|
|
{
|
2015-10-29 13:23:55 +00:00
|
|
|
dissector_table_t decode_table;
|
|
|
|
|
2013-11-20 19:17:08 +00:00
|
|
|
/* Ensure valid functions */
|
|
|
|
DISSECTOR_ASSERT(reg->populate_list);
|
|
|
|
DISSECTOR_ASSERT(reg->reset_value);
|
|
|
|
DISSECTOR_ASSERT(reg->change_value);
|
|
|
|
|
2015-10-29 13:23:55 +00:00
|
|
|
/* Ensure the dissector table can't have duplicate protocols
|
|
|
|
that could confuse users */
|
|
|
|
decode_table = find_dissector_table(reg->table_name);
|
|
|
|
/* XXX - This should really be a DISSECTOR_ASSERT but a Bluetooth
|
|
|
|
* dissector is registering for "media_type" dissector table before it
|
|
|
|
* can be created
|
|
|
|
* There is also the "fake" DCE/RPC dissector table that needs to be fixed
|
|
|
|
*/
|
|
|
|
if (decode_table != NULL)
|
|
|
|
{
|
|
|
|
/* FT_STRING can at least show the string value in the dialog, so don't penalize them */
|
|
|
|
if ((dissector_table_get_type(decode_table) != FT_STRING) &&
|
|
|
|
(dissector_table_get_proto_allowed(decode_table) != DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s allows duplicates, which can lead to confuse in the Decode As dialog\n", reg->table_name);
|
|
|
|
if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:17:08 +00:00
|
|
|
decode_as_list = g_list_append(decode_as_list, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct decode_as_default_populate
|
|
|
|
{
|
|
|
|
decode_as_add_to_list_func add_to_list;
|
|
|
|
gpointer ui_element;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
decode_proto_add_to_list (const gchar *table_name, gpointer value, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct decode_as_default_populate* populate = (struct decode_as_default_populate*)user_data;
|
|
|
|
const gchar *proto_name;
|
|
|
|
gint i;
|
|
|
|
dissector_handle_t handle;
|
|
|
|
|
|
|
|
|
|
|
|
handle = (dissector_handle_t)value;
|
|
|
|
proto_name = dissector_handle_get_short_name(handle);
|
|
|
|
|
|
|
|
i = dissector_handle_get_protocol_index(handle);
|
|
|
|
if (i >= 0 && !proto_is_protocol_enabled(find_protocol_by_id(i)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
populate->add_to_list(table_name, proto_name, value, populate->ui_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
void decode_as_default_populate_list(const gchar *table_name, decode_as_add_to_list_func add_to_list, gpointer ui_element)
|
|
|
|
{
|
|
|
|
struct decode_as_default_populate populate;
|
|
|
|
|
|
|
|
populate.add_to_list = add_to_list;
|
|
|
|
populate.ui_element = ui_element;
|
|
|
|
|
|
|
|
dissector_table_foreach_handle(table_name, decode_proto_add_to_list, &populate);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean decode_as_default_reset(const char *name, const gpointer pattern)
|
|
|
|
{
|
2015-03-08 13:59:32 +00:00
|
|
|
switch (get_dissector_table_selector_type(name)) {
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
dissector_reset_uint(name, GPOINTER_TO_UINT(pattern));
|
|
|
|
return TRUE;
|
|
|
|
case FT_STRING:
|
|
|
|
case FT_STRINGZ:
|
|
|
|
case FT_UINT_STRING:
|
|
|
|
case FT_STRINGZPAD:
|
|
|
|
dissector_reset_string(name, (!pattern)?"":(gchar *) pattern);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
};
|
|
|
|
|
2013-11-20 19:17:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean decode_as_default_change(const char *name, const gpointer pattern, gpointer handle, gchar* list_name _U_)
|
|
|
|
{
|
|
|
|
dissector_handle_t* dissector = (dissector_handle_t*)handle;
|
2015-03-08 13:59:32 +00:00
|
|
|
if (dissector != NULL) {
|
|
|
|
switch (get_dissector_table_selector_type(name)) {
|
|
|
|
case FT_UINT8:
|
|
|
|
case FT_UINT16:
|
|
|
|
case FT_UINT24:
|
|
|
|
case FT_UINT32:
|
|
|
|
dissector_change_uint(name, GPOINTER_TO_UINT(pattern), *dissector);
|
|
|
|
return TRUE;
|
|
|
|
case FT_STRING:
|
|
|
|
case FT_STRINGZ:
|
|
|
|
case FT_UINT_STRING:
|
|
|
|
case FT_STRINGZPAD:
|
|
|
|
dissector_change_string(name, (!pattern)?"":(gchar *) pattern, *dissector);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
};
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:17:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-22 00:20:23 +00:00
|
|
|
|
2013-11-29 15:46:50 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|