예제 #1
0
            /// <summary>
            /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data.
            /// If the chunk has already been processed, this function does nothing.
            /// </summary>
            /// <param name="depotKey">The depot decryption key.</param>
            /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception>
            public void Process(byte[] depotKey)
            {
                if (depotKey == null)
                {
                    throw new ArgumentNullException(nameof(depotKey));
                }

                if (IsProcessed)
                {
                    return;
                }

                byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey);

                if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z')
                {
                    processedData = VZipUtil.Decompress(processedData);
                }
                else
                {
                    processedData = ZipUtil.Decompress(processedData);
                }

                byte[] dataCrc = CryptoHelper.AdlerHash(processedData);

                if (!dataCrc.SequenceEqual(ChunkInfo.Checksum))
                {
                    throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?");
                }

                Data        = processedData;
                IsProcessed = true;
            }
예제 #2
0
            /// <summary>
            /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data.
            /// If the chunk has already been processed, this function does nothing.
            /// </summary>
            /// <param name="depotKey">The depot decryption key.</param>
            /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception>
            public void Process(byte[] depotKey)
            {
                if (depotKey == null)
                {
                    throw new ArgumentNullException(nameof(depotKey));
                }

                if (IsProcessed)
                {
                    return;
                }

                if (Data != null)
                {
                    byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey);

                    if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z')
                    {
                        processedData = VZipUtil.Decompress(processedData);
                    }
                    else
                    {
                        processedData = ZipUtil.Decompress(processedData);
                    }

                    byte[] dataCrc = CryptoHelper.AdlerHash(processedData);

                    if (!dataCrc.SequenceEqual(ChunkInfo.Checksum))
                    {
                        throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?");
                    }

                    Data        = processedData;
                    IsProcessed = true;
                }
                if (DataStream != null)
                {
                    Stream reProcessedData;
                    using (Stream processedData = CryptoHelper.SymmetricDecrypt(DataStream, depotKey))
                    {
                        int firstByte  = processedData.ReadByte();
                        int secondByte = processedData.ReadByte();
                        processedData.Position = 0;

                        if (firstByte == 86 && secondByte == 90)
                        {
                            reProcessedData = VZipUtil.Decompress(processedData);
                        }
                        else
                        {
                            reProcessedData = ZipUtil.Decompress(processedData);
                        }
                    }

                    byte[] dataCrc = CryptoHelper.AdlerHash(reProcessedData);

                    if (!dataCrc.SequenceEqual(ChunkInfo.Checksum))
                    {
                        throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?");
                    }

                    DataStream  = reProcessedData;
                    IsProcessed = true;
                }
            }