Hi guys.
I'm developing a clientless bot in Java for v62/83. However i have some problem's the the encription.
The problem is everythime i encode with the iv it become a different packet which i'm not able to decript
Encode:
Decode:
and the Cipher definition:
If i comment the line send_crypto.crypt(unencrypted); and the line PacketEncoder.recvCypher.crypt(decryptedPacket); (the iv cripto) it works
any idea why?
I'm developing a clientless bot in Java for v62/83. However i have some problem's the the encription.
The problem is everythime i encode with the iv it become a different packet which i'm not able to decript
Encode:
Code:
@Override protected void encode(ChannelHandlerContext ctx, Object message, ByteBuf buffer) throws Exception {
final byte[] input = (byte[]) message;
System.out.println("To decode: " + HexTool.toString(input));
final byte[] unencrypted = new byte[input.length];
System.arraycopy(input, 0, unencrypted, 0, input.length);
final byte[] ret = new byte[unencrypted.length + 4];
final byte[] header = send_crypto.getPacketHeader(unencrypted.length);
MapleCustomEncryption.encryptData(unencrypted);
send_crypto.crypt(unencrypted);
System.arraycopy(header, 0, ret, 0, 4);
System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);
buffer.writeBytes(ret);
System.out.println("After encode: " + HexTool.toString(ret));
}
Decode:
Code:
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> message) throws Exception {
DecoderState decoderState = ctx.channel().attr(DECODER_STATE_KEY).get();
if (decoderState == null) {
decoderState = new DecoderState();
ctx.channel().attr(DECODER_STATE_KEY).set(decoderState);
}
if (in.readableBytes() >= 4 && decoderState.packetlength == -1) {
int packetHeader = in.readInt();
if (!PacketEncoder.recvCypher.checkPacket(packetHeader)) {
System.out.println("Invalid packet");
//return;
}
decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
} else if (in.readableBytes() < 4 && decoderState.packetlength == -1) {
return;
}
if (in.readableBytes() >= decoderState.packetlength) {
byte decryptedPacket[] = new byte[decoderState.packetlength];
in.readBytes(decryptedPacket);
System.out.println("Starting decode: " + HexTool.toString(decryptedPacket));
decoderState.packetlength = -1;
PacketEncoder.recvCypher.crypt(decryptedPacket);
MapleCustomEncryption.decryptData(decryptedPacket);
System.out.println("Decoded: " + HexTool.toString(decryptedPacket));
message.add(decryptedPacket);
}
and the Cipher definition:
Code:
private final static short MAPLE_VERSION = 62;
public static final byte key[] = { 0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
(byte) 0xB4, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x52,
0x00, 0x00, 0x00 };
public static byte ivRecv[] = { 70, 114, 122, 82 };
public static byte ivSend[] = { 82, 48, 120, 115 };
public static MapleAESOFB send_crypto;
public static MapleAESOFB recvCypher;
static {
ivRecv[3] = (byte) (Math.random() * 255);
ivSend[3] = (byte) (Math.random() * 255);
send_crypto = new MapleAESOFB(key, ivSend, (short) (0xFFFF - MAPLE_VERSION));
recvCypher = new MapleAESOFB(key, ivRecv, MAPLE_VERSION);
}
If i comment the line send_crypto.crypt(unencrypted); and the line PacketEncoder.recvCypher.crypt(decryptedPacket); (the iv cripto) it works
any idea why?