getSize() public method

public getSize ( ) : int
return int
Exemplo n.º 1
0
        public void addCharacter(string charName, int charId, int status, int serverId)
        {
            byte[] charNameB = new byte[charName.Length + 3];
            byte[] hexSize   = NumericalUtils.uint16ToByteArray((UInt16)(charName.Length + 1), 1);
            charNameB[0] = hexSize[0];
            charNameB[1] = hexSize[1];
            charNameB[charName.Length + 2] = 0x00;
            for (int i = 0; i < charName.Length; i++)
            {
                charNameB[2 + i] = (byte)charName[i];
            }


            byte[] charDataB = new byte[14];
            byte[] charIdB   = NumericalUtils.uint32ToByteArray((UInt32)charId, 1);
            charDataB[3]  = charIdB[0];
            charDataB[4]  = charIdB[1];
            charDataB[5]  = charIdB[2];
            charDataB[6]  = charIdB[3];
            charDataB[9]  = 0x00;
            charDataB[10] = (byte)status;
            charDataB[11] = 0x00;
            charDataB[12] = (byte)serverId;

            numChars++; // Lets say we have done one ;)

            int offset = 0;

            // Use formula to calculate offset here

            offset = 14 + (14 * (totalChars - numChars));

            if (numChars == 1)
            {
                offset += 0;
            }
            else
            {
                offset += charNames.getSize();
            }

            // End of formula

            byte[] offsetH = NumericalUtils.uint16ToByteArray((UInt16)offset, 1);
            charDataB[1] = offsetH[0];
            charDataB[2] = offsetH[1];

            // After all calculations, append it to the dynamic arrays
            charData.append(charDataB);
            charNames.append(charNameB);
        }
Exemplo n.º 2
0
        public byte[] encrypt(byte[] packet)
        {
            // Get timestamp
            byte[] timestamp = TimeUtils.getUnixTime();

            // get size
            int psize = packet.Length;
            byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize,1);

            //showPacket(size, " Size ");

            // final Packet

            DynamicArray temp = new DynamicArray();
            temp.append(size);
            temp.append(timestamp);
            temp.append(packet);

            // compute CRC32
            byte[] crc32pax = crc32.checksumB(temp.getBytes(),1);

            // Padding
            int totalLength = temp.getSize() + 4;
            int padding = 16 - (totalLength % 16);

            byte[] paddingBytes = new byte[padding];

            for (int i = 0; i < padding; i++)
            {
                paddingBytes[i] = (byte)padding;
            }

            temp.append(paddingBytes);
            tf.setIV(IV);
            tf.setKey(TF_Key);

            // We init with 2 more than needed, so no memory reservation is done on dyn array
            DynamicArray finalPlainData = new DynamicArray();

            finalPlainData.append(crc32pax);
            finalPlainData.append(temp.getBytes());

            temp = null; // Cleaning the house

            byte[] encryptedData = new byte[finalPlainData.getSize()];
            tf.encrypt(finalPlainData.getBytes(),encryptedData);

            finalPlainData = null; // Cleaning the house (2)

            // add IV before the results

            DynamicArray response = new DynamicArray();
            response.append(IV);
            response.append(encryptedData);

            // Display HEX Values after Encryption
            return response.getBytes();
        }
Exemplo n.º 3
0
        public byte[] encrypt(byte[] packet)
        {
            // Get timestamp
            byte[] timestamp = TimeUtils.getUnixTime();


            // get size
            int psize = packet.Length;

            byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize, 1);

            //showPacket(size, " Size ");

            // final Packet

            DynamicArray temp = new DynamicArray();

            temp.append(size);
            temp.append(timestamp);
            temp.append(packet);


            // compute CRC32
            byte[] crc32pax = crc32.checksumB(temp.getBytes(), 1);


            // Padding
            int totalLength = temp.getSize() + 4;
            int padding     = 16 - (totalLength % 16);

            byte[] paddingBytes = new byte[padding];

            for (int i = 0; i < padding; i++)
            {
                paddingBytes[i] = (byte)padding;
            }

            temp.append(paddingBytes);
            tf.setIV(IV);
            tf.setKey(TF_Key);

            // We init with 2 more than needed, so no memory reservation is done on dyn array
            DynamicArray finalPlainData = new DynamicArray();

            finalPlainData.append(crc32pax);
            finalPlainData.append(temp.getBytes());

            temp = null;             // Cleaning the house


            byte[] encryptedData = new byte[finalPlainData.getSize()];
            tf.encrypt(finalPlainData.getBytes(), encryptedData);


            finalPlainData = null;             // Cleaning the house (2)

            // add IV before the results

            DynamicArray response = new DynamicArray();

            response.append(IV);
            response.append(encryptedData);

            // Display HEX Values after Encryption
            return(response.getBytes());
        }
Exemplo n.º 4
0
 public int getTotalSize()
 {
     // We also add the 2 length bytes
     return(worlds.getSize() + 2);
 }
Exemplo n.º 5
0
 public int getPackLength()
 {
     // We will count the 2bytes of content size too ;)
     return(charNames.getSize() + charData.getSize() + 2);
 }