Skip to content

Instantly share code, notes, and snippets.

@nathan130200
Forked from joserobjr/test\DataInspect.java
Created December 30, 2019 18:01
Show Gist options
  • Save nathan130200/28b16c50323ff23a08c4e4d2c530724c to your computer and use it in GitHub Desktop.
Save nathan130200/28b16c50323ff23a08c4e4d2c530724c to your computer and use it in GitHub Desktop.
Wireshark RakNet
package test;
import cn.nukkit.network.Network;
import cn.nukkit.network.protocol.BatchPacket;
import cn.nukkit.network.protocol.DataPacket;
import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.raknet.protocol.EncapsulatedPacket;
import cn.nukkit.utils.Zlib;
import java.util.Arrays;
public class DataInspect {
private static Network network = new Network(null);
public static void main(String[] args) {
Zlib.setProvider(0);
byte[] bytes = hexStringToByteArray("02000000450000806da20000801100007f0000017f000001f62a4abc006cbc5c844a40006002b0793f00633f0000fe47b1165edafe07b91e7733a8f1eea936522efeb9aa7c03f907fb191a28eb3ab71f705575e17cbd82b6466fd2baefede39e25f281d6e3d1f71f6d76180d72ca7e1cb4999b4edad7d67506d8a59e4cdedb5edcfbee8a");
bytes = hexStringToByteArray("02000000450000676dc40000801100007f0000017f000001f62a4abc0053d023845740006001e8863f00703f0000fead3af44f24c42dcf1b9880629d3cd7a044aaf383881cf2391e08a69d53287706c2dd294f70ed8342eb00bc2d1452c19556febe40b2b157358544d208");
bytes = hexStringToByteArray("0200000045000065986d0000801100007f0000017f0000014abcf62a00519ffa844003006001d8390300e4020000febbfa4976c4164af761b3951e03998b7beb37c52204727343dea7248fcd4540ede0ae9da31575eacdcba4641c5aa94dfaf9b388c58d393e586f96");
bytes = hexStringToByteArray("02000000450000a684230000801100007f0000017f000001fbe14abc0092b961849806006003e07e060068060000fe20d0d3949473f5bd0c4dc72f5c0be4022cd4d5fd9fcb655c6754193567f088e0ec26739da043eb744e323ec0118dcb5b2ea439aea9f4f0f78ae68726983b1e24a1b85f394c6ec43480ed160dfe1203933c493a9e3aea0dbd3f652fb02475e61968db9a4e5140b624ddb3717f847b5ad2fdfd797eb46be6663c870e");
//bytes = hexStringToByteArray("0200000045000078ca3a0000801100007f0000017f000001fbe14abc0064969d84da0000600270c80000af000000fe7801014200bdff237b231a37ce4296d08242f8238a42fa08106d696e6563726166743a706c6179657200001d13011741ce42723d8542fe228a4288348b4178d5a84277d5a842000100490018b7");
bytes = Arrays.copyOfRange(bytes, 8*4 + 4, bytes.length);
EncapsulatedPacket encapsulatedPacket = EncapsulatedPacket.fromBinary(bytes);
DataPacket packet = getPacket(encapsulatedPacket.buffer);
assert packet != null;
packet.decode();
if (packet instanceof BatchPacket) {
BatchPacket batchPacket = (BatchPacket) packet;
network.processBatch(batchPacket, null);
}
}
private static DataPacket getPacket(byte[] buffer) {
int start = 0;
if (buffer[0] == (byte) 0xfe) {
start++;
}
DataPacket data = network.getPacket(ProtocolInfo.BATCH_PACKET);
if (data == null) {
return null;
}
data.setBuffer(buffer, start);
return data;
}
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment