Skip to content

Commit

Permalink
fix 23w31a
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed Aug 6, 2023
1 parent 64e8bc6 commit b7ca51d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 47 deletions.
9 changes: 6 additions & 3 deletions protocol_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#define INVALID_DATA (-1)
#define is_invalid(x) ((x) == INVALID_DATA)

typedef enum {
HANDSHAKE, PLAY, PING, LOGIN, CONFIGURATION, INVALID
} je_state;

typedef struct {
enum {
HANDSHAKE, PLAY, PING, LOGIN, CONFIGURATION, INVALID
} state;
je_state client_state;
je_state server_state;
guint32 server_port;
guint32 protocol_version;
guint32 data_version;
Expand Down
30 changes: 15 additions & 15 deletions protocol_je/je_dissect.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ guint get_packet_length_je(packet_info *pinfo, tvbuff_t *tvb, int offset, void *
col_append_str(pinfo->cinfo, COL_INFO, "[Invalid] Failed to parse payload length");
conversation_t *conv = find_or_create_conversation(pinfo);
mcje_protocol_context *ctx = conversation_get_proto_data(conv, proto_mcje);
ctx->state = INVALID;
ctx->client_state = INVALID;
conversation_set_dissector(conv, ignore_je_handle);
return 0;
} else
Expand All @@ -40,10 +40,10 @@ guint get_packet_length_je(packet_info *pinfo, tvbuff_t *tvb, int offset, void *

void sub_dissect_je(guint length, tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree, mcje_protocol_context *ctx,
bool is_client, bool visited) {
bool is_server, bool visited) {
const guint8 *data = tvb_get_ptr(tvb, pinfo->desegment_offset, length);
if (is_client) {
switch (ctx->state) {
if (is_server) {
switch (ctx->server_state) {
case HANDSHAKE:
if (!visited && is_invalid(handle_server_handshake_switch(data, length, ctx)))
return;
Expand Down Expand Up @@ -77,7 +77,7 @@ void sub_dissect_je(guint length, tvbuff_t *tvb, packet_info *pinfo,
return;
}
} else {
switch (ctx->state) {
switch (ctx->client_state) {
case PING:
if (tree)
handle_client_slp(tree, tvb, pinfo, data, length, ctx);
Expand Down Expand Up @@ -123,8 +123,8 @@ int dissect_je_core(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
p_add_proto_data(wmem_file_scope(), pinfo, proto_mcje, pinfo->fd->subnum, save);
}

bool is_client = pinfo->destport == ctx->server_port;
if (is_client)
bool is_server = pinfo->destport == ctx->server_port;
if (is_server)
col_set_str(pinfo->cinfo, COL_INFO, "[C => S]");
else
col_set_str(pinfo->cinfo, COL_INFO, "[S => C]");
Expand All @@ -142,7 +142,7 @@ int dissect_je_core(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
proto_item *ti = proto_tree_add_item(tree, proto_mcje, tvb, 0, -1, FALSE);
mcje_tree = proto_item_add_subtree(ti, ett_mcje);
proto_tree_add_uint(mcje_tree, hf_packet_length_je, tvb, 0, packet_length_length, packet_length_vari);
proto_item_append_text(ti, ", State: %s", STATE_NAME[ctx->state]);
proto_item_append_text(ti, ", Client State: %s, Server State: %s", STATE_NAME[ctx->client_state], STATE_NAME[ctx->server_state]);
}

tvbuff_t *new_tvb;
Expand All @@ -152,16 +152,16 @@ int dissect_je_core(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
proto_item *packet_item = proto_tree_add_item(mcje_tree, proto_mcje, new_tvb, 0, -1, FALSE);
proto_item_set_text(packet_item, "Minecraft JE Packet");
proto_tree *sub_mcpc_tree = proto_item_add_subtree(packet_item, ett_je_proto);
sub_dissect_je(packet_length_vari, new_tvb, pinfo, sub_mcpc_tree, ctx, is_client, pinfo->fd->visited);
sub_dissect_je(packet_length_vari, new_tvb, pinfo, sub_mcpc_tree, ctx, is_server, pinfo->fd->visited);
} else
sub_dissect_je(packet_length_vari, new_tvb, pinfo, NULL, ctx, is_client, pinfo->fd->visited);
sub_dissect_je(packet_length_vari, new_tvb, pinfo, NULL, ctx, is_server, pinfo->fd->visited);
} else {
guint uncompressed_length;
int var_len = read_var_int(dt + packet_length_length, packet_length - read_pointer, &uncompressed_length);
if (is_invalid(var_len)) {
proto_tree_add_string(mcje_tree, hf_invalid_data_je, tvb,
read_pointer, var_len, "Invalid Compression VarInt");
ctx->state = INVALID;
ctx->client_state = INVALID;
return tvb_captured_length(tvb);
}

Expand Down Expand Up @@ -192,10 +192,10 @@ int dissect_je_core(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *d
proto_item *packet_item = proto_tree_add_item(mcje_tree, proto_mcje, new_tvb, 0, -1, FALSE);
proto_item_set_text(packet_item, "Minecraft JE Packet");
proto_tree *sub_mcpc_tree = proto_item_add_subtree(packet_item, ett_je_proto);
sub_dissect_je(tvb_captured_length(new_tvb), new_tvb, pinfo, sub_mcpc_tree, ctx, is_client,
sub_dissect_je(tvb_captured_length(new_tvb), new_tvb, pinfo, sub_mcpc_tree, ctx, is_server,
pinfo->fd->visited);
} else
sub_dissect_je(tvb_captured_length(new_tvb), new_tvb, pinfo, NULL, ctx, is_client,
sub_dissect_je(tvb_captured_length(new_tvb), new_tvb, pinfo, NULL, ctx, is_server,
pinfo->fd->visited);
}

Expand All @@ -208,7 +208,7 @@ int dissect_je_boot(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, voi
if (!ctx) {
ctx = wmem_alloc(wmem_file_scope(), sizeof(mcje_protocol_context));
ctx->server_port = pinfo->destport;
ctx->state = HANDSHAKE;
ctx->client_state = HANDSHAKE;
ctx->compression_threshold = -1;
conversation_add_proto_data(conv, proto_mcje, ctx);
conversation_set_dissector(conv, mcje_handle);
Expand All @@ -232,7 +232,7 @@ int dissect_je_ignore(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, v
if (!(ctx = p_get_proto_data(wmem_file_scope(), pinfo, proto_mcje, pinfo->fd->subnum)))
ctx = conversation_get_proto_data(conv, proto_mcje);

if (ctx->state == INVALID) {
if (ctx->client_state == INVALID) {
col_add_str(pinfo->cinfo, COL_INFO, "[Invalid] Data may be corrupted or meet a capturing failure.");
} else
tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 0,
Expand Down
44 changes: 19 additions & 25 deletions protocol_je/je_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int handle_server_handshake_switch(const guint8 *data, guint length, mcje_protoc
return INVALID_DATA;
guint nearest_data_version = find_nearest_java_protocol(ctx->data_version);
gchar *nearest_java_version = get_java_version_name_by_data_version(nearest_data_version);
ctx->state = next_state + 1;
ctx->client_state = ctx->server_state = next_state + 1;
ctx->protocol_set = get_protocol_je_set(nearest_java_version);
ctx->protocol_version = protocol_version;
return 0;
Expand Down Expand Up @@ -88,15 +88,6 @@ void handle_server_handshake(proto_tree *packet_tree, tvbuff_t *tvb, packet_info
return;
}
proto_tree_add_string(packet_tree, hf_next_state_je, tvb, p, read, STATE_NAME[next_state + 1]);

gchar *unchecked_java_version = get_java_version_name_unchecked(protocol_version);
ctx->data_version = get_java_data_version(unchecked_java_version);
guint nearest_data_version = find_nearest_java_protocol(ctx->data_version);
gchar *nearest_java_version = get_java_version_name_by_data_version(nearest_data_version);
gchar *test = "";
for (int i = 0; i < data_version_list_je->len; i++)
test = g_strconcat(test, g_strdup_printf("%d ", g_array_index(data_version_list_je, gint, i)), NULL);
proto_tree_add_string(packet_tree, hf_invalid_data_je, tvb, p, read, g_strdup_printf("%d(%d) [%s]", ctx->data_version, get_java_data_version("23w31a"), test));
} else if (packet_id == PACKET_ID_LEGACY_SERVER_LIST_PING) {
proto_tree_add_string_format_value(packet_tree, hf_packet_name_je, tvb, 0, read,
"legacy_server_list_ping", "Legacy Server List Ping");
Expand Down Expand Up @@ -167,7 +158,7 @@ void handle_client_slp(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinf

int handle_client_login_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
Expand All @@ -176,7 +167,10 @@ int handle_client_login_switch(const guint8 *data, guint length, mcje_protocol_c
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == PACKET_ID_CLIENT_SUCCESS)
ctx->state = ctx->data_version >= 3567 ? CONFIGURATION : PLAY;
if (ctx->data_version >= 3567)
ctx->client_state = CONFIGURATION;
else
ctx->client_state = ctx->server_state = PLAY;
if (packet_id == PACKET_ID_CLIENT_COMPRESS) {
guint threshold;
read = read_var_int(data + p, length - p, &threshold);
Expand All @@ -189,15 +183,15 @@ int handle_client_login_switch(const guint8 *data, guint length, mcje_protocol_c

int handle_server_login_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
guint p = read_var_int(data, length, &packet_id);
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == get_packet_id(ctx->protocol_set->login, "login_acknowledgement", false))
ctx->state = CONFIGURATION;
ctx->server_state = CONFIGURATION;
return 0;
}

Expand Down Expand Up @@ -246,83 +240,83 @@ void handle_login(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_
guint length, 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->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return;
}
handle(packet_tree, tvb, pinfo, data, length, ctx, ctx->protocol_set->login, is_client);
}

int handle_client_play_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
guint p = read_var_int(data, length, &packet_id);
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == get_packet_id(ctx->protocol_set->play, "start_configuration", true))
ctx->state = CONFIGURATION;
ctx->client_state = CONFIGURATION;
return 0;
}

int handle_server_play_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
guint p = read_var_int(data, length, &packet_id);
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == get_packet_id(ctx->protocol_set->play, "configuration_acknowledgement", false))
ctx->state = CONFIGURATION;
ctx->server_state = CONFIGURATION;
return 0;
}

void handle_play(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const guint8 *data,
guint length, 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->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return;
}
handle(packet_tree, tvb, pinfo, data, length, ctx, ctx->protocol_set->play, is_client);
}

int handle_client_configuration_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
guint p = read_var_int(data, length, &packet_id);
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == get_packet_id(ctx->protocol_set->configuration, "finish_configuration", true))
ctx->state = PLAY;
ctx->client_state = PLAY;
return 0;
}

int handle_server_configuration_switch(const guint8 *data, guint length, mcje_protocol_context *ctx) {
if (ctx->protocol_set == NULL) {
ctx->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return -1;
}
guint packet_id;
guint p = read_var_int(data, length, &packet_id);
if (is_invalid(p))
return INVALID_DATA;
if (packet_id == get_packet_id(ctx->protocol_set->configuration, "finish_configuration", false))
ctx->state = PLAY;
ctx->server_state = PLAY;
return 0;
}

void handle_configuration(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const guint8 *data,
guint length, 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->state = INVALID;
ctx->client_state = ctx->server_state = INVALID;
return;
}
handle(packet_tree, tvb, pinfo, data, length, ctx, ctx->protocol_set->configuration, is_client);
Expand Down
12 changes: 11 additions & 1 deletion protocol_je/je_protocol_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ void init_je_constants() {
// Login
DEFINE_NAME_CLIENT(disconnect, Client Login Disconnect)
DEFINE_NAME_CLIENT(encryption_begin, Client Hello)
DEFINE_NAME_CLIENT(success, Client Game Profile)
DEFINE_NAME_CLIENT(success, Client Login Success)
DEFINE_NAME_CLIENT(compress, Client Compression)
DEFINE_NAME_CLIENT(login_plugin_request, Client Custom Query)
DEFINE_NAME_SERVER(login_start, Server Hello)
DEFINE_NAME_SERVER(encryption_begin, Server Key)
DEFINE_NAME_SERVER(login_plugin_response, Server Custom Query)
DEFINE_NAME_SERVER(login_acknowledgement, Server Login Success ACK)
// Play
DEFINE_NAME_CLIENT(bundle_delimiter, Client Bundle Delimter)
DEFINE_NAME_CLIENT(spawn_entity, Client Add Entity)
Expand Down Expand Up @@ -135,6 +136,9 @@ void init_je_constants() {
DEFINE_NAME_CLIENT(entity_effect, Client Update Mob Effect)
DEFINE_NAME_CLIENT(declare_recipes, Client Update Recipes)
DEFINE_NAME_CLIENT(tags, Client Update Tags)
DEFINE_NAME_CLIENT(chunk_batch_finished, Client Chunk Batch Finished)
DEFINE_NAME_CLIENT(chunk_batch_start, Client Chunk Batch Start)
DEFINE_NAME_CLIENT(start_configuration, Client Start Configuration)
DEFINE_NAME_SERVER(teleport_confirm, Server Accept Teleportation)
DEFINE_NAME_SERVER(query_block_nbt, Server Block Entity Tag Query)
DEFINE_NAME_SERVER(set_difficulty, Server Change Difficulty)
Expand Down Expand Up @@ -186,4 +190,10 @@ void init_je_constants() {
DEFINE_NAME_SERVER(spectate, Server Teleport To Entity)
DEFINE_NAME_SERVER(block_place, Server Use Item on)
DEFINE_NAME_SERVER(use_item, Server Use Item)
DEFINE_NAME_SERVER(chunk_batch_received, Server Chunk Batch Received)
DEFINE_NAME_SERVER(configuration_acknowledgement, Server Configuration ACK)
// Configuration
DEFINE_NAME_CLIENT(finish_configuration, Client Finish Configuration)
DEFINE_NAME_CLIENT(registry_data, Client Registry Data)
DEFINE_NAME_SERVER(finish_configuration, Server Finish Configuration)
}
35 changes: 32 additions & 3 deletions strings/strings_je.json
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,10 @@
},
"position": {
"name": "Position",
"type": "i8"
"type": [
"i8",
"u32"
]
},
"vehicle_id": {
"name": "Vechicle ID",
Expand Down Expand Up @@ -1646,6 +1649,18 @@
"name": "Has Background Texture",
"type": "bool",
"bitmask": "01"
},
"batch_size": {
"name": "Batch Size",
"type": "u32"
},
"desired_batch_size": {
"name": "Desired Batch Size",
"type": "f32"
},
"registry_data": {
"name": "Registry Data",
"type": "bytes"
}
},
"mappings": {
Expand Down Expand Up @@ -2327,7 +2342,19 @@
"chat_session_update/publicKey": "public_key",
"chat_session_update/signature": "signature",
"end_combat_event/entityId": "killer_id",
"death_combat_event/entityId": "killer_id"
"death_combat_event/entityId": "killer_id",
"common_player_spawn_info/worldType": "world_type",
"common_player_spawn_info/worldName": "world_name",
"common_player_spawn_info/hashedSeed": "hashed_seed",
"common_player_spawn_info/gameMode": "gamemode",
"common_player_spawn_info/previousGameMode": "previous_gamemode",
"common_player_spawn_info/isDebug": "is_debug",
"common_player_spawn_info/isFlat": "is_flat",
"common_player_spawn_info/death/dimensionName": "dimension_name",
"common_player_spawn_info/portalCooldown": "portal_cooldown",
"chunk_batch_finished/batchSize": "batch_size",
"chunk_batch_received/desiredBatchSize": "desired_batch_size",
"registry_data/registryData": "registry_data"
},
"bitmask_collection": {
"[26]x[26]z[12]y": [
Expand Down Expand Up @@ -2474,6 +2501,8 @@
"window_click/changedSlots": "Changed Slots",
"window_click/changedSlots/item/slot": "Item",
"window_click/cursorItem/slot": "Cursor Item",
"set_creative_slot/item/slot": "Item"
"set_creative_slot/item/slot": "Item",
"login/playerSpawnInfo/common_player_spawn_info": "Common Player Spawn Info",
"respawn/playerSpawnInfo/common_player_spawn_info": "Common Player Spawn Info"
}
}

0 comments on commit b7ca51d

Please sign in to comment.