Skip to content

Commit

Permalink
Put all protocol data outside the library
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Jul 17, 2024
1 parent 796b837 commit dcb609c
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 295 deletions.
7 changes: 2 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ body:
label: Minecraft Dissector Version
description: What version of the Minecraft dissector are you using?
options:
- 1.0.0-beta.1
- 1.0.0-beta.2
- 1.0.0-beta.3
- 1.0.0-beta.4
- 1.0.0-beta.5
- 1.0.0
- 1.1.0
- type: input
id: os
attributes:
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ endmacro(invoke_py)
invoke_py("Generate Java String Data"
"${PROJECT_SOURCE_DIR}/codegen_script/string_gen.py" "${PROJECT_SOURCE_DIR}/strings/strings_je.json"
"${GEN_RESOURCE_DIR}/strings_je.c" "${GEN_RESOURCE_DIR}/strings_je.h" "je")
invoke_py("Generate Protocol Data"
"${PROJECT_SOURCE_DIR}/codegen_script/protocol_data_gen.py" "${PROJECT_SOURCE_DIR}/minecraft-data" "${GEN_RESOURCE_DIR}")
invoke_py("Generate Entity ID Data"
"${PROJECT_SOURCE_DIR}/codegen_script/entity_id_gen.py" "${PROJECT_SOURCE_DIR}/minecraft-data/java"
"${CMAKE_CURRENT_BINARY_DIR}/preprocess_resources")
Expand Down
75 changes: 0 additions & 75 deletions codegen_script/protocol_data_gen.py

This file was deleted.

9 changes: 6 additions & 3 deletions mc_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by Nickid2018 on 2023/7/12.
//
#include <ws_version.h>
#include <wsutil/filesystem.h>

#include "mc_dissector.h"
#include "protocol/protocol_data.h"
Expand All @@ -19,7 +20,7 @@ int proto_mcje = -1;
int proto_mcbe = -1;

module_t *pref_mc = NULL;
gchar *pref_protocol_data_dir = DATA_FILE_PATH;
gchar *pref_protocol_data_dir;
module_t *pref_mcje = NULL;
gchar *pref_ignore_packets_je = "c:map_chunk";
gchar *pref_secret_key = "";
Expand All @@ -31,12 +32,14 @@ void proto_register() {
proto_register_mcje();
proto_register_mcbe();

pref_protocol_data_dir = get_datafile_path("minecraft-protocol");

// Preference ------------------------------------------------------------------------------------------------------
proto_mc = proto_register_protocol("Minecraft", "Minecraft", "Minecraft");
pref_mc = prefs_register_protocol(proto_mc, NULL);
prefs_register_filename_preference(
prefs_register_directory_preference(
pref_mc, "protocol_data_dir", "Protocol Data Directory",
"Directory for protocol data", (const char **) &pref_protocol_data_dir, false
"Directory for protocol data", (const char **) &pref_protocol_data_dir
);
pref_mcje = prefs_register_protocol_subtree("Minecraft", proto_mcje, NULL);
prefs_register_string_preference(
Expand Down
2 changes: 1 addition & 1 deletion minecraft-data
7 changes: 1 addition & 6 deletions protocol/protocol_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <epan/proto.h>
#include <gcrypt.h>
#include "protocol/schema/protocols.h"
#include "storage/storage.h"

#define INVALID_DATA (-1)
#define is_invalid(x) ((x) == INVALID_DATA)
Expand Down Expand Up @@ -50,11 +50,6 @@ typedef struct {
gint32 compression_threshold;
} mcje_frame_data;

typedef struct {
gint record_total;
gint record_latest;
} reassemble_offset;

extern char *STATE_NAME[];

gint read_var_int(tvbuff_t *tvb, gint offset, gint *result);
Expand Down
26 changes: 13 additions & 13 deletions protocol/schema/protocol_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ FIELD_MAKE_TREE(container) {
gint total_length = 0;
for (guint i = 1; i <= length; i++) {
protocol_field sub_field = wmem_map_lookup(field->additional_info, GUINT_TO_POINTER(i));
if (strcmp(sub_field->name, "[unnamed]") == 0 && not_top) {
if (g_strcmp0(sub_field->name, "[unnamed]") == 0 && not_top) {
record_pop(recorder);
record_start(recorder, now_record);
sub_field->make_tree(NULL, pinfo, tvb, extra, sub_field, offset, remaining, recorder, is_je);
Expand Down Expand Up @@ -573,7 +573,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
field->additional_info = NULL;
field->make_tree = make_tree_func;

if (settings.nbt_any_type && strcmp(type, "nbt") == 0)
if (settings.nbt_any_type && g_strcmp0(type, "nbt") == 0)
field->make_tree = make_tree_nbt_any_type;

return field;
Expand All @@ -596,14 +596,14 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
field->make_tree = NULL;
field->name = "[unnamed]";

if (strcmp(type, "function") == 0) {
if (g_strcmp0(type, "function") == 0) {
#ifdef MC_DISSECTOR_FUNCTION_FEATURE
field->make_tree = wmem_map_lookup(function_make_tree, fields->valuestring);
#else
field->make_tree = make_tree_void;
#endif // MC_DISSECTOR_FUNCTION_FEATURE
return field;
} else if (strcmp(type, "container") == 0) { // container
} else if (g_strcmp0(type, "container") == 0) { // container
field->make_tree = make_tree_container;
int size = cJSON_GetArraySize(fields);
wmem_map_insert(field->additional_info, 0, GINT_TO_POINTER(size));
Expand All @@ -622,7 +622,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
if (on_top)
wmem_map_insert(field->additional_info, GINT_TO_POINTER(-1), GINT_TO_POINTER(1));
return field;
} else if (strcmp(type, "option") == 0) { // option
} else if (g_strcmp0(type, "option") == 0) { // option
field->make_tree = make_tree_option;
protocol_field sub_field = parse_protocol(
basic_types, fields, types, is_je, false, settings
Expand All @@ -631,15 +631,15 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
return NULL;
wmem_map_insert(field->additional_info, 0, sub_field);
return field;
} else if (strcmp(type, "buffer") == 0) { // buffer
} else if (g_strcmp0(type, "buffer") == 0) { // buffer
if (cJSON_HasObjectItem(fields, "count")) {
field->make_tree = make_tree_buffer;
cJSON *count = cJSON_GetObjectItem(fields, "count");
wmem_map_insert(field->additional_info, 0, GINT_TO_POINTER(count->valueint));
} else
field->make_tree = make_tree_var_buffer;
return field;
} else if (strcmp(type, "mapper") == 0) { // mapper
} else if (g_strcmp0(type, "mapper") == 0) { // mapper
field->additional_info = wmem_map_new(wmem_epan_scope(), g_str_hash, g_str_equal);
cJSON *type_data = cJSON_GetObjectItem(fields, "type");
protocol_field sub_field = parse_protocol(
Expand All @@ -658,7 +658,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
now = now->next;
}
return field;
} else if (strcmp(type, "array") == 0) { // array
} else if (g_strcmp0(type, "array") == 0) { // array
cJSON *count = cJSON_GetObjectItem(fields, "count");
if (count != NULL)
wmem_map_insert(
Expand All @@ -667,7 +667,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
);
else {
cJSON *count_type = cJSON_GetObjectItem(fields, "countType");
if (count_type == NULL || strcmp(count_type->valuestring, "varint") != 0)
if (count_type == NULL || g_strcmp0(count_type->valuestring, "varint") != 0)
return NULL;
}

Expand All @@ -680,7 +680,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
field->make_tree = make_tree_array;
wmem_map_insert(field->additional_info, GINT_TO_POINTER(1), sub_field);
return field;
} else if (strcmp(type, "bitfield") == 0) {
} else if (g_strcmp0(type, "bitfield") == 0) {
int size = cJSON_GetArraySize(fields);
wmem_map_insert(field->additional_info, GINT_TO_POINTER(-1), GINT_TO_POINTER(size));
int total_bits = 0;
Expand All @@ -696,7 +696,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
}
field->make_tree = make_tree_bitfield;
return field;
} else if (strcmp(type, "topBitSetTerminatedArray") == 0) {
} else if (g_strcmp0(type, "topBitSetTerminatedArray") == 0) {
protocol_field sub_field = parse_protocol(
basic_types, cJSON_GetObjectItem(fields, "type"), types, is_je, false, settings
);
Expand All @@ -705,7 +705,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
wmem_map_insert(field->additional_info, 0, sub_field);
field->make_tree = make_tree_top_bit_set_terminated_array;
return field;
} else if (strcmp(type, "switch") == 0) {
} else if (g_strcmp0(type, "switch") == 0) {
char *compare_data = cJSON_GetObjectItem(fields, "compareTo")->valuestring;
char **compare_data_split = g_strsplit(strdup(compare_data), "/", 10);
field->additional_info = wmem_map_new(wmem_epan_scope(), g_str_hash, g_str_equal);
Expand Down Expand Up @@ -735,7 +735,7 @@ protocol_field parse_protocol(wmem_map_t *basic_types, cJSON *data, cJSON *types
}
field->make_tree = make_tree_switch;
return field;
} else if (strcmp(type, "entityMetadataLoop") == 0) {
} else if (g_strcmp0(type, "entityMetadataLoop") == 0) {
protocol_field sub_field = parse_protocol(
basic_types, cJSON_GetObjectItem(fields, "type"), types, is_je, false, settings
);
Expand Down
Loading

0 comments on commit dcb609c

Please sign in to comment.