From 62c6b187044dc6dc4f6a8b12940a5090603720ca Mon Sep 17 00:00:00 2001 From: nickid2018 Date: Mon, 24 Jun 2024 20:36:32 +0800 Subject: [PATCH] update pref definition --- mc_dissector.c | 24 ++++++++++++++++++++++++ mc_dissector.h | 18 ++++++++++++------ protocol_be/be_dissect.c | 2 +- protocol_je/je_dissect.c | 2 +- protocol_je/je_dissect.h | 3 --- protocol_je/je_registers.c | 22 ++-------------------- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/mc_dissector.c b/mc_dissector.c index b48e594..2d6b43d 100644 --- a/mc_dissector.c +++ b/mc_dissector.c @@ -17,9 +17,33 @@ WS_DLL_PUBLIC _U_ void plugin_register(); int proto_mcje = -1; int proto_mcbe = -1; +module_t *pref_mcje = NULL; +gchar *pref_ignore_packets_je = "c:map_chunk"; +gchar *pref_secret_key = ""; +gboolean pref_do_nbt_decode = false; + +module_t *pref_mcbe = NULL; + void proto_register() { proto_register_mcje(); proto_register_mcbe(); + + // Preference ------------------------------------------------------------------------------------------------------ + pref_mcje = prefs_register_protocol_subtree("Minecraft", proto_mcje, NULL); + prefs_register_string_preference( + pref_mcje, "ignore_packets", "Ignore Packets", + "Ignore packets with the given names", (const char **) &pref_ignore_packets_je + ); + prefs_register_string_preference( + pref_mcje, "secret_key", "Secret Key", + "Secret key for decryption", (const char **) &pref_secret_key + ); + prefs_register_bool_preference( + pref_mcje, "do_nbt_decode", "NBT Decoding", + "Decode NBT data", &pref_do_nbt_decode + ); + + pref_mcbe = prefs_register_protocol_subtree("Minecraft", proto_mcbe, NULL); } void proto_reg_handoff() { diff --git a/mc_dissector.h b/mc_dissector.h index 451040b..4b01f7d 100644 --- a/mc_dissector.h +++ b/mc_dissector.h @@ -5,10 +5,10 @@ #ifndef MC_DISSECTOR_MC_DISSECTOR_H #define MC_DISSECTOR_MC_DISSECTOR_H -#include +#include -#define MCJE_PORT 25565 -#define MCBE_PORT 19132 +#define MCJE_PORT "25565" +#define MCBE_PORT "19132" #define MCJE_NAME "Minecraft Java Edition" #define MCBE_NAME "Minecraft Bedrock Edition" #define MCJE_SHORT_NAME "MCJE" @@ -19,9 +19,7 @@ #define DATA_FILE_PATH "mc_dissector" #define DATA_FILE_PATH_JE_DATA "mc_dissector/je" #define DATA_FILE_PATH_BE_DATA "mc_dissector/be" -#define DATA_FILE_PATH_PROTOCOL_VERSIONS "mc_dissector/protocol_versions.json" - -#define DEFINE_HF(name, desc, key, type, dis) {&name, {desc, key, FT_##type, BASE_##dis, NULL, 0x0, NULL, HFILL}}, +#define DATA_FILE_PATH_PROTOCOL_VERSIONS "protocol_versions.json" #if defined(DEBUG) #define WS_LOG(format, ...) ws_log("", LOG_LEVEL_CRITICAL, format, ##__VA_ARGS__) @@ -32,4 +30,12 @@ extern int proto_mcje; extern int proto_mcbe; +extern module_t *pref_mcje; +extern gchar *pref_ignore_packets_je; +extern gchar *pref_secret_key; +extern gboolean pref_do_nbt_decode; + +extern module_t *pref_mcbe; + + #endif //MC_DISSECTOR_MC_DISSECTOR_H diff --git a/protocol_be/be_dissect.c b/protocol_be/be_dissect.c index 2c33656..24decd3 100644 --- a/protocol_be/be_dissect.c +++ b/protocol_be/be_dissect.c @@ -18,7 +18,7 @@ void proto_reg_handoff_mcbe() { mcbe_boot_handle = create_dissector_handle(dissect_be_boot, proto_mcbe); mcbe_handle = create_dissector_handle(dissect_be_conv, proto_mcbe); ignore_be_handle = create_dissector_handle(dissect_be_ignore, proto_mcbe); - dissector_add_uint("udp.port", MCBE_PORT, mcbe_boot_handle); + dissector_add_uint_range_with_preference("udp.port", MCBE_PORT, mcbe_boot_handle); } int dissect_be_boot(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_) { diff --git a/protocol_je/je_dissect.c b/protocol_je/je_dissect.c index e1113ba..5e3cb12 100644 --- a/protocol_je/je_dissect.c +++ b/protocol_je/je_dissect.c @@ -17,7 +17,7 @@ dissector_handle_t mcje_handle; void proto_reg_handoff_mcje() { mcje_handle = create_dissector_handle(dissect_je_conv, proto_mcje); - dissector_add_uint_with_preference("tcp.port", MCJE_PORT, mcje_handle); + dissector_add_uint_range_with_preference("tcp.port", MCJE_PORT, mcje_handle); } void sub_dissect_je(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, mcje_protocol_context *ctx, bool is_server, bool visited) { diff --git a/protocol_je/je_dissect.h b/protocol_je/je_dissect.h index 7f4596c..685e053 100644 --- a/protocol_je/je_dissect.h +++ b/protocol_je/je_dissect.h @@ -9,9 +9,6 @@ #include "protocol/protocol_data.h" extern dissector_handle_t mcje_handle; -extern gchar *pref_ignore_packets_je; -extern gchar *pref_secret_key; -extern gboolean pref_do_nbt_decode; extern int ett_mcje; extern int ett_je_proto; diff --git a/protocol_je/je_registers.c b/protocol_je/je_registers.c index 4165d49..7abdc97 100644 --- a/protocol_je/je_registers.c +++ b/protocol_je/je_registers.c @@ -7,11 +7,6 @@ #include "strings_je.h" #include "je_protocol.h" -module_t *pref_mcje = NULL; -gchar *pref_ignore_packets_je = "c:map_chunk"; -gchar *pref_secret_key = ""; -gboolean pref_do_nbt_decode = false; - // ett int ett_mcje = -1; int ett_je_proto = -1; @@ -50,24 +45,11 @@ int hf_ping_time_je = -1; int hf_server_status_je = -1; int hf_legacy_slp_payload = -1; +#define DEFINE_HF(name, desc, key, type, dis) {&name, {desc, key, FT_##type, BASE_##dis, NULL, 0x0, NULL, HFILL}}, + void proto_register_mcje() { proto_mcje = proto_register_protocol(MCJE_NAME, MCJE_SHORT_NAME, MCJE_FILTER); - // Preference ------------------------------------------------------------------------------------------------------ - pref_mcje = prefs_register_protocol(proto_mcje, NULL); - prefs_register_string_preference( - pref_mcje, "ignore_packets", "Ignore Packets", - "Ignore packets with the given names", (const char **) &pref_ignore_packets_je - ); - prefs_register_string_preference( - pref_mcje, "secret_key", "Secret Key", - "Secret key for decryption", (const char **) &pref_secret_key - ); - prefs_register_bool_preference( - pref_mcje, "do_nbt_decode", "NBT Decoding", - "Decode NBT data", &pref_do_nbt_decode - ); - register_string_je(); static hf_register_info hf_je[] = {