2010-10-18 16:15:12 +00:00
|
|
|
/* packet-etch.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Holger Grandy, BMW Car IT GmbH (holger.grandy@bmw-carit.de)
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Apache Etch Protocol dissector
|
|
|
|
* http://incubator.apache.org/etch/
|
|
|
|
*
|
|
|
|
* This dissector reads configuration files (generated by Etch IDL compiler).
|
|
|
|
* Configuration file directory path is given in dissector options.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Include files */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <wsutil/file_util.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/report_err.h>
|
|
|
|
#include <epan/dissectors/packet-tcp.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* maximum numbers for symbols from config files
|
|
|
|
*/
|
|
|
|
#define ETCH_MAX_SYMBOL_LENGTH "256"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Magic Number for Etch
|
|
|
|
*/
|
|
|
|
static const guint8 etch_magic[] = { 0xde, 0xad, 0xbe, 0xef };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Typecodes in the Etch protocol, representing the field types
|
|
|
|
*/
|
|
|
|
#define ETCH_TC_NULL 0x80
|
|
|
|
#define ETCH_TC_NONE 0x81
|
|
|
|
#define ETCH_TC_BOOLEAN_FALSE 0x82
|
|
|
|
#define ETCH_TC_BOOLEAN_TRUE 0x83
|
|
|
|
#define ETCH_TC_BYTE 0x84
|
|
|
|
#define ETCH_TC_SHORT 0x85
|
|
|
|
#define ETCH_TC_INT 0x86
|
|
|
|
#define ETCH_TC_LONG 0x87
|
|
|
|
#define ETCH_TC_FLOAT 0x88
|
|
|
|
#define ETCH_TC_DOUBLE 0x89
|
|
|
|
#define ETCH_TC_BYTES 0x8B
|
|
|
|
#define ETCH_TC_ARRAY 0x91
|
|
|
|
#define ETCH_TC_EMPTY_STRING 0x92
|
|
|
|
#define ETCH_TC_STRING 0x93
|
|
|
|
#define ETCH_TC_STRUCT 0x94
|
|
|
|
#define ETCH_TC_CUSTOM 0x95
|
|
|
|
#define ETCH_TC_ANY 0x96
|
|
|
|
#define ETCH_TC_MIN_TINY_INT 0xC0
|
|
|
|
#define ETCH_TC_MAX_TINY_INT 0x7F
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Variables */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* String representation of all Type Codes
|
|
|
|
*/
|
|
|
|
static const value_string tc_lookup_table[] = {
|
|
|
|
{ ETCH_TC_NULL, "Etch TypeCode: NULL"},
|
|
|
|
{ ETCH_TC_NONE, "Etch TypeCode: NONE"},
|
|
|
|
{ ETCH_TC_BOOLEAN_FALSE, "Etch TypeCode: BOOLEAN_FALSE" },
|
|
|
|
{ ETCH_TC_BOOLEAN_TRUE, "Etch TypeCode: BOOLEAN_TRUE"},
|
|
|
|
{ ETCH_TC_BYTE, "Etch TypeCode: BYTE"},
|
|
|
|
{ ETCH_TC_SHORT, "Etch TypeCode: SHORT"},
|
|
|
|
{ ETCH_TC_INT, "Etch TypeCode: INT"},
|
|
|
|
{ ETCH_TC_LONG, "Etch TypeCode: LONG"},
|
|
|
|
{ ETCH_TC_FLOAT, "Etch TypeCode: FLOAT"},
|
|
|
|
{ ETCH_TC_DOUBLE, "Etch TypeCode: DOUBLE"},
|
|
|
|
{ ETCH_TC_BYTES, "Etch TypeCode: BYTES"},
|
|
|
|
{ ETCH_TC_ARRAY, "Etch TypeCode: ARRAY"},
|
|
|
|
{ ETCH_TC_EMPTY_STRING, "Etch TypeCode: EMPTY_STRING"},
|
|
|
|
{ ETCH_TC_STRING, "Etch TypeCode: STRING"},
|
|
|
|
{ ETCH_TC_STRUCT, "Etch TypeCode: STRUCT"},
|
|
|
|
{ ETCH_TC_CUSTOM, "Etch TypeCode: CUSTOM"},
|
|
|
|
{ ETCH_TC_ANY, "Etch TypeCode: ANY"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wireshark internal fields
|
|
|
|
*/
|
|
|
|
static int proto_etch = -1;
|
|
|
|
static gint ett_etch = -1;
|
|
|
|
static gint ett_etch_struct = -1;
|
|
|
|
static gint ett_etch_keyvalue = -1;
|
|
|
|
static gint ett_etch_key = -1;
|
|
|
|
static gint ett_etch_value = -1;
|
|
|
|
static int hf_etch_sig = 0;
|
|
|
|
static int hf_etch_length = 0;
|
|
|
|
static int hf_etch_version = 0;
|
|
|
|
static int hf_etch_typecode = 0;
|
|
|
|
static int hf_etch_value = 0;
|
|
|
|
static int hf_etch_bytes = 0;
|
|
|
|
static int hf_etch_byte = 0;
|
|
|
|
static int hf_etch_short = 0;
|
|
|
|
static int hf_etch_int = 0;
|
|
|
|
static int hf_etch_long = 0;
|
|
|
|
static int hf_etch_float = 0;
|
|
|
|
static int hf_etch_double = 0;
|
|
|
|
static int hf_etch_key = 0;
|
|
|
|
static int hf_etch_valuename = 0;
|
|
|
|
static int hf_etch_keyname = 0;
|
|
|
|
static int hf_etch_string = 0;
|
|
|
|
static int hf_etch_keyvalue = 0;
|
|
|
|
static int hf_etch_struct = 0;
|
|
|
|
static int hf_etch_dim = 0;
|
|
|
|
static int hf_etch_symbol = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* internal fields/defines for dissector
|
|
|
|
*/
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
static const char *gbl_keytab_folder = "";
|
|
|
|
static guint gbl_etch_port = 0;
|
|
|
|
static char *gbl_current_keytab_folder = NULL;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
static int gbl_pdu_counter;
|
|
|
|
static guint32 gbl_old_frame_num;
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
static emem_strbuf_t *gbl_symbol_buffer = NULL;
|
|
|
|
static gboolean gbl_have_symbol = FALSE;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* forward declared dissector methods
|
|
|
|
*/
|
2010-10-19 14:31:05 +00:00
|
|
|
static void read_key_value(unsigned int *offset, tvbuff_t *tvb,
|
|
|
|
proto_tree *etch_tree);
|
|
|
|
static void read_struct(unsigned int *offset, tvbuff_t *tvb,
|
|
|
|
proto_tree *etch_tree, int add_type_field);
|
|
|
|
static int read_value(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
|
2010-10-18 16:15:12 +00:00
|
|
|
int asWhat);
|
|
|
|
void proto_reg_handoff_etch(void);
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Symbol value-string functions
|
|
|
|
* Essentially: Build a value_string_ext at runtime:
|
|
|
|
* a. Upon startup & whenever symbol folder changed: Read from file(s)
|
|
|
|
* and add all hash/symbol pairs to a GArray;
|
|
|
|
* b. When file reads complete, sort the GArray and then create a
|
|
|
|
* value_string_ext from the array for use by match_strval_ext & friends.
|
|
|
|
* (Code based upon code in packet-diameter.c)
|
|
|
|
*/
|
|
|
|
static GArray *gbl_symbols_array = NULL;
|
|
|
|
static value_string_ext *gbl_symbols_vs_ext = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gbl_symbols_new(void) {
|
2010-10-20 00:47:23 +00:00
|
|
|
DISSECTOR_ASSERT(gbl_symbols_array == NULL);
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_array = g_array_new(TRUE, TRUE, sizeof(value_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gbl_symbols_free(void) {
|
|
|
|
g_free(gbl_symbols_vs_ext);
|
|
|
|
gbl_symbols_vs_ext = NULL;
|
|
|
|
|
|
|
|
if (gbl_symbols_array != NULL) {
|
|
|
|
value_string *vs_p;
|
|
|
|
guint i;
|
2011-04-22 03:31:06 +00:00
|
|
|
vs_p = (value_string *)(void *)gbl_symbols_array->data;
|
2010-10-19 14:31:05 +00:00
|
|
|
for (i=0; i<gbl_symbols_array->len; i++) {
|
|
|
|
g_free((gchar *)vs_p[i].strptr);
|
|
|
|
}
|
|
|
|
g_array_free(gbl_symbols_array, TRUE);
|
|
|
|
gbl_symbols_array = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gbl_symbols_array_append(int hash, gchar *symbol) {
|
|
|
|
value_string vs = {hash, symbol};
|
2010-10-20 00:47:23 +00:00
|
|
|
DISSECTOR_ASSERT(gbl_symbols_array != NULL);
|
2010-10-19 14:31:05 +00:00
|
|
|
g_array_append_val(gbl_symbols_array, vs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gbl_symbols_compare_vs(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
value_string *vsa = (value_string *)a;
|
|
|
|
value_string *vsb = (value_string *)b;
|
|
|
|
|
|
|
|
if(vsa->value > vsb->value)
|
|
|
|
return 1;
|
|
|
|
if(vsa->value < vsb->value)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gbl_symbols_vs_ext_new(void) {
|
2010-10-20 00:47:23 +00:00
|
|
|
DISSECTOR_ASSERT(gbl_symbols_vs_ext == NULL);
|
|
|
|
DISSECTOR_ASSERT(gbl_symbols_array != NULL);
|
2010-10-19 14:31:05 +00:00
|
|
|
g_array_sort(gbl_symbols_array, gbl_symbols_compare_vs);
|
2011-04-22 03:31:06 +00:00
|
|
|
gbl_symbols_vs_ext = value_string_ext_new((value_string *)(void *)gbl_symbols_array->data,
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_array->len+1,
|
|
|
|
"etch-global-symbols" );
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:15:12 +00:00
|
|
|
/*********************************************************************************/
|
|
|
|
/* Aux Functions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the length of a given typecode in bytes, -1 if to be derived from message
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static gint32
|
|
|
|
get_byte_length(guint8 typecode)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
switch (typecode) {
|
|
|
|
case ETCH_TC_NULL:
|
|
|
|
case ETCH_TC_NONE:
|
|
|
|
case ETCH_TC_BOOLEAN_FALSE:
|
|
|
|
case ETCH_TC_BOOLEAN_TRUE:
|
2010-10-19 14:31:05 +00:00
|
|
|
case ETCH_TC_EMPTY_STRING:
|
|
|
|
case ETCH_TC_MIN_TINY_INT:
|
|
|
|
case ETCH_TC_MAX_TINY_INT:
|
2010-10-18 16:15:12 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case ETCH_TC_BYTE:
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case ETCH_TC_SHORT:
|
|
|
|
return 2;
|
|
|
|
break;
|
|
|
|
case ETCH_TC_INT:
|
|
|
|
case ETCH_TC_FLOAT:
|
|
|
|
return 4;
|
|
|
|
break;
|
2010-10-19 14:31:05 +00:00
|
|
|
case ETCH_TC_LONG:
|
2010-10-18 16:15:12 +00:00
|
|
|
case ETCH_TC_DOUBLE:
|
|
|
|
return 8;
|
|
|
|
break;
|
|
|
|
case ETCH_TC_BYTES:
|
|
|
|
case ETCH_TC_ARRAY:
|
|
|
|
case ETCH_TC_STRING:
|
|
|
|
case ETCH_TC_STRUCT:
|
|
|
|
case ETCH_TC_CUSTOM:
|
|
|
|
case ETCH_TC_ANY:
|
|
|
|
return -1;
|
|
|
|
break;
|
2010-10-19 14:31:05 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
2010-10-18 16:15:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add all etch symbols from file to our symbol cache
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
|
|
|
add_symbols_of_file(const char *filename)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
FILE *pFile;
|
|
|
|
pFile = ws_fopen(filename, "r");
|
|
|
|
|
|
|
|
if (pFile != NULL) {
|
|
|
|
char line[256];
|
|
|
|
while (fgets(line, sizeof line, pFile) != NULL) {
|
2010-10-18 18:37:07 +00:00
|
|
|
int hash;
|
|
|
|
size_t length, pos;
|
|
|
|
|
2010-10-18 16:15:12 +00:00
|
|
|
length = strlen(line);
|
|
|
|
|
|
|
|
/* Must at least have a hash, else skip line */
|
|
|
|
if (length < 10)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pos = length - 1;
|
|
|
|
while (pos > 0 && (line[pos] == 0xD || line[pos] == 0xA)) {
|
|
|
|
pos--;
|
|
|
|
}
|
|
|
|
line[pos + 1] = '\0';
|
|
|
|
|
|
|
|
/* Parse the Hash */
|
|
|
|
if (sscanf(&line[0], "%x", &hash) != 1)
|
|
|
|
continue; /* didn't find a valid hex value at the beginning of the line */
|
|
|
|
|
|
|
|
/* And read the symbol */
|
|
|
|
pos = strcspn(line, ",");
|
|
|
|
if ((line[pos] != '\0') && (line[pos+1] !='\0')) /* require at least 1 char in symbol */
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_array_append(hash,
|
|
|
|
g_strdup_printf("%." ETCH_MAX_SYMBOL_LENGTH "s", &line[pos+1]));
|
2010-10-18 16:15:12 +00:00
|
|
|
}
|
|
|
|
fclose(pFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add all etch symbol from directory to our symbol cache
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
|
|
|
read_hashed_symbols_from_dir(const char *dirname)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
2010-10-19 14:31:05 +00:00
|
|
|
WS_DIR *dir;
|
|
|
|
WS_DIRENT *file;
|
|
|
|
const char *name;
|
|
|
|
char *filename;
|
|
|
|
GError *err_p = NULL;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
if(gbl_current_keytab_folder != NULL) {
|
|
|
|
g_free(gbl_current_keytab_folder);
|
|
|
|
gbl_current_keytab_folder = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_free();
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
if ((dirname == NULL) || (dirname[0] == '\0'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((dir = ws_dir_open(dirname, 0, &err_p)) != NULL) {
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_new();
|
|
|
|
|
2010-10-18 16:15:12 +00:00
|
|
|
gbl_current_keytab_folder = g_strdup(dirname);
|
|
|
|
while ((file = ws_dir_read_name(dir)) != NULL) {
|
|
|
|
name = ws_dir_get_name(file);
|
|
|
|
|
|
|
|
if (g_str_has_suffix(file, ".ewh")) {
|
|
|
|
filename =
|
|
|
|
g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", dirname,
|
|
|
|
name);
|
|
|
|
add_symbols_of_file(filename);
|
|
|
|
g_free(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ws_dir_close(dir);
|
2010-10-19 14:31:05 +00:00
|
|
|
gbl_symbols_vs_ext_new();
|
2010-10-18 16:15:12 +00:00
|
|
|
}else{
|
|
|
|
report_failure("%s", err_p->message);
|
|
|
|
g_error_free(err_p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************************/
|
2010-10-19 14:31:05 +00:00
|
|
|
/* Etch Protocol Functions */
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read a type flag from tvb and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static guint8
|
2010-10-19 14:31:05 +00:00
|
|
|
read_type(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
guint32 type_code;
|
|
|
|
const gchar *type_as_string;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
type_code = tvb_get_guint8(tvb, *offset);
|
|
|
|
type_as_string = val_to_str(type_code, tc_lookup_table, "Etch TypeCode: 0x%02x");
|
|
|
|
proto_tree_add_text(etch_tree, tvb, *offset, 1, "%s", type_as_string);
|
|
|
|
(*offset)++;
|
|
|
|
return type_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a array type flag and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_array_type(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
guint32 type_code;
|
|
|
|
|
|
|
|
type_code = tvb_get_guint8(tvb, *offset);
|
|
|
|
|
|
|
|
read_type(offset, tvb, etch_tree);
|
2010-10-19 14:31:05 +00:00
|
|
|
if (type_code == ETCH_TC_CUSTOM) {
|
2010-10-18 16:15:12 +00:00
|
|
|
type_code = read_type(offset, tvb, etch_tree);
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_value, tvb, *offset, 4,
|
|
|
|
ENC_BIG_ENDIAN);
|
|
|
|
(*offset) += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read the length of an array and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static guint32
|
2010-10-19 14:31:05 +00:00
|
|
|
read_length(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
guint32 length;
|
|
|
|
int length_of_array_length_type;
|
|
|
|
guint8 tiny;
|
|
|
|
|
|
|
|
tiny = tvb_get_guint8(tvb, *offset);
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* Is this the value already? */
|
2010-10-18 16:15:12 +00:00
|
|
|
if ( tiny <= ETCH_TC_MAX_TINY_INT
|
|
|
|
|| tiny >= ETCH_TC_MIN_TINY_INT) {
|
|
|
|
length = tiny;
|
|
|
|
length_of_array_length_type = 1;
|
|
|
|
} else {
|
|
|
|
guint8 type_code;
|
|
|
|
type_code = read_type(offset, tvb, etch_tree);
|
|
|
|
length_of_array_length_type = get_byte_length(type_code);
|
|
|
|
|
|
|
|
switch (length_of_array_length_type) {
|
|
|
|
case 1:
|
2010-10-19 14:31:05 +00:00
|
|
|
length = tvb_get_guint8(tvb, *offset);
|
2010-10-18 16:15:12 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-10-19 14:31:05 +00:00
|
|
|
length = tvb_get_ntohs(tvb, *offset);
|
2010-10-18 16:15:12 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2010-10-19 14:31:05 +00:00
|
|
|
length = tvb_get_ntohl(tvb, *offset);
|
2010-10-18 16:15:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-10-19 14:31:05 +00:00
|
|
|
return 0; /* error! */
|
2010-10-18 16:15:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_length, tvb, *offset,
|
|
|
|
length_of_array_length_type, ENC_BIG_ENDIAN);
|
|
|
|
(*offset) += length_of_array_length_type;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read an array from tvb and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_array(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* array type */
|
2010-10-18 16:15:12 +00:00
|
|
|
read_type(offset, tvb, etch_tree);
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* Array of type: */
|
2010-10-18 16:15:12 +00:00
|
|
|
read_array_type(offset, tvb, etch_tree);
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* Array dim */
|
2010-10-18 16:15:12 +00:00
|
|
|
proto_tree_add_item(etch_tree, hf_etch_dim, tvb, *offset, 1, ENC_NA);
|
|
|
|
(*offset)++;
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* Array length */
|
2010-10-18 16:15:12 +00:00
|
|
|
length = read_length(offset, tvb, etch_tree);
|
|
|
|
|
|
|
|
for (; length > 0; length--) {
|
|
|
|
read_value(offset, tvb, etch_tree, hf_etch_value);
|
|
|
|
}
|
2010-10-19 14:31:05 +00:00
|
|
|
/* terminaton */
|
2010-10-18 16:15:12 +00:00
|
|
|
read_type(offset, tvb, etch_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a sequence of bytes and add them to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_bytes(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
int length;
|
|
|
|
read_type(offset, tvb, etch_tree);
|
|
|
|
length = read_length(offset, tvb, etch_tree);
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_bytes, tvb, *offset, length,
|
|
|
|
ENC_NA);
|
|
|
|
(*offset) += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a string and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_string(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
int byteLength;
|
|
|
|
read_type(offset, tvb, etch_tree);
|
|
|
|
|
|
|
|
byteLength = read_length(offset, tvb, etch_tree);
|
|
|
|
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_string, tvb, *offset,
|
|
|
|
byteLength, ENC_NA);
|
|
|
|
(*offset) += byteLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a number and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_number(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
|
2010-10-18 21:55:56 +00:00
|
|
|
int asWhat, guint8 type_code)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
int byteLength;
|
|
|
|
|
|
|
|
read_type(offset, tvb, etch_tree);
|
|
|
|
byteLength = get_byte_length(type_code);
|
|
|
|
if (byteLength > 0) {
|
2010-10-19 14:31:05 +00:00
|
|
|
proto_item *ti;
|
|
|
|
const gchar *symbol = NULL;
|
|
|
|
guint32 hash = 0;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
gbl_symbol_buffer = ep_strbuf_new_label(""); /* no symbol found yet */
|
|
|
|
if (byteLength == 4) {
|
|
|
|
hash = tvb_get_ntohl(tvb, *offset);
|
2010-10-19 14:31:05 +00:00
|
|
|
symbol = match_strval_ext(hash, gbl_symbols_vs_ext);
|
2010-10-18 16:15:12 +00:00
|
|
|
if(symbol != NULL) {
|
|
|
|
asWhat = hf_etch_symbol;
|
|
|
|
gbl_have_symbol = TRUE;
|
|
|
|
ep_strbuf_append_printf(gbl_symbol_buffer,"%s",symbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ti = proto_tree_add_item(etch_tree, asWhat, tvb, *offset,
|
|
|
|
byteLength, ENC_BIG_ENDIAN);
|
|
|
|
*offset += byteLength;
|
|
|
|
if (symbol != NULL) {
|
|
|
|
proto_item_append_text(ti, " (0x%08x) %s", hash, symbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a value and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static int
|
2010-10-19 14:31:05 +00:00
|
|
|
read_value(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
|
2010-10-18 21:55:56 +00:00
|
|
|
int asWhat)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
guint8 type_code;
|
|
|
|
|
|
|
|
type_code = tvb_get_guint8(tvb, *offset);
|
|
|
|
if (type_code <= ETCH_TC_MAX_TINY_INT ||
|
|
|
|
type_code >= ETCH_TC_MIN_TINY_INT) {
|
|
|
|
/* this is the value already */
|
|
|
|
proto_tree_add_item(etch_tree, asWhat, tvb, *offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
(*offset)++;
|
|
|
|
return type_code;
|
2010-10-19 14:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(type_code) {
|
|
|
|
case ETCH_TC_CUSTOM:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_struct(offset, tvb, etch_tree, 1);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_ARRAY:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_array(offset, tvb, etch_tree);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_STRING:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_string(offset, tvb, etch_tree);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_FLOAT:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_float, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_DOUBLE:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_double, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_SHORT:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_short, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_INT:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_int, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_LONG:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_long, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_BYTE:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, hf_etch_byte, type_code);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
case ETCH_TC_BYTES:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_bytes(offset, tvb, etch_tree);
|
2010-10-19 14:31:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-10-18 16:15:12 +00:00
|
|
|
read_number(offset, tvb, etch_tree, asWhat, type_code);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a struct and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_struct(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
|
2010-10-18 21:55:56 +00:00
|
|
|
int add_type_field)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *new_tree;
|
|
|
|
int length;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(etch_tree, hf_etch_struct, tvb, *offset,
|
2011-05-27 01:57:33 +00:00
|
|
|
tvb_length(tvb) - *offset, ENC_NA);
|
2010-10-18 16:15:12 +00:00
|
|
|
new_tree = proto_item_add_subtree(ti, ett_etch_struct);
|
|
|
|
|
|
|
|
if (add_type_field) {
|
|
|
|
read_type(offset, tvb, new_tree);
|
|
|
|
}
|
2010-10-19 14:31:05 +00:00
|
|
|
/* struct type as hash */
|
2010-10-18 16:15:12 +00:00
|
|
|
read_value(offset, tvb, new_tree, hf_etch_value);
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/* struct length */
|
2010-10-18 16:15:12 +00:00
|
|
|
length = read_value(offset, tvb, new_tree, hf_etch_length);
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
read_key_value(offset, tvb, new_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* termination */
|
|
|
|
read_type(offset, tvb, new_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a key value pair and add it to tree
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
read_key_value(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
proto_tree *new_tree;
|
|
|
|
proto_tree *new_tree_bck;
|
|
|
|
proto_item *ti, *parent_ti;
|
|
|
|
|
|
|
|
gbl_have_symbol = FALSE;
|
|
|
|
|
|
|
|
parent_ti =
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_keyvalue, tvb, *offset, 1,
|
|
|
|
ENC_NA);
|
|
|
|
new_tree_bck = new_tree =
|
|
|
|
proto_item_add_subtree(parent_ti, ett_etch_keyvalue);
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(new_tree, hf_etch_keyname, tvb, *offset, 0,
|
|
|
|
ENC_NA);
|
|
|
|
new_tree = proto_item_add_subtree(ti, ett_etch_key);
|
|
|
|
read_value(offset, tvb, new_tree, hf_etch_value);
|
|
|
|
|
|
|
|
/* append the symbol of the key */
|
|
|
|
if(gbl_have_symbol == TRUE){
|
|
|
|
proto_item_append_text(parent_ti, " (");
|
|
|
|
proto_item_append_text(parent_ti, "%s", gbl_symbol_buffer->str);
|
|
|
|
proto_item_append_text(parent_ti, ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
ti = proto_tree_add_item(new_tree_bck, hf_etch_valuename, tvb, *offset,
|
|
|
|
0, ENC_NA);
|
|
|
|
new_tree = proto_item_add_subtree(ti, ett_etch_value);
|
|
|
|
read_value(offset, tvb, new_tree, hf_etch_value);
|
|
|
|
}
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
/*************************************************************************/
|
2010-10-18 16:15:12 +00:00
|
|
|
/*
|
|
|
|
* Preparse the message for the info column
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static emem_strbuf_t*
|
2010-10-19 14:31:05 +00:00
|
|
|
get_column_info(tvbuff_t *tvb)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
int byte_length;
|
2010-10-19 14:31:05 +00:00
|
|
|
guint8 type_code;
|
|
|
|
emem_strbuf_t *result_buf;
|
|
|
|
int my_offset = 0;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
/* We've a full PDU: 8 bytes + pdu_packetlen bytes */
|
|
|
|
result_buf = ep_strbuf_new_label("");
|
|
|
|
|
|
|
|
my_offset += (4 + 4 + 1); /* skip Magic, Length, Version */
|
|
|
|
|
|
|
|
type_code = tvb_get_guint8(tvb, my_offset);
|
|
|
|
byte_length = get_byte_length(type_code);
|
|
|
|
my_offset++;
|
|
|
|
|
|
|
|
if (byte_length == 4) {
|
2010-10-19 14:31:05 +00:00
|
|
|
const gchar *symbol;
|
|
|
|
guint32 hash;
|
2010-10-18 16:15:12 +00:00
|
|
|
hash = tvb_get_ntohl(tvb, my_offset);
|
2010-10-19 14:31:05 +00:00
|
|
|
symbol = match_strval_ext(hash, gbl_symbols_vs_ext);
|
2010-10-18 16:15:12 +00:00
|
|
|
if (symbol != NULL) {
|
|
|
|
ep_strbuf_append_printf(result_buf, "%s()", symbol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************************/
|
|
|
|
/*
|
|
|
|
* main dissector function for an etch message
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
2010-10-19 14:31:05 +00:00
|
|
|
dissect_etch_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
/* We've a full PDU: 8 bytes + pdu_packetlen bytes */
|
2010-10-19 14:31:05 +00:00
|
|
|
emem_strbuf_t *colInfo = NULL;
|
2010-10-18 16:15:12 +00:00
|
|
|
|
|
|
|
if (pinfo->cinfo || tree) {
|
|
|
|
colInfo = get_column_info(tvb); /* get current symbol */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pinfo->cinfo) {
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETCH");
|
|
|
|
gbl_pdu_counter++;
|
|
|
|
|
|
|
|
/* Switch to another frame? => Clear column */
|
|
|
|
if (pinfo->fd->num != gbl_old_frame_num) {
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
|
|
|
gbl_pdu_counter = 0;
|
|
|
|
}
|
|
|
|
gbl_old_frame_num = pinfo->fd->num;
|
|
|
|
|
|
|
|
col_set_writable(pinfo->cinfo, 1);
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", colInfo->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
/* we are being asked for details */
|
|
|
|
unsigned int offset;
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *etch_tree;
|
|
|
|
|
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_etch, tvb, 0, -1,
|
|
|
|
"ETCH Protocol: %s", colInfo->str);
|
|
|
|
|
|
|
|
offset = 9;
|
|
|
|
etch_tree = proto_item_add_subtree(ti, ett_etch);
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_sig, tvb, 0, 4, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_length, tvb, 4, 4, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(etch_tree, hf_etch_version, tvb, 8, 1, ENC_NA);
|
|
|
|
read_struct(&offset, tvb, etch_tree, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* determine PDU length of protocol etch
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static guint
|
2010-10-19 14:31:05 +00:00
|
|
|
get_etch_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
/* length is at offset 4. we add magic bytes length + length size */
|
|
|
|
return tvb_get_ntohl(tvb, offset + 4) + 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* main dissector function for the etch protocol
|
|
|
|
*/
|
2010-10-18 21:55:56 +00:00
|
|
|
static int
|
2010-10-19 14:31:05 +00:00
|
|
|
dissect_etch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2010-10-18 16:15:12 +00:00
|
|
|
{
|
|
|
|
if (tvb_length(tvb) < 4) {
|
|
|
|
/* Too small for an etch packet. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tvb_memeql(tvb, 0, etch_magic, 4) == -1) {
|
|
|
|
/* Not an etch packet. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 8, get_etch_message_len,
|
|
|
|
dissect_etch_message);
|
|
|
|
|
|
|
|
if (gbl_pdu_counter > 0) {
|
|
|
|
col_set_writable(pinfo->cinfo, 1);
|
|
|
|
col_prepend_fstr(pinfo->cinfo, COL_INFO, "[%d] ", gbl_pdu_counter + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-18 21:55:56 +00:00
|
|
|
static void
|
|
|
|
etch_dissector_init(void)
|
|
|
|
{
|
2010-10-18 16:15:12 +00:00
|
|
|
gbl_pdu_counter = 0;
|
|
|
|
gbl_old_frame_num = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_register_etch(void)
|
|
|
|
{
|
|
|
|
module_t *etch_module;
|
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{&hf_etch_sig,
|
|
|
|
{"Etch Signature", "etch.signature",
|
|
|
|
FT_UINT32, BASE_HEX,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_length,
|
|
|
|
{"Etch Length", "etch.msglength",
|
|
|
|
FT_UINT64, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_dim,
|
|
|
|
{"Etch Dim", "etch.dim",
|
|
|
|
FT_UINT8, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_version,
|
|
|
|
{"Etch Version", "etch.version",
|
|
|
|
FT_UINT8, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_typecode,
|
|
|
|
{"Etch TypeCode", "etch.typecode",
|
2010-10-19 14:31:05 +00:00
|
|
|
FT_STRING, BASE_NONE, /* FT_INT8 */
|
2010-10-18 16:15:12 +00:00
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_value,
|
|
|
|
{"Etch Value", "etch.value",
|
|
|
|
FT_UINT64, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_bytes,
|
|
|
|
{"Etch Bytes", "etch.bytes",
|
|
|
|
FT_BYTES, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_byte,
|
|
|
|
{"Etch Byte", "etch.byte",
|
|
|
|
FT_INT8, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_short,
|
|
|
|
{"Etch Short", "etch.short",
|
|
|
|
FT_INT16, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_int,
|
|
|
|
{"Etch Int", "etch.int",
|
|
|
|
FT_INT32, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_long,
|
|
|
|
{"Etch Long", "etch.long",
|
|
|
|
FT_INT64, BASE_DEC,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_float,
|
|
|
|
{"Etch Float", "etch.float",
|
|
|
|
FT_FLOAT, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_double,
|
|
|
|
{"Etch Double", "etch.double",
|
|
|
|
FT_DOUBLE, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_keyvalue,
|
|
|
|
{"Etch keyValue", "etch.keyvalue",
|
|
|
|
FT_NONE, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_key,
|
|
|
|
{"Etch key", "etch.key",
|
|
|
|
FT_BYTES, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_symbol,
|
|
|
|
{"Etch symbol", "etch.symbol",
|
|
|
|
FT_UINT32, BASE_HEX,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_struct,
|
|
|
|
{"Etch Struct", "etch.struct",
|
|
|
|
FT_BYTES, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_string,
|
|
|
|
{"Etch String", "etch.string",
|
|
|
|
FT_STRING, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_keyname,
|
|
|
|
{"Etch key", "etch.keyname",
|
|
|
|
FT_NONE, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
{&hf_etch_valuename,
|
|
|
|
{"Etch value", "etch.valuename",
|
|
|
|
FT_NONE, BASE_NONE,
|
|
|
|
NULL, 0x0,
|
|
|
|
NULL, HFILL}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_etch,
|
|
|
|
&ett_etch_struct,
|
|
|
|
&ett_etch_keyvalue,
|
|
|
|
&ett_etch_key,
|
|
|
|
&ett_etch_value,
|
|
|
|
};
|
|
|
|
|
2010-10-19 14:31:05 +00:00
|
|
|
proto_etch = proto_register_protocol("Apache Etch Protocol", /* name */
|
|
|
|
"ETCH", /* short name */
|
|
|
|
"etch" /* abbrev */
|
2010-10-18 16:15:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
proto_register_field_array(proto_etch, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
new_register_dissector("etch", dissect_etch, proto_etch);
|
|
|
|
|
|
|
|
register_init_routine(&etch_dissector_init);
|
|
|
|
|
|
|
|
etch_module = prefs_register_protocol(proto_etch,
|
|
|
|
proto_reg_handoff_etch);
|
|
|
|
|
|
|
|
prefs_register_string_preference(etch_module, "file",
|
2010-10-18 21:55:56 +00:00
|
|
|
"Apache Etch symbol folder",
|
2010-10-19 14:31:05 +00:00
|
|
|
"Place the hash/symbol files "
|
|
|
|
"(generated by the Apache Etch compiler) "
|
|
|
|
"ending with .ewh here",
|
2010-10-18 21:55:56 +00:00
|
|
|
&gbl_keytab_folder);
|
2010-10-18 16:15:12 +00:00
|
|
|
prefs_register_uint_preference(etch_module, "tcp.port",
|
|
|
|
"etch TCP Port",
|
|
|
|
"Etch TCP port",
|
|
|
|
10,
|
|
|
|
&gbl_etch_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_reg_handoff_etch(void)
|
|
|
|
{
|
|
|
|
static gboolean etch_prefs_initialized = FALSE;
|
|
|
|
static dissector_handle_t etch_handle;
|
|
|
|
static guint old_etch_port = 0;
|
|
|
|
|
|
|
|
/* create dissector handle only once */
|
|
|
|
if(!etch_prefs_initialized) {
|
|
|
|
etch_handle = new_create_dissector_handle(dissect_etch, proto_etch);
|
|
|
|
/* add heuristic dissector for tcp */
|
|
|
|
heur_dissector_add("tcp", dissect_etch, proto_etch);
|
|
|
|
etch_prefs_initialized = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(old_etch_port != 0 && old_etch_port != gbl_etch_port){
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_delete_uint("tcp.port", old_etch_port, etch_handle);
|
2010-10-18 16:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(gbl_etch_port != 0 && old_etch_port != gbl_etch_port) {
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", gbl_etch_port, etch_handle);
|
2010-10-18 16:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
old_etch_port = gbl_etch_port;
|
|
|
|
|
2010-10-18 21:55:56 +00:00
|
|
|
/* read config folder files, if filename has changed
|
|
|
|
* (while protecting strcmp() from NULLs)
|
|
|
|
*/
|
|
|
|
if(gbl_keytab_folder == NULL || gbl_current_keytab_folder == NULL ||
|
|
|
|
strcmp(gbl_keytab_folder, gbl_current_keytab_folder) != 0) {
|
2010-10-18 16:15:12 +00:00
|
|
|
read_hashed_symbols_from_dir(gbl_keytab_folder);
|
|
|
|
}
|
|
|
|
}
|