From 3619cc26e674ba75c576798e628120cc53c48ba5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 26 Jan 2022 18:42:51 +0100 Subject: [PATCH] hex to bytes epan/dissectors/pidl/drsuapi/drsuapi.cnf --- epan/dissectors/pidl/drsuapi/drsuapi.cnf | 47 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/epan/dissectors/pidl/drsuapi/drsuapi.cnf b/epan/dissectors/pidl/drsuapi/drsuapi.cnf index 92c5df2c9a..2b2d587816 100644 --- a/epan/dissectors/pidl/drsuapi/drsuapi.cnf +++ b/epan/dissectors/pidl/drsuapi/drsuapi.cnf @@ -19,6 +19,7 @@ CODE START #include #include + #include #define KERBEROS_METZE 1 #include "packet-kerberos.h" @@ -79,6 +80,15 @@ drsuapi_dissect_element_DsReplicaAttribute_attid(tvbuff_t *tvb _U_, int offset _ return offset; } +static gboolean +drsuapi_GByteArray_destroy_cb(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_, void *user_data _U_) +{ + GByteArray *bytes = (GByteArray *)user_data; + g_byte_array_free(bytes, TRUE); + /* unregister this callback */ + return FALSE; +} + int drsuapi_dissect_struct_supplementalCredentialsPackage(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, dcerpc_info* di _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_) { @@ -86,6 +96,7 @@ drsuapi_dissect_struct_supplementalCredentialsPackage(tvbuff_t *tvb _U_, int off proto_tree *tree = NULL; int old_offset; guint16 name_len = 0; + const char *name = NULL; guint16 data_len = 0; ALIGN_TO_2_BYTES; @@ -111,20 +122,48 @@ if (0) { if (0) { offset = drsuapi_dissect_element_supplementalCredentialsPackage_name(tvb, offset, pinfo, tree, di, drep); } else { - const guint8 *name = NULL; + const guint8 *_name = NULL; proto_tree_add_item_ret_string(tree, hf_drsuapi_supplementalCredentialsPackage_name, tvb, offset, name_len, ENC_UTF_16|ENC_LITTLE_ENDIAN, - wmem_packet_scope(), &name); + wmem_packet_scope(), &_name); + name = (const char *)_name; proto_item_append_text(item, ": %s", name); offset += name_len; } if (0) { offset = drsuapi_dissect_element_supplementalCredentialsPackage_data(tvb, offset, pinfo, tree, di, drep); } else { - const guint8 *hexdata = NULL; + const guint8 *_hexdata = NULL; + const char *hexdata = NULL; + tvbuff_t *tvbdata = NULL; proto_tree_add_item_ret_string(tree, hf_drsuapi_supplementalCredentialsPackage_data, tvb, offset, data_len, ENC_ASCII, - wmem_packet_scope(), &hexdata); + wmem_packet_scope(), &_hexdata); + hexdata = (const char *)_hexdata; + if (hexdata != NULL) { + GByteArray *bytes = NULL; + + /* Convert key to raw bytes */ + bytes = g_byte_array_new(); + if (bytes != NULL) { + gboolean res; + + wmem_register_callback(wmem_packet_scope(), drsuapi_GByteArray_destroy_cb, bytes); + + res = hex_str_to_bytes(hexdata, bytes, FALSE); + if (res) { + tvbdata = tvb_new_child_real_data(tvb, + bytes->data, + bytes->len, + bytes->len); + } + } + } + + if (tvbdata != NULL) { + add_new_data_source(pinfo, tvbdata, name); + } + offset += data_len; } -- 2.11.4.GIT