From b392640daeae71fa45569087e5abdbe9f5973e6a Mon Sep 17 00:00:00 2001 From: nickid2018 Date: Sun, 2 Jun 2024 23:37:51 +0800 Subject: [PATCH] use pinfo->pool --- protocol_data.c | 4 +- protocol_data.h | 2 +- protocol_je/je_dissect.c | 16 ++++---- protocol_je/je_protocol.c | 26 ++++++------- protocol_je/je_protocol.h | 10 ++--- protocols/protocol_functions.h | 2 +- protocols/protocol_schema.c | 68 ++++++++++++++++++---------------- protocols/protocol_schema.h | 4 +- utils/data_recorder.c | 13 ++++--- utils/data_recorder.h | 2 +- 10 files changed, 77 insertions(+), 70 deletions(-) diff --git a/protocol_data.c b/protocol_data.c index 7649bbd..63c2450 100644 --- a/protocol_data.c +++ b/protocol_data.c @@ -46,12 +46,12 @@ gint read_var_long(tvbuff_t *tvb, gint offset, gint64 *result) { return p; } -gint read_buffer(tvbuff_t *tvb, gint offset, guint8 **result) { +gint read_buffer(tvbuff_t *tvb, gint offset, guint8 **result, wmem_allocator_t *allocator) { gint length; gint read = read_var_int(tvb, offset, &length); if (is_invalid(read)) return INVALID_DATA; - *result = wmem_alloc(wmem_packet_scope(), length + 1); + *result = wmem_alloc(allocator, length + 1); tvb_memcpy(tvb, *result, offset + read, length); (*result)[length] = '\0'; return read + length; diff --git a/protocol_data.h b/protocol_data.h index 3864ef5..665f680 100644 --- a/protocol_data.h +++ b/protocol_data.h @@ -57,6 +57,6 @@ gint read_var_int_with_limit(tvbuff_t *tvb, gint offset, gint max_length, gint * gint read_var_long(tvbuff_t *tvb, gint offset, gint64 *result); -gint read_buffer(tvbuff_t *tvb, gint offset, guint8 **result); +gint read_buffer(tvbuff_t *tvb, gint offset, guint8 **resul, wmem_allocator_t *allocator); #endif //MC_DISSECTOR_PROTOCOL_DATA_H diff --git a/protocol_je/je_dissect.c b/protocol_je/je_dissect.c index 10cfb91..4660c28 100644 --- a/protocol_je/je_dissect.c +++ b/protocol_je/je_dissect.c @@ -24,7 +24,7 @@ void sub_dissect_je(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, mcje_pr if (!visited && is_invalid(handle_server_handshake_switch(tvb, ctx))) return; if (tree) - handle_server_handshake(tree, tvb); + handle_server_handshake(tree, pinfo, tvb); return; case PING: if (tree) @@ -35,19 +35,19 @@ void sub_dissect_je(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, mcje_pr if (!visited && is_invalid(handle_server_login_switch(tvb, ctx))) return; if (tree) - handle_login(tree, tvb, ctx, false); + handle_login(tree, pinfo, tvb, ctx, false); return; case PLAY: if (!visited && is_invalid(handle_server_play_switch(tvb, ctx))) return; if (tree) - handle_play(tree, tvb, ctx, false); + handle_play(tree, pinfo, tvb, ctx, false); return; case CONFIGURATION: if (!visited && is_invalid(handle_server_configuration_switch(tvb, ctx))) return; if (tree) - handle_configuration(tree, tvb, ctx, false); + handle_configuration(tree, pinfo, tvb, ctx, false); return; default: col_add_str(pinfo->cinfo, COL_INFO, "[Invalid State]"); @@ -57,26 +57,26 @@ void sub_dissect_je(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, mcje_pr switch (ctx->client_state) { case PING: if (tree) - handle_client_slp(tree, tvb); + handle_client_slp(tree, pinfo, tvb); return; case LOGIN: case TRANSFER: if (!visited && is_invalid(handle_client_login_switch(tvb, ctx))) return; if (tree) - handle_login(tree, tvb, ctx, true); + handle_login(tree, pinfo, tvb, ctx, true); return; case PLAY: if (!visited && is_invalid(handle_client_play_switch(tvb, ctx))) return; if (tree) - handle_play(tree, tvb, ctx, true); + handle_play(tree, pinfo, tvb, ctx, true); return; case CONFIGURATION: if (!visited && is_invalid(handle_client_configuration_switch(tvb, ctx))) return; if (tree) - handle_configuration(tree, tvb, ctx, true); + handle_configuration(tree, pinfo, tvb, ctx, true); return; default: col_add_str(pinfo->cinfo, COL_INFO, "[Invalid State]"); diff --git a/protocol_je/je_protocol.c b/protocol_je/je_protocol.c index 6f69519..e650822 100644 --- a/protocol_je/je_protocol.c +++ b/protocol_je/je_protocol.c @@ -51,7 +51,7 @@ int handle_server_handshake_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { return INVALID_DATA; } -void handle_server_handshake(proto_tree *packet_tree, tvbuff_t *tvb) { +void handle_server_handshake(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb) { gint packet_id; gint p; gint read = p = read_var_int(tvb, 0, &packet_id); @@ -75,7 +75,7 @@ void handle_server_handshake(proto_tree *packet_tree, tvbuff_t *tvb) { p += read; guint8 *server_address; - read = read_buffer(tvb, p, &server_address); + read = read_buffer(tvb, p, &server_address, pinfo->pool); if (is_invalid(read)) { proto_tree_add_string(packet_tree, hf_server_address_je, tvb, p, -1, "Invalid Server Address"); return; @@ -121,7 +121,7 @@ void handle_server_slp(proto_tree *packet_tree, tvbuff_t *tvb) { proto_tree_add_string(packet_tree, hf_packet_name_je, tvb, 0, read, "Unknown Packet ID"); } -void handle_client_slp(proto_tree *packet_tree, tvbuff_t *tvb) { +void handle_client_slp(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb) { gint packet_id; gint p; gint read = p = read_var_int(tvb, 0, &packet_id); @@ -134,7 +134,7 @@ void handle_client_slp(proto_tree *packet_tree, tvbuff_t *tvb) { if (packet_id == PACKET_ID_CLIENT_SERVER_INFO) { proto_tree_add_string(packet_tree, hf_packet_name_je, tvb, 0, read, "Client Server Info"); guint8 *server_info; - read = read_buffer(tvb, p, &server_info); + read = read_buffer(tvb, p, &server_info, pinfo->pool); if (is_invalid(read)) { proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, p, -1, "Invalid Server Info"); return; @@ -215,7 +215,7 @@ int handle_server_login_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { return 0; } -void handle(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, protocol_set protocol_set, bool is_client) { +void handle(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, protocol_set protocol_set, bool is_client) { gint packet_id; gint p; gint read = p = read_var_int(tvb, 0, &packet_id); @@ -252,18 +252,18 @@ void handle(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, gint length = (gint) tvb_reported_length(tvb); if (ignore) proto_tree_add_string(packet_tree, hf_ignored_packet_je, tvb, p, length - p, "Ignored by user"); - else if (!make_tree(protocol, packet_tree, tvb, ctx->extra, length)) + else if (!make_tree(protocol, packet_tree, pinfo, tvb, ctx->extra, length)) proto_tree_add_string(packet_tree, hf_ignored_packet_je, tvb, p, length - p, "Protocol hasn't been implemented yet"); } -void handle_login(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { +void handle_login(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { if (ctx->protocol_set == NULL) { proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, 0, 1, "Can't find protocol set for this version"); ctx->client_state = ctx->server_state = INVALID; return; } - handle(packet_tree, tvb, ctx, ctx->protocol_set->login, is_client); + handle(packet_tree, pinfo, tvb, ctx, ctx->protocol_set->login, is_client); } int handle_client_play_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { @@ -294,16 +294,16 @@ int handle_server_play_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { return 0; } -void handle_play(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { +void handle_play(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { if (ctx->protocol_set == NULL) { proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, 0, 1, "Can't find protocol set for this version"); ctx->client_state = ctx->server_state = INVALID; return; } - handle(packet_tree, tvb, ctx, ctx->protocol_set->play, is_client); + handle(packet_tree, pinfo, tvb, ctx, ctx->protocol_set->play, is_client); } -int handle_client_configuration_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { +int handle_client_configuration_switch(tvbuff_t *tvb, mcje_protocol_context *ctx) { if (ctx->protocol_set == NULL) { ctx->client_state = ctx->server_state = INVALID; return -1; @@ -331,11 +331,11 @@ int handle_server_configuration_switch(tvbuff_t *tvb, mcje_protocol_context *ctx return 0; } -void handle_configuration(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { +void handle_configuration(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client) { if (ctx->protocol_set == NULL) { proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, 0, 1, "Can't find protocol set for this version"); ctx->client_state = ctx->server_state = INVALID; return; } - handle(packet_tree, tvb, ctx, ctx->protocol_set->configuration, is_client); + handle(packet_tree, pinfo, tvb, ctx, ctx->protocol_set->configuration, is_client); } \ No newline at end of file diff --git a/protocol_je/je_protocol.h b/protocol_je/je_protocol.h index 6573513..5475641 100644 --- a/protocol_je/je_protocol.h +++ b/protocol_je/je_protocol.h @@ -20,28 +20,28 @@ int handle_server_handshake_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); -void handle_server_handshake(proto_tree *packet_tree, tvbuff_t *tvb); +void handle_server_handshake(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb); void handle_server_slp(proto_tree *packet_tree, tvbuff_t *tvb); -void handle_client_slp(proto_tree *packet_tree, tvbuff_t *tvb); +void handle_client_slp(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb); int handle_client_login_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); int handle_server_login_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); -void handle_login(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); +void handle_login(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); int handle_client_play_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); int handle_server_play_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); -void handle_play(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); +void handle_play(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); int handle_client_configuration_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); int handle_server_configuration_switch(tvbuff_t *tvb, mcje_protocol_context *ctx); -void handle_configuration(proto_tree *packet_tree, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); +void handle_configuration(proto_tree *packet_tree, packet_info *pinfo, tvbuff_t *tvb, mcje_protocol_context *ctx, bool is_client); #endif //MC_DISSECTOR_JE_PROTOCOL_H diff --git a/protocols/protocol_functions.h b/protocols/protocol_functions.h index 09cfbed..4f50828 100644 --- a/protocols/protocol_functions.h +++ b/protocols/protocol_functions.h @@ -9,7 +9,7 @@ #include "protocol_schema.h" #define FIELD_MAKE_TREE(name) \ -gint make_tree_##name(proto_tree *tree, tvbuff_t *tvb, extra_data *extra, protocol_field field, gint offset, gint remaining, data_recorder recorder, bool is_je) +gint make_tree_##name(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, extra_data *extra, protocol_field field, gint offset, gint remaining, data_recorder recorder, bool is_je) #define SINGLE_LENGTH_FIELD_MAKE(name, len, func_add, func_parse, record) \ FIELD_MAKE_TREE(name) { \ diff --git a/protocols/protocol_schema.c b/protocols/protocol_schema.c index 96bdc53..5f807f1 100644 --- a/protocols/protocol_schema.c +++ b/protocols/protocol_schema.c @@ -50,7 +50,7 @@ FIELD_MAKE_TREE(var_long) { FIELD_MAKE_TREE(string) { guint8 *str; - gint length = read_buffer(tvb, offset, &str); + gint length = read_buffer(tvb, offset, &str, pinfo->pool); if (tree) proto_tree_add_string(tree, field->hf_index, tvb, offset, length, record(recorder, str)); else @@ -64,10 +64,10 @@ FIELD_MAKE_TREE(var_buffer) { if (tree) { if (length < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length + read, - tvb_memdup(wmem_packet_scope(), tvb, offset + read, length)); + tvb_memdup(pinfo->pool, tvb, offset + read, length)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length + read, - tvb_memdup(wmem_packet_scope(), tvb, offset + read, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset + read, BYTES_MAX_LENGTH)); } return read + length; } @@ -98,16 +98,16 @@ FIELD_MAKE_TREE(rest_buffer) { if (tree) { if (remaining < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, remaining, - tvb_memdup(wmem_packet_scope(), tvb, offset, remaining)); + tvb_memdup(pinfo->pool, tvb, offset, remaining)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, remaining, - tvb_memdup(wmem_packet_scope(), tvb, offset, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset, BYTES_MAX_LENGTH)); } return remaining; } FIELD_MAKE_TREE(uuid) { - e_guid_t *uuid = wmem_new(wmem_packet_scope(), e_guid_t); + e_guid_t *uuid = wmem_new(pinfo->pool, e_guid_t); tvb_get_guid(tvb, offset, uuid, 0); if (tree) proto_tree_add_guid(tree, field->hf_index, tvb, offset, 16, record(recorder, uuid)); @@ -128,10 +128,10 @@ FIELD_MAKE_TREE(nbt) { if (tree) { if (length < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, length)); + tvb_memdup(pinfo->pool, tvb, offset, length)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset, BYTES_MAX_LENGTH)); } return length; } @@ -147,10 +147,10 @@ FIELD_MAKE_TREE(optional_nbt) { if (tree) { if (length < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, length)); + tvb_memdup(pinfo->pool, tvb, offset, length)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset, BYTES_MAX_LENGTH)); } return length; } @@ -168,10 +168,10 @@ FIELD_MAKE_TREE(nbt_any_type) { if (tree) { if (length < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length + 1, - tvb_memdup(wmem_packet_scope(), tvb, offset, length + 1)); + tvb_memdup(pinfo->pool, tvb, offset, length + 1)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length + 1, - tvb_memdup(wmem_packet_scope(), tvb, offset, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset, BYTES_MAX_LENGTH)); } return length + 1; } @@ -196,12 +196,12 @@ FIELD_MAKE_TREE(container) { if (is_anon && not_top) { record_pop(recorder); record_start(recorder, now_record); - sub_field->make_tree(NULL, tvb, extra, sub_field, offset, remaining, recorder, is_je); + sub_field->make_tree(NULL, pinfo, tvb, extra, sub_field, offset, remaining, recorder, is_je); record_start(recorder, now_record); record_push(recorder); } record_start(recorder, sub_field->name); - gint sub_length = sub_field->make_tree(tree, tvb, extra, sub_field, offset, remaining, recorder, is_je); + gint sub_length = sub_field->make_tree(tree, pinfo, tvb, extra, sub_field, offset, remaining, recorder, is_je); offset += sub_length; total_length += sub_length; remaining -= sub_length; @@ -222,7 +222,7 @@ FIELD_MAKE_TREE(option) { sub_field->hf_resolved = true; } if (is_present) - return sub_field->make_tree(tree, tvb, extra, sub_field, offset + 1, remaining - 1, recorder, is_je) + 1; + return sub_field->make_tree(tree, pinfo, tvb, extra, sub_field, offset + 1, remaining - 1, recorder, is_je) + 1; else return 1; } @@ -232,10 +232,10 @@ FIELD_MAKE_TREE(buffer) { if (tree) { if (length < BYTES_MAX_LENGTH) proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, length)); + tvb_memdup(pinfo->pool, tvb, offset, length)); else proto_tree_add_bytes(tree, field->hf_index, tvb, offset, length, - tvb_memdup(wmem_packet_scope(), tvb, offset, BYTES_MAX_LENGTH)); + tvb_memdup(pinfo->pool, tvb, offset, BYTES_MAX_LENGTH)); } return length; } @@ -244,7 +244,7 @@ FIELD_MAKE_TREE(mapper) { protocol_field sub_field = wmem_map_lookup(field->additional_info, "__subfield"); gchar *recording = record_get_recording(recorder); record_start(recorder, "__mapperValue"); - gint length = sub_field->make_tree(NULL, tvb, extra, sub_field, offset, remaining, recorder, is_je); + gint length = sub_field->make_tree(NULL, pinfo, tvb, extra, sub_field, offset, remaining, recorder, is_je); char *path[] = {"__mapperValue", NULL}; gchar *map = record_query(recorder, path); gchar *map_name = wmem_map_lookup(field->additional_info, map); @@ -289,7 +289,8 @@ FIELD_MAKE_TREE(array) { else sub_field->name = g_strdup_printf("[%d]", i); sub_field->display_name = g_strdup_printf("[%d]", i); - gint sub_length = sub_field->make_tree(sub_tree, tvb, extra, sub_field, offset, remaining, recorder, is_je); + gint sub_length = sub_field->make_tree(sub_tree, pinfo, tvb, extra, sub_field, offset, remaining, recorder, + is_je); offset += sub_length; len += sub_length; remaining -= sub_length; @@ -363,8 +364,8 @@ FIELD_MAKE_TREE(top_bit_set_terminated_array) { else sub_field->name = g_strdup_printf("[%d]", ord); sub_field->display_name = g_strdup_printf("[%d]", ord); - gint sub_length = sub_field->make_tree(sub_tree, tvb, extra, sub_field, offset, remaining - len, recorder, - is_je); + gint sub_length = sub_field->make_tree(sub_tree, pinfo, tvb, extra, sub_field, offset, remaining - len, + recorder, is_je); offset += sub_length; len += sub_length; } while ((now & 0x80) != 0); @@ -390,7 +391,8 @@ FIELD_MAKE_TREE(switch) { } char *display_name_raw = sub_field_choose->display_name; sub_field_choose->display_name = field->display_name; - gint len = sub_field_choose->make_tree(tree, tvb, extra, sub_field_choose, offset, remaining, recorder, is_je); + gint len = sub_field_choose->make_tree(tree, pinfo, tvb, extra, sub_field_choose, offset, remaining, recorder, + is_je); sub_field_choose->display_name = display_name_raw; return len; } @@ -420,8 +422,8 @@ FIELD_MAKE_TREE(entity_metadata_loop) { else sub_field->name = g_strdup_printf("[%d]", count); sub_field->display_name = g_strdup_printf("[%d]", count); - gint sub_length = sub_field->make_tree(sub_tree, tvb, extra, sub_field, offset, remaining - len, recorder, - is_je); + gint sub_length = sub_field->make_tree(sub_tree, pinfo, tvb, extra, sub_field, offset, remaining - len, + recorder, is_je); offset += sub_length; len += sub_length; count++; @@ -448,7 +450,7 @@ FIELD_MAKE_TREE(basic_type) { } char *display_name_raw = sub_field->display_name; sub_field->display_name = field->display_name; - gint sub_length = sub_field->make_tree(tree, tvb, extra, sub_field, offset, remaining, recorder, is_je); + gint sub_length = sub_field->make_tree(tree, pinfo, tvb, extra, sub_field, offset, remaining, recorder, is_je); sub_field->display_name = display_name_raw; record_clear_alias(recorder); return sub_length; @@ -928,15 +930,19 @@ protocol_entry get_protocol_entry(protocol_set set, guint packet_id, bool is_cli return wmem_map_lookup(packet_map, GUINT_TO_POINTER(packet_id)); } -bool make_tree(protocol_entry entry, proto_tree *tree, tvbuff_t *tvb, extra_data *extra, gint remaining) { +bool make_tree(protocol_entry entry, proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, extra_data *extra, + gint remaining) { if (entry->field != NULL) { - data_recorder recorder = create_data_recorder(); - guint len = entry->field->make_tree(tree, tvb, extra, entry->field, 1, remaining - 1, recorder, entry->is_je); + data_recorder recorder = create_data_recorder(pinfo->pool); + guint len = entry->field->make_tree(tree, pinfo, tvb, extra, entry->field, 1, remaining - 1, recorder, + entry->is_je); destroy_data_recorder(recorder); if (len != remaining - 1) - proto_tree_add_string_format_value(tree, hf_invalid_data_je, tvb, 1, remaining - 1, - "length mismatch", "Packet length mismatch, expected %d, got %d", len, - remaining - 1); + proto_tree_add_string_format_value( + tree, hf_invalid_data_je, tvb, 1, remaining - 1, + "length mismatch", "Packet length mismatch, expected %d, got %d", len, + remaining - 1 + ); return true; } return false; diff --git a/protocols/protocol_schema.h b/protocols/protocol_schema.h index ef963ef..8448823 100644 --- a/protocols/protocol_schema.h +++ b/protocols/protocol_schema.h @@ -25,7 +25,7 @@ struct _protocol_field { int hf_index; wmem_map_t *additional_info; - gint (*make_tree)(proto_tree *tree, tvbuff_t *tvb, extra_data *extra, protocol_field field, + gint (*make_tree)(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, extra_data *extra, protocol_field field, gint offset, gint remaining, data_recorder recorder, bool is_je); }; @@ -45,6 +45,6 @@ gint get_packet_id(protocol_set set, gchar *name, bool is_client); protocol_entry get_protocol_entry(protocol_set set, guint packet_id, bool is_client); -bool make_tree(protocol_entry entry, proto_tree *tree, tvbuff_t *tvb, extra_data *extra, gint remaining); +bool make_tree(protocol_entry entry, proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, extra_data *extra, gint remaining); #endif //MC_DISSECTOR_PROTOCOL_SCHEMA_H diff --git a/utils/data_recorder.c b/utils/data_recorder.c index 85c97fe..b9a92a1 100644 --- a/utils/data_recorder.c +++ b/utils/data_recorder.c @@ -9,19 +9,20 @@ struct _data_recorder { gchar *recording_path; gchar *recording; wmem_map_t *alias_map; + wmem_allocator_t *allocator; }; -data_recorder create_data_recorder() { +data_recorder create_data_recorder(wmem_allocator_t *allocator) { data_recorder recorder = wmem_new(wmem_packet_scope(), data_recorder_t); - recorder->store_map = wmem_map_new(wmem_packet_scope(), g_str_hash, g_str_equal); - recorder->alias_map = wmem_map_new(wmem_packet_scope(), g_str_hash, g_str_equal); - recorder->recording_path = ""; + recorder->store_map = wmem_map_new(allocator, g_str_hash, g_str_equal); + recorder->alias_map = wmem_map_new(allocator, g_str_hash, g_str_equal); + recorder->recording_path = g_strdup(""); recorder->recording = NULL; + recorder->allocator = allocator; return recorder; } void destroy_data_recorder(data_recorder recorder) { - wmem_free(wmem_packet_scope(), recorder); } void record_start(data_recorder recorder, gchar *name) { @@ -140,5 +141,5 @@ void record_add_alias(data_recorder recorder, gchar *name, gchar *alias) { void record_clear_alias(data_recorder recorder) { wmem_free(wmem_packet_scope(), recorder->alias_map); - recorder->alias_map = wmem_map_new(wmem_packet_scope(), g_str_hash, g_str_equal); + recorder->alias_map = wmem_map_new(recorder->allocator, g_str_hash, g_str_equal); } \ No newline at end of file diff --git a/utils/data_recorder.h b/utils/data_recorder.h index b5a405c..de08df7 100644 --- a/utils/data_recorder.h +++ b/utils/data_recorder.h @@ -9,7 +9,7 @@ typedef struct _data_recorder data_recorder_t, *data_recorder; -data_recorder create_data_recorder(); +data_recorder create_data_recorder(wmem_allocator_t *allocator); void destroy_data_recorder(data_recorder recorder);