public EncoderStream(Stream stream, ByteEncoder encoder, EncoderStreamAccess access) { if (stream == null) { throw new ArgumentNullException("stream"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } if (access == EncoderStreamAccess.Read) { if (!stream.CanRead) { throw new NotSupportedException(EncodersStrings.EncStrCannotRead); } } else if (!stream.CanWrite) { throw new NotSupportedException(EncodersStrings.EncStrCannotWrite); } this.stream = stream; this.encoder = encoder; this.access = access; this.ownsStream = true; this.length = long.MaxValue; this.buffer = new byte[4096]; }
// Token: 0x06000663 RID: 1635 RVA: 0x00024E74 File Offset: 0x00023074 public sealed override void Convert(byte[] input, int inputIndex, int inputSize, byte[] output, int outputIndex, int outputSize, bool flush, out int inputUsed, out int outputUsed, out bool completed) { if (inputSize != 0) { if (input == null) { throw new ArgumentNullException("input"); } if (inputIndex < 0 || inputIndex >= input.Length) { throw new ArgumentOutOfRangeException("inputIndex"); } if (inputSize < 0 || inputSize > input.Length - inputIndex) { throw new ArgumentOutOfRangeException("inputSize"); } } if (output == null) { throw new ArgumentNullException("output"); } if (outputIndex < 0 || outputIndex >= output.Length) { throw new ArgumentOutOfRangeException("outputIndex"); } if (outputSize < 1 || outputSize > output.Length - outputIndex) { throw new ArgumentOutOfRangeException("outputSize"); } if (this.numLines == 0) { this.outLineReady = false; this.bufferSize = 0; Array.Clear(this.chunk, 0, this.chunk.Length); this.chunkIndex = 0; if (this.fileName != null) { ByteEncoder.BlockCopy(UUEncoder.Prologue, 0, this.buffer, 0, UUEncoder.Prologue.Length); this.bufferSize = UUEncoder.Prologue.Length; ByteEncoder.BlockCopy(this.fileName, 0, this.buffer, this.bufferSize, this.fileName.Length); this.bufferSize += this.fileName.Length; ByteEncoder.BlockCopy(ByteEncoder.LineWrap, 0, this.buffer, this.bufferSize, ByteEncoder.LineWrap.Length); this.bufferSize += ByteEncoder.LineWrap.Length; this.bufferIndex = 0; this.outLineReady = true; this.numLines++; } } inputUsed = inputIndex; outputUsed = outputIndex; do { if (this.outLineReady) { int num = Math.Min(this.bufferSize, outputSize); ByteEncoder.BlockCopy(this.buffer, this.bufferIndex, output, outputIndex, num); outputSize -= num; outputIndex += num; this.bufferSize -= num; this.bufferIndex += num; if (this.bufferSize != 0) { break; } this.outLineReady = false; if (3 == this.bufferIndex) { if (this.fileName != null) { ByteEncoder.BlockCopy(UUEncoder.Epilogue, 0, this.buffer, 0, UUEncoder.Epilogue.Length); this.bufferSize = UUEncoder.Epilogue.Length; this.bufferIndex = 0; this.outLineReady = true; continue; } break; } else { if (5 == this.bufferIndex && this.fileName != null && this.buffer[0] == 101) { break; } this.bufferIndex = 0; } } if (this.bufferSize == 0) { this.buffer[this.bufferSize++] = 0; this.bufferIndex = 0; this.rawCount = 0; this.numLines++; } while (inputSize != 0 || flush) { if (inputSize != 0) { int num2 = Math.Min(3 - this.chunkIndex, inputSize); if ((num2 & 2) != 0) { this.chunk[this.chunkIndex++] = input[inputIndex++]; this.chunk[this.chunkIndex++] = input[inputIndex++]; } if ((num2 & 1) != 0) { this.chunk[this.chunkIndex++] = input[inputIndex++]; } inputSize -= num2; if (this.chunkIndex != 3) { continue; } } if (this.chunkIndex != 0) { if (3 != this.chunkIndex) { Array.Clear(this.chunk, this.chunkIndex, 3 - this.chunkIndex); } this.buffer[this.bufferSize++] = UUEncoder.UUEncode(this.chunk[0] >> 2); this.buffer[this.bufferSize++] = UUEncoder.UUEncode((int)this.chunk[0] << 4 | this.chunk[1] >> 4); this.buffer[this.bufferSize++] = UUEncoder.UUEncode((int)this.chunk[1] << 2 | this.chunk[2] >> 6); this.buffer[this.bufferSize++] = UUEncoder.UUEncode((int)this.chunk[2]); this.rawCount += this.chunkIndex; this.chunkIndex = 0; } if (this.bufferSize == 61 || (flush && inputSize == 0)) { this.buffer[0] = UUEncoder.UUEncode(this.rawCount); this.buffer[this.bufferSize++] = 13; this.buffer[this.bufferSize++] = 10; this.outLineReady = true; break; } } }while (this.outLineReady); inputUsed = inputIndex - inputUsed; outputUsed = outputIndex - outputUsed; completed = (inputSize == 0 && (!flush || 0 == this.bufferSize)); if (flush && completed) { this.numLines = 0; } }
// Token: 0x0600065C RID: 1628 RVA: 0x00024ACC File Offset: 0x00022CCC private bool UULineGood() { this.encodedBytes = 0; int num = this.encodedSize; while (this.encodedSize > 0 && ByteEncoder.IsWhiteSpace(this.encoded[this.encodedSize - 1])) { this.encodedSize--; } if (this.encodedSize == 0) { return(true); } if (this.state == UUDecoder.State.Prologue) { if (ByteEncoder.BeginsWithNI(this.encoded, 0, UUDecoder.Prologue, this.encodedSize)) { int num2 = this.encodedSize - 6; int num3 = 6; while (num2 != 0 && ByteEncoder.IsWhiteSpace(this.encoded[num3])) { num3++; num2--; } if (num2 == 0 || this.encoded[num3] < 48 || this.encoded[num3] > 55) { return(true); } do { num3++; num2--; }while (num2 != 0 && this.encoded[num3] >= 48 && this.encoded[num3] <= 55); if (num2 == 0 || !ByteEncoder.IsWhiteSpace(this.encoded[num3])) { return(true); } do { num3++; num2--; }while (num2 != 0 && ByteEncoder.IsWhiteSpace(this.encoded[num3])); if (num2 <= 128) { this.fileName = new byte[num2]; ByteEncoder.BlockCopy(this.encoded, num3, this.fileName, 0, num2); } return(true); } } else { if (this.state == UUDecoder.State.Ending) { return(true); } if (ByteEncoder.BeginsWithNI(this.encoded, 0, UUDecoder.Prologue, this.encodedSize)) { return(true); } } if (true) { int num4 = (int)UUDecoder.UUDecode(this.encoded[0]); int num5 = 0; int num6 = num4 % 3; if (num6 != 0) { num6++; num5 = 4 - num6; } int num7 = 4 * (num4 / 3) + num6 + 1; if (this.encodedSize < num7) { if (num < num7) { goto IL_285; } this.encodedSize = num7; } if (num7 != this.encodedSize && num7 + num5 != this.encodedSize) { if (num7 + 1 == this.encodedSize || num7 + num5 + 1 == this.encodedSize) { this.encodedSize--; } else { if (num7 - 1 != this.encodedSize && num7 + num5 - 1 == this.encodedSize) { goto IL_285; } goto IL_285; } } this.encodedBytes = num4; if (num5 != 0 && num7 == this.encodedSize) { this.encoded[num7] = 32; if (num5 > 1) { this.encoded[num7 + 1] = 32; } this.encodedSize += num5; } this.encodedSize--; this.encodedIndex = 1; if (this.encodedBytes == 0) { this.state = UUDecoder.State.Ending; } else { this.state = UUDecoder.State.Data; } return(true); } IL_285: if (ByteEncoder.BeginsWithNI(this.encoded, 0, UUDecoder.Epilogue, this.encodedSize)) { this.state = UUDecoder.State.Ending; return(true); } return(false); }
// Token: 0x060005D9 RID: 1497 RVA: 0x00020C04 File Offset: 0x0001EE04 public sealed override void Convert(byte[] input, int inputIndex, int inputSize, byte[] output, int outputIndex, int outputSize, bool flush, out int inputUsed, out int outputUsed, out bool completed) { if (inputSize != 0) { if (input == null) { throw new ArgumentNullException("input"); } if (inputIndex < 0 || inputIndex >= input.Length) { throw new ArgumentOutOfRangeException("inputIndex"); } if (inputSize < 0 || inputSize > input.Length - inputIndex) { throw new ArgumentOutOfRangeException("inputSize"); } } if (output == null) { throw new ArgumentNullException("output"); } if (outputIndex < 0 || outputIndex >= output.Length) { throw new ArgumentOutOfRangeException("outputIndex"); } if (outputSize < 1 || outputSize > output.Length - outputIndex) { throw new ArgumentOutOfRangeException("outputSize"); } inputUsed = inputIndex; outputUsed = outputIndex; for (;;) { if (this.extraSize != 0) { int num = Math.Min(this.extraSize, outputSize); Buffer.BlockCopy(this.extra, this.extraIndex, output, outputIndex, num); outputSize -= num; outputIndex += num; this.extraSize -= num; if (this.extraSize != 0) { this.extraIndex += num; goto IL_2F0; } this.extraIndex = 0; } if (this.repeatCount != 0) { switch (this.state) { case BinHexUtils.State.Data: case BinHexUtils.State.Resource: this.OutputChunk(output, ref outputIndex, ref outputSize); break; case BinHexUtils.State.DataCRC: goto IL_123; default: goto IL_123; } IL_13B: if (this.bytesNeeded == 0) { this.TransitionState(); } if (outputSize == 0) { goto IL_2F0; } continue; IL_123: this.OutputChunk(this.scratch, ref this.scratchIndex, ref this.scratchSize); goto IL_13B; } if (this.lineReady) { byte b = this.encoded[this.encodedIndex++]; this.encodedSize--; if (this.encodedSize == 0) { this.lineReady = false; } if (ByteEncoder.IsWhiteSpace(b)) { continue; } if (this.state == BinHexUtils.State.Started) { if (58 == b) { this.state = BinHexUtils.State.HdrFileSize; this.bytesNeeded = 1; this.scratchSize = this.scratch.Length; this.scratchIndex = 0; this.runningCRC = 0; continue; } break; } else { b -= 32; byte b2 = ((int)b >= BinHexDecoder.Dictionary.Length) ? 127 : BinHexDecoder.Dictionary[(int)b]; if (b2 == 127) { goto Block_20; } if (this.accumCount == 0) { this.accum = (int)b2; this.accumCount++; continue; } this.accum = (this.accum << 6 | (int)b2); b2 = (byte)(this.accum >> BinHexDecoder.ShiftTabe[this.accumCount] & 255); this.accumCount++; this.accumCount %= Marshal.SizeOf(this.accum); if (this.repeatCheck) { this.repeatCheck = false; if (b2 == 0) { this.decodedByte = 144; this.repeatCount = 1; continue; } this.repeatCount = (int)(b2 - 1); continue; } else { if (144 == b2) { this.repeatCheck = true; continue; } this.decodedByte = b2; this.repeatCount = 1; continue; } } } IL_2F0: if (this.lineReady) { goto IL_316; } this.lineReady = this.ReadLine(input, ref inputIndex, ref inputSize, flush); if (!this.lineReady) { goto IL_316; } } throw new ByteEncoderException(EncodersStrings.BinHexDecoderFirstNonWhitespaceMustBeColon); Block_20: throw new ByteEncoderException(EncodersStrings.BinHexDecoderFoundInvalidCharacter); IL_316: outputUsed = outputIndex - outputUsed; inputUsed = inputIndex - inputUsed; completed = (inputSize == 0 && this.extraSize == 0 && this.repeatCount == 0 && !this.lineReady); if (flush && completed) { if (this.state != BinHexUtils.State.Ending) { throw new ByteEncoderException(EncodersStrings.BinHexDecoderDataCorrupt); } this.Reset(); } }
// Token: 0x060005DE RID: 1502 RVA: 0x000210B0 File Offset: 0x0001F2B0 private bool ReadLine(byte[] input, ref int inputIndex, ref int inputSize, bool flush) { if (this.state == BinHexUtils.State.Ending) { inputIndex += inputSize; inputSize = 0; return(false); } bool result = false; while (inputSize != 0 || (flush && this.encodedSize != 0)) { byte b = 10; if (inputSize != 0) { inputSize--; b = input[inputIndex++]; } if (b != 10) { if (this.encodedSize >= this.encoded.Length) { throw new ByteEncoderException(EncodersStrings.BinHexDecoderLineTooLong); } this.encoded[this.encodedSize++] = b; } else if (this.state == BinHexUtils.State.Starting) { uint num = 0U; while ((ulong)num < (ulong)((long)this.encodedSize)) { if (!ByteEncoder.IsWhiteSpace(this.encoded[(int)((UIntPtr)num)])) { if ((ulong)((uint)((long)this.encodedSize - (long)((ulong)num))) >= (ulong)((long)BinHexDecoder.BinHexPrologue.Length) && ByteEncoder.BeginsWithNI(this.encoded, (int)num, BinHexDecoder.BinHexPrologue, BinHexDecoder.BinHexPrologue.Length)) { this.state = BinHexUtils.State.Started; this.repeatCheck = false; this.accumCount = 0; this.accum = 0; this.header = null; break; } throw new ByteEncoderException(EncodersStrings.BinHexDecoderLineCorrupt); } else { num += 1U; } } this.encodedSize = 0; } else { while (this.encodedSize != 0 && (this.encoded[this.encodedSize - 1] == 13 || this.encoded[this.encodedSize - 1] == 32 || this.encoded[this.encodedSize - 1] == 9)) { this.encodedSize--; } if (this.encodedSize != 0) { result = true; this.encodedIndex = 0; break; } if (this.state == BinHexUtils.State.Started) { } } } return(result); }
// Token: 0x06000643 RID: 1603 RVA: 0x000235DC File Offset: 0x000217DC public sealed override void Convert(byte[] input, int inputIndex, int inputSize, byte[] output, int outputIndex, int outputSize, bool flush, out int inputUsed, out int outputUsed, out bool completed) { if (inputSize != 0) { if (input == null) { throw new ArgumentNullException("input"); } if (inputIndex < 0 || inputIndex >= input.Length) { throw new ArgumentOutOfRangeException("inputIndex"); } if (inputSize < 0 || inputSize > input.Length - inputIndex) { throw new ArgumentOutOfRangeException("inputSize"); } } if (output == null) { throw new ArgumentNullException("output"); } if (outputIndex < 0 || outputIndex >= output.Length) { throw new ArgumentOutOfRangeException("outputIndex"); } if (outputSize < 1 || outputSize > output.Length - outputIndex) { throw new ArgumentOutOfRangeException("outputSize"); } outputUsed = outputIndex; inputUsed = inputIndex; int num = inputIndex + inputSize; while (inputIndex != num && outputSize != 0) { if (this.encodedIndex != 0) { for (;;) { byte b = input[inputIndex++]; if (32 != b && 9 != b) { this.encoded[this.encodedIndex++] = b; if (this.encodedIndex == 3) { break; } } if (inputIndex == num) { goto IL_164; } } this.encodedIndex = 0; byte b2 = this.encoded[1]; byte b3 = this.encoded[2]; if (b2 != 13 || b3 != 10) { byte b4 = ByteEncoder.Tables.NumFromHex[(int)b2]; byte b5 = ByteEncoder.Tables.NumFromHex[(int)b3]; byte b = (b4 == byte.MaxValue || b5 == byte.MaxValue) ? 61 : ((byte)((int)b4 << 4 | (int)b5)); output[outputIndex++] = b; if (--outputSize == 0) { inputUsed = inputIndex - inputUsed; outputUsed = outputIndex - outputUsed; completed = (inputIndex == num); return; } } } IL_164: if (inputIndex != num) { int num2 = Math.Min(num - inputIndex, outputSize); int num3 = ByteString.IndexOf(input, 61, inputIndex, num2); if (input.GetLowerBound(0) - 1 == num3) { num3 = inputIndex + num2; } else { num2 = num3 - inputIndex; this.encoded[this.encodedIndex++] = 61; num3++; } if (0 < num2) { ByteEncoder.BlockCopy(input, inputIndex, output, outputIndex, num2); outputSize -= num2; outputIndex += num2; } inputIndex = num3; } } if (flush && this.encodedIndex != 0 && inputIndex == num) { if ((this.encodedIndex == 1 && 61 == this.encoded[0]) || this.encoded[1] == 13) { this.encodedIndex = 0; } else if (0 < outputSize) { output[outputIndex++] = this.encoded[0]; if (0 < --outputSize) { if (1 < this.encodedIndex) { output[outputIndex++] = this.encoded[1]; } this.encodedIndex = 0; } else if (1 < this.encodedIndex) { this.encoded[0] = this.encoded[1]; this.encodedIndex--; } } } inputUsed = inputIndex - inputUsed; outputUsed = outputIndex - outputUsed; completed = (inputIndex == num && (!flush || 0 == this.encodedIndex)); }
public sealed override void Convert(byte[] input, int inputIndex, int inputSize, byte[] output, int outputIndex, int outputSize, bool flush, out int inputUsed, out int outputUsed, out bool completed) { if (inputSize != 0) { if (input == null) { throw new ArgumentNullException("input"); } if (inputIndex < 0 || inputIndex >= input.Length) { throw new ArgumentOutOfRangeException("inputIndex"); } if (inputSize < 0 || inputSize > input.Length - inputIndex) { throw new ArgumentOutOfRangeException("inputSize"); } } if (output == null) { throw new ArgumentNullException("output"); } if (outputIndex < 0 || outputIndex >= output.Length) { throw new ArgumentOutOfRangeException("outputIndex"); } if (outputSize < 1 || outputSize > output.Length - outputIndex) { throw new ArgumentOutOfRangeException("outputSize"); } inputUsed = inputIndex; outputUsed = outputIndex; int num = inputIndex + inputSize; if (this.decodedSize != 0) { int num2 = Math.Min(outputSize, this.decodedSize); if ((num2 & 2) != 0) { output[outputIndex++] = this.decoded[this.decodedIndex++]; output[outputIndex++] = this.decoded[this.decodedIndex++]; } if ((num2 & 1) != 0) { output[outputIndex++] = this.decoded[this.decodedIndex++]; } outputSize -= num2; this.decodedSize -= num2; if (this.decodedSize == 0) { this.decodedIndex = 0; } } while (this.decodedSize == 0 && (inputIndex != num || (flush && this.encodedSize != 0))) { while (inputIndex != num && 4 != this.encodedSize) { byte b = input[inputIndex++]; if (b != 61 && !ByteEncoder.IsWhiteSpace(b)) { b -= 32; if ((int)b < ByteEncoder.Tables.Base64ToByte.Length) { b = ByteEncoder.Tables.Base64ToByte[(int)b]; if (b < 64) { this.encoded[this.encodedSize++] = b; } } } } if (4 == this.encodedSize && 3 <= outputSize) { output[outputIndex] = (byte)((int)this.encoded[0] << 2 | this.encoded[1] >> 4); output[outputIndex + 1] = (byte)((int)this.encoded[1] << 4 | this.encoded[2] >> 2); output[outputIndex + 2] = (byte)((int)this.encoded[2] << 6 | (int)this.encoded[3]); outputSize -= 3; outputIndex += 3; this.encodedSize = 0; } else { if (4 != this.encodedSize && (!flush || num != inputIndex)) { break; } if (2 > this.encodedSize) { this.encodedSize = 0; break; } if (this.encodedSize > 1) { this.decoded[this.decodedSize++] = (byte)((int)this.encoded[0] << 2 | this.encoded[1] >> 4); } if (this.encodedSize > 2) { this.decoded[this.decodedSize++] = (byte)((int)this.encoded[1] << 4 | this.encoded[2] >> 2); } if (this.encodedSize > 3) { this.decoded[this.decodedSize++] = (byte)((int)this.encoded[2] << 6 | (int)this.encoded[3]); } this.encodedSize = 0; int num3 = Math.Min(outputSize, this.decodedSize); if ((num3 & 2) != 0) { output[outputIndex++] = this.decoded[this.decodedIndex++]; output[outputIndex++] = this.decoded[this.decodedIndex++]; } if ((num3 & 1) != 0) { output[outputIndex++] = this.decoded[this.decodedIndex++]; } outputSize -= num3; this.decodedSize -= num3; if (this.decodedSize == 0) { this.decodedIndex = 0; } } } outputUsed = outputIndex - outputUsed; inputUsed = inputIndex - inputUsed; completed = (num == inputIndex && this.decodedSize == 0 && (!flush || 0 == this.encodedSize)); }