List of usage examples for io.netty.buffer ByteBuf getUnsignedByte
public abstract short getUnsignedByte(int index);
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
static boolean isLengthCodedLongNull(ByteBuf cb) { boolean isNull = (cb.getUnsignedByte(cb.readerIndex()) == LEN_CODED_NULL); if (isNull)//from w w w . j a v a 2 s. co m cb.readUnsignedByte(); return isNull; }
From source file:com.twitter.http2.HttpFrameDecoder.java
License:Apache License
/** * Reads the HTTP/2 Frame Header and sets the length, type, flags, and streamId member variables. * * @param buffer input buffer containing the entire 9-octet header *///from w w w . j ava 2s . co m private void readFrameHeader(ByteBuf buffer) { int frameOffset = buffer.readerIndex(); length = getUnsignedMedium(buffer, frameOffset); type = buffer.getUnsignedByte(frameOffset + 3); flags = buffer.getByte(frameOffset + 4); streamId = getUnsignedInt(buffer, frameOffset + 5); buffer.skipBytes(HTTP_FRAME_HEADER_SIZE); }
From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java
License:Open Source License
static int GetDecodedSize(ByteBuf buff) { switch (buff.getUnsignedByte(0)) { case 0xC1://w w w . ja va 2 s. c om return GetPacketSize(buff); case 0xC3: return (((GetPacketSize(buff) - 2) * 8) / 11) + 1; case 0xC2: return GetPacketSize(buff); case 0xC4: return (((GetPacketSize(buff) - 3) * 8) / 11) + 2; default: return 0; } }
From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java
License:Open Source License
static int GetHeaderSize(ByteBuf buff) { switch (buff.getUnsignedByte(0)) { case 0xC1:// w w w.j a va 2 s . c o m case 0xC3: return 2; case 0xC2: case 0xC4: return 3; } return -1; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java
License:Open Source License
static int GetPacketSize(ByteBuf buff) { switch (buff.getUnsignedByte(0)) { case 0xC1://from ww w . java 2 s. c o m case 0xC3: return buff.getUnsignedByte(1); case 0xC2: case 0xC4: return buff.getUnsignedByte(1) << 8 | buff.getUnsignedByte(2) & 0xFF; } return -1; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java
License:Open Source License
public static final short[] getAsUByteArray(ByteBuf buff) { short[] uByteArray = new short[buff.capacity()]; for (int i = 0; i < uByteArray.length; i++) { uByteArray[i] = buff.getUnsignedByte(i); }/*from w w w . j a va2s . com*/ return uByteArray; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java
License:Open Source License
public static final short[] getAsUByteArray(ByteBuf buff, short[] uByteArray) { for (int i = 0; i < uByteArray.length; i++) { uByteArray[i] = buff.getUnsignedByte(i); }//w w w. j a va 2s. c o m return uByteArray; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java
License:Open Source License
/** * C3 C4/*from w ww .ja v a 2s .c o m*/ * @param buff * @return */ public static ByteBuf DecodePacket(ByteBuf buff) { if (buff.writerIndex() <= 2) { log.fatal("Ambiguous buffer! " + ByteBufUtil.hexDump(buff)); return null; } if (buff.readerIndex() != 0) { log.warn("Buffer must be at index 0!"); buff.readerIndex(0); } int header = GetHeaderSize(buff); int packetSize = GetPacketSize(buff); int decodedSize = GetDecodedSize(buff); int contentSize = packetSize - header; //System.out.println("Header[0x"+PrintData.fillHex(buff.getUnsignedByte(0), 2)+"] size: "+GetHeaderSize(buff)+" Packet Size: "+GetPacketSize(buff) +" Content Size: "+contentSize +" Decoded: "+ GetDecodedSize(buff)); ByteBuf out = alloc.heapBuffer(decodedSize, decodedSize); int originalHead = buff.getUnsignedByte(0); buff.readerIndex(header); int size = DecodeBlock(buff, out, header, contentSize); //buff.clear(); size += header - 1; out.writerIndex(0); out.writeByte(originalHead); switch (originalHead) { case 0xc3: out.writeByte(size); break; case 0xC4: out.writeByte(size >> 8); out.writeByte(size & 0xFF); break; } out.writerIndex(size); out.readerIndex(header); DecXor32(out, header, size); out.readerIndex(0); return out; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java
License:Open Source License
/** * @param decrypted//from ww w.j a v a 2 s . co m * @param encrypted * @param decServerKeys * @return */ private static int BlockDecode(ByteBuf decrypted, short[] InBuf, ByteBuf converter, long[] Keys) { long[] Ring = new long[4]; short[] Shift = new short[4]; ShiftBytes(Shift, 0x00, InBuf, 0x00, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x10, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x12, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x22, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x24, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x34, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x36, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x46, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); // for (int i = 0; i < Ring.length; i++) { // System.err.print(Integer.toHexString((int) Ring[i])+" ");; // } // System.err.println(); for (int i = 0; i < Ring.length; i++) { Ring[i] = converter.readInt(); } converter.clear(); Ring[2] = Ring[2] ^ Keys[10] ^ (Ring[3] & 0xFFFF); Ring[1] = Ring[1] ^ Keys[9] ^ (Ring[2] & 0xFFFF); Ring[0] = Ring[0] ^ Keys[8] ^ (Ring[1] & 0xFFFF); // System.err.println("Finished Ring: "); // for (int i = 0; i < Ring.length; i++) { // System.err.print(Integer.toHexString((int) Ring[i])+" ");; // } // System.err.println(); int[] CryptBuf = new int[4]; // Had ushort cast here. CryptBuf[0] = (int) (Keys[8] ^ ((Ring[0] * Keys[4]) % Keys[0])); CryptBuf[1] = (int) (Keys[9] ^ ((Ring[1] * Keys[5]) % Keys[1]) ^ (Ring[0] & 0xFFFF)); CryptBuf[2] = (int) (Keys[10] ^ ((Ring[2] * Keys[6]) % Keys[2]) ^ (Ring[1] & 0xFFFF)); CryptBuf[3] = (int) (Keys[11] ^ ((Ring[3] * Keys[7]) % Keys[3]) ^ (Ring[2] & 0xFFFF)); // System.err.println("Pre done: " + PrintData.printData(CryptBuf)); short[] Finale = new short[2]; ShiftBytes(Finale, 0x00, InBuf, 0x48, 0x10); Finale[0] ^= Finale[1]; Finale[0] ^= 0x3D; converter.clear(); for (int i = 0; i < CryptBuf.length; i++) { converter.writeShort(CryptBuf[i]); } decrypted.writeBytes(converter, Finale[0]); converter.clear(); //System.out.println(PrintData.printData(decrypted.nioBuffer())); // System.err.println("Finale: "+ Finale[0]); short Check = 0xF8; for (int i = 0; i < Finale[0]; ++i) Check = (short) (Check ^ decrypted.getUnsignedByte(i)); if (Finale[1] == Check) return Finale[0]; //System.err.println("Finale["+Finale[0]+"] And done: "+PrintData.printData(decrypted.nioBuffer())); return Finale[0]; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java
License:Open Source License
private static void DecXor32(ByteBuf buff, int SizeOfHeader, int Len) { for (int i = Len - 1; i > 0; i--) { int Buff = buff.getUnsignedByte(buff.readerIndex() + i); Buff ^= (Xor32Keys[(i + SizeOfHeader) & 31] ^ buff.getUnsignedByte((buff.readerIndex() + i) - 1)); buff.setByte(buff.readerIndex() + i, Buff); }//from w w w . j a v a2s . com }