コード例 #1
0
ファイル: Reader.cs プロジェクト: rtsonneveld/Ray1Map
        public override byte[] ReadBytes(int count)
        {
            byte[] bytes = base.ReadBytes(count);

            if (autoAlignOn)
            {
                bytesSinceAlignStart += (uint)bytes.Length;
            }

            if (checksumCalculator?.CalculateForDecryptedData == false)
            {
                checksumCalculator?.AddBytes(bytes);
            }

            if (xorKey.HasValue)
            {
                for (int i = 0; i < count; i++)
                {
                    bytes[i] = (byte)(bytes[i] ^ xorKey.Value);
                }
            }

            if (checksumCalculator?.CalculateForDecryptedData == true)
            {
                checksumCalculator?.AddBytes(bytes);
            }

            return(bytes);
        }
コード例 #2
0
ファイル: Writer.cs プロジェクト: PluMGMK/Ray1Map
        public override void Write(byte[] buffer)
        {
            if (buffer == null)
            {
                return;
            }

            var data = buffer;

            if (checksumCalculator?.CalculateForDecryptedData == true)
            {
                checksumCalculator?.AddBytes(data);
            }

            if (xorKey.HasValue)
            {
                // Avoid changing data in array, so create a copy
                data = new byte[buffer.Length];
                Array.Copy(buffer, 0, data, 0, buffer.Length);
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = (byte)(data[i] ^ xorKey.Value);
                }
            }

            if (checksumCalculator?.CalculateForDecryptedData == false)
            {
                checksumCalculator?.AddBytes(data);
            }

            base.Write(data);

            if (autoAlignOn)
            {
                bytesSinceAlignStart += (uint)data.Length;
            }
        }