-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprotocol_tree.c
352 lines (338 loc) · 8.25 KB
/
protocol_tree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include "protocol_constants.h"
#include "protocol_tree.h"
#include "protocol_tree_internal.h"
#include "protocol.h"
#include <epan/packet.h>
int
ett_strlen=-1,
ett_metadata=-1;
int
hf_string_length=-1,
hf_player_name=-1,
hf_uuid=-1,
hf_compression_trxld=-1,
hf_protocol_version=-1,
hf_hs_next_state=-1,
hf_server_address=-1,
hf_entity_id=-1,
hf_difficulty=-1,
hf_resourcepack_state=-1,
hf_channel_name=-1,
hf_chunk_x=-1,
hf_chunk_z=-1,
hf_pos_x=-1,
hf_pos_y=-1,
hf_pos_z=-1,
hf_metadata=-1,
hf_metadata_index=-1,
hf_metadata_type=-1,
hf_size=-1,
hf_primary_bit_mask=-1,
hf_bits_per_block=-1,
hf_section_number=-1,
hf_palette=-1,
hf_palette_length=-1;
void tree_register_fields(void) {
static gint *ett[] = { &ett_strlen, &ett_metadata };
static hf_register_info hf[] = {
{ &hf_string_length,
{
"String length", "mcpc.string.length",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_uuid,
{
"UUID", "mcpc.player.uuid",
FT_STRING, STR_ASCII,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_player_name,
{
"Player name", "mcpc.player.name",
FT_STRING, STR_ASCII,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_compression_trxld,
{
"Compression treshold", "mcpc.trxld",
FT_INT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_protocol_version,
{
"Protocol version", "mcpc.protocol.version",
FT_UINT16, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_hs_next_state,
{
"Next state", "mcpc.handshake.nextstate",
FT_UINT16, BASE_DEC,
VALS(states), 0x0,
NULL, HFILL
}
},
{ &hf_server_address,
{
"Server address", "mcpc.address",
FT_STRING, STR_ASCII,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_entity_id,
{
"Entity ID", "mcpc.entity.id",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_difficulty,
{
"Difficulty", "mcpc.difficulty",
FT_UINT8, BASE_DEC,
VALS(difficulty_levels), 0x0,
NULL, HFILL
}
},
{ &hf_resourcepack_state,
{
"Resource Pack Status", "mcpc.resourcepack.status",
FT_UINT8, BASE_DEC,
VALS(resourcepack_status), 0x0,
NULL, HFILL
}
},
{ &hf_channel_name,
{
"Channel name", "mcpc.channel",
FT_STRING, STR_ASCII,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_chunk_x,
{
"Chunk X", "mcpc.chunk.x",
FT_INT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_chunk_z,
{
"Chunk Z", "mcpc.chunk.z",
FT_INT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_pos_x,
{
"X coordinate", "mcpc.coord.x",
FT_DOUBLE, BASE_NONE,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_pos_y,
{
"Y coordinate", "mcpc.coord.y",
FT_DOUBLE, BASE_NONE,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_pos_z,
{
"Z coordinate", "mcpc.coord.z",
FT_DOUBLE, BASE_NONE,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_metadata,
{
"Metadata", "mcpc.metadata",
FT_NONE, BASE_NONE,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_metadata_index,
{
"Metadata index", "mcpc.metadata.index",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_metadata_type,
{
"Metadata type", "mcpc.metadata.type",
FT_UINT32, BASE_DEC,
VALS(metadata_types), 0x0,
NULL, HFILL
}
},
{ &hf_size,
{
"Size", "mcpc.size",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_primary_bit_mask,
{
"Primary Bit Mask", "mcpc.chunk.pbm",
FT_UINT32, BASE_HEX,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_bits_per_block,
{
"Bits Per Block", "mcpc.section.bpb",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_section_number,
{
"Section Y", "mcpc.section.y",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_palette,
{
"Palette", "mcpc.section.palette",
FT_NONE, BASE_NONE,
NULL, 0x0,
NULL, HFILL
}
},
{ &hf_palette_length,
{
"Palette", "mcpc.section.palette.length",
FT_UINT32, BASE_DEC,
NULL, 0x0,
NULL, HFILL
}
}
};
proto_register_field_array(proto_mcpc, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
void tree_server_slp(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const void *data, guint length){
uint32_t varint;
int8_t varlen;
varlen=VarIntToUint(data, &varint, length);//PacketID
if(varlen>0){
proto_item_append_text(proto_tree_get_parent(proto_tree_get_parent_tree(packet_tree)), ", PID: 0x%X", varint);
proto_tree_add_uint(packet_tree, hf_protocol_packetid_sb_slp, tvb, 0, varlen, varint);
}
}
void tree_client_slp(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const void *data, guint length){
guint readed;
uint32_t varint;
int8_t varlen;
readed=varlen=VarIntToUint(data, &varint, length);//PacketID
if(varlen>0){
proto_item_append_text(proto_tree_get_parent(proto_tree_get_parent_tree(packet_tree)), ", PID: 0x%X", varint);
proto_tree_add_uint(packet_tree, hf_protocol_packetid_cb_slp, tvb, 0, varlen, varint);
switch(varint){
case 0x00:
varlen=VarIntToUint(data+readed, &varint, length-readed);//String length
proto_tree_add_uint(packet_tree, hf_string_length, tvb, readed, varlen, varint);
readed+=varlen;
proto_item_set_text(
proto_tree_add_item(packet_tree, hf_server_address, tvb, readed, varint, FALSE),
"Response: %.*s:%hu", varint, (const char*)data+readed, g_ntohs(*(const uint16_t*)(data+readed)));
readed+=varint;
break;
}
}
}
void tree_server_login(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const void *data, guint length){
guint readed;
uint32_t varint;
int8_t varlen;
readed=varlen=VarIntToUint(data, &varint, length);//PacketID
if(varlen>0){
proto_item_append_text(proto_tree_get_parent(proto_tree_get_parent_tree(packet_tree)), ", PID: 0x%X", varint);
proto_tree_add_uint(packet_tree, hf_protocol_packetid_sb_login, tvb, 0, varlen, varint);
switch(varint){
case PID_SB_LOGIN_START:
STR_TO_TREE(packet_tree, hf_player_name);
break;
}
}
}
void tree_client_login(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const void *data, guint length){
guint readed;
uint32_t varint;
int8_t varlen;
readed=varlen=VarIntToUint(data, &varint, length);//PacketID
if(varlen>0){
proto_item_append_text(proto_tree_get_parent(proto_tree_get_parent_tree(packet_tree)), ", PID: 0x%X", varint);
proto_tree_add_uint(packet_tree, hf_protocol_packetid_cb_login, tvb, 0, varlen, varint);
switch(varint){
case PID_CB_LOGIN_SUCCESS:
varlen=VarIntToUint(data+readed, &varint, length);//String length
STR_TO_TREE(packet_tree, hf_uuid);
STR_TO_TREE(packet_tree, hf_player_name);
break;
case PID_CB_LOGIN_SET_COMPRESSION:
varlen=VarIntToUint(data+readed, &varint, length);//Threshold
proto_tree_add_int(packet_tree, hf_compression_trxld, tvb, readed, varlen, (int32_t)varint);
break;
}
}
}
void tree_server_handshake(proto_tree *packet_tree, tvbuff_t *tvb, packet_info *pinfo _U_, const void *data, guint length){
guint readed;
uint32_t varint;
int8_t varlen;
readed=varlen=VarIntToUint(data, &varint, length);//PacketID
if(varlen>0){
proto_item_append_text(proto_tree_get_parent(proto_tree_get_parent_tree(packet_tree)), ", PID: 0x%X", varint);
proto_tree_add_uint(packet_tree, hf_protocol_packetid_sb_hs, tvb, 0, varlen, varint);
switch(varint){
case 0x00:
varlen=VarIntToUint(data+readed, &varint, length-readed);//Protocol version
proto_tree_add_uint(packet_tree, hf_protocol_version, tvb, readed, varlen, varint);
readed+=varlen;
varlen=VarIntToUint(data+readed, &varint, length-readed);//String length
proto_tree_add_uint(packet_tree, hf_string_length, tvb, readed, varlen, varint);
readed+=varlen;
gchar *addr=wmem_alloc(pinfo->pool, varint+1);
memcpy(addr, data+readed, varint);
addr[varint]=0x00;
readed+=varint;
proto_item_set_text(
proto_tree_add_item(packet_tree, hf_server_address, tvb, readed-varint, varint+2, FALSE),
"Address: %s:%hu", addr, be16toh(*(const uint16_t*)(data+readed)));
readed+=2;//Skip short
varlen=VarIntToUint(data+readed, &varint, length-readed);//Next State
proto_tree_add_uint(packet_tree, hf_hs_next_state, tvb, readed, varlen, varint);
break;
}
}
return;
}