Esempio n. 1
0
        /// <summary>
        ///     Decrypts data from server-side packets (sent from servers to clients.)
        /// </summary>
        /// <param name="source">The encrypted packet data.</param>
        /// <param name="key">Key to decrypt with.</param>
        /// <returns>The decrypted packet data.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown if the key is invalid or the packet data is too short.
        /// </exception>
        public static byte[] Decrypt(byte[] source, byte key)
        {
            if (key >= 0x10)
            {
                throw new ArgumentOutOfRangeException(nameof(key), $"Key too large ({key} >= 0x10)");
            }

            if (source.Length < 8)
            {
                throw new ArgumentOutOfRangeException(nameof(source), $"Packet too small ({source.Length} < 8)");
            }

            var oracleByte = CryptoOracle.CryptTable2[(key << 8) + source[0]];
            var buffer     = (byte[])source.Clone();

            buffer[7] ^= oracleByte;

            for (var i = 10; i < source.Length; i++)
            {
                buffer[i] ^= buffer[i - 4];
            }

            var compressedData = new byte[source.Length - 8];

            Array.Copy(buffer, 8, compressedData, 0, source.Length - 8);
            return(MiniLzo.Decompress(compressedData));
        }