简体   繁体   English

Java / Minecraft - 如何阅读/理解数据包

[英]Java/Minecraft - How to read/understand packets

I have written a Packet Sniffer in Java and it works perfect but now I have a text file with integers and I dont know how to decode them. 我用Java编写了一个数据包嗅探器,它工作得很完美,但现在我有一个带整数的文本文件,我不知道如何解码它们。 I already tried to use this : Minecraft Protocol , but I still can't decode the packets... 我已经尝试过使用这个: Minecraft协议 ,但我还是无法解码数据包......

Output: 输出:

[Client] 15
[Client] 0
[Client] 47
[Client] 9
[Client] 108
[Client] 111
[Client] 99
[Client] 97
[Client] 108
[Client] 104
[Client] 111
[Client] 115
[Client] 116
[Client] 30
[Client] 97
[Client] 1
[Client] 1
[Client] 0


[Server] 118
[Server] 0
[Server] 116
[Server] 123
[Server] 34
[Server] 100
[Server] 101
[Server] 115
[Server] 99
[Server] 114
[Server] 105
[Server] 112
[Server] 116
[Server] 105
[Server] 111
[Server] 110
[Server] 34
[Server] 58
[Server] 34
[Server] 65
[Server] 32
[Server] 77
[Server] 105
[Server] 110
[Server] 101
[Server] 99
[Server] 114
[Server] 97
[Server] 102
[Server] 116
[Server] 32
[Server] 83
[Server] 101
[Server] 114
[Server] 118
[Server] 101
[Server] 114
[Server] 34
[Server] 44
[Server] 34
[Server] 112
[Server] 108
[Server] 97
[Server] 121
[Server] 101
[Server] 114
[Server] 115
[Server] 34
[Server] 58
[Server] 123
[Server] 34
[Server] 109
[Server] 97
[Server] 120
[Server] 34
[Server] 58
[Server] 50
[Server] 48
[Server] 44
[Server] 34
[Server] 111
[Server] 110
[Server] 108
[Server] 105
[Server] 110
[Server] 101
[Server] 34
[Server] 58
[Server] 48
[Server] 125
[Server] 44
[Server] 34
[Server] 118
[Server] 101
[Server] 114
[Server] 115
[Server] 105
[Server] 111
[Server] 110
[Server] 34
[Server] 58
[Server] 123
[Server] 34
[Server] 110
[Server] 97
[Server] 109
[Server] 101
[Server] 34
[Server] 58
[Server] 34
[Server] 83
[Server] 112
[Server] 105
[Server] 103
[Server] 111
[Server] 116
[Server] 32
[Server] 49
[Server] 46
[Server] 56
[Server] 46
[Server] 55
[Server] 34
[Server] 44
[Server] 34
[Server] 112
[Server] 114
[Server] 111
[Server] 116
[Server] 111
[Server] 99
[Server] 111
[Server] 108
[Server] 34
[Server] 58
[Server] 52
[Server] 55
[Server] 125
[Server] 125


[Client] 9
[Client] 1
[Client] 0
[Client] 0
[Client] 0
[Client] 0
[Client] 10
[Client] 158
[Client] 220
[Client] 203


[Server] 9
[Server] 1
[Server] 0
[Server] 0
[Server] 0
[Server] 0
[Server] 10
[Server] 158
[Server] 220
[Server] 203
[Server] -1


[Client] -1

I would really appreciate it if someone has an answer. 如果有人有答案我真的很感激。

It seems that no integer is higher than 255, so this is a single byte per line output. 似乎没有整数高于255,所以这是每行输出一个字节。 The packet that you are seeing might be compressed, but it is impossible to say without seeing the configuration of your Minecraft user/server. 您看到的数据包可能会被压缩,但如果没有看到您的Minecraft用户/服务器的配置,则无法说出来。 If they are actually compressed - you will need to unzip them before you will be able to analyze them. 如果它们实际上是压缩的 - 您将需要解压缩它们才能分析它们。

To help you with decoding, I highly recommend Wireshark. 为了帮助您解码,我强烈推荐Wireshark。 Download it and re-run your network capture. 下载并重新运行您的网络捕获。 Then compare the decoded output with that of your program. 然后将解码后的输出与程序的输出进行比较。 Wireshark will give the meaning of each data member in a packet. Wireshark将在数据包中给出每个数据成员的含义。

EDIT: What part of decoding is unclear for you? 编辑:解码的哪个部分不清楚? Using pen and paper and windows calculator in programming mode here is the decoding of first packet: 在编程模式下使用笔和纸和窗口计算器这里是第一个数据包的解码:

15 - Varint - length of the packet
0  - Varint - packet ID - Handshake
47 - VarInt - protocol version
     Following bytes are length prefixed server address in UTF-8:
9  - Lenght
108 - l
111 - o
99  - c
97  - a
108 - l
104 - h
111 - o
115 - s
116 - t
     Following 2 bytes are server port in unsigned short format (I guess 7777)
30
97

1  - Varint - Next state

Last 2 bytes are unclear to me. 最后2个字节对​​我来说不清楚。

In short - for each packet: 简而言之 - 对于每个数据包:

  1. Find length of the packet 查找数据包的长度
  2. Find the packet type 找到数据包类型
  3. Using packet type decode the rest 使用数据包类型解码其余部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM