Skip to content

Commit

Permalink
update pref definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Jun 24, 2024
1 parent 52b49fc commit 62c6b18
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
24 changes: 24 additions & 0 deletions mc_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 12 additions & 6 deletions mc_dissector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef MC_DISSECTOR_MC_DISSECTOR_H
#define MC_DISSECTOR_MC_DISSECTOR_H

#include <epan/tfs.h>
#include <epan/prefs.h>

#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"
Expand All @@ -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__)
Expand All @@ -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
2 changes: 1 addition & 1 deletion protocol_be/be_dissect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
2 changes: 1 addition & 1 deletion protocol_je/je_dissect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions protocol_je/je_dissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 2 additions & 20 deletions protocol_je/je_registers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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[] = {
Expand Down

0 comments on commit 62c6b18

Please sign in to comment.