public void Reset() { gzipHeaderSubstate = GzipHeaderState.ReadingID1; gzipFooterSubstate = GzipHeaderState.ReadingCRC; expectedCrc32 = 0; expectedOutputStreamSizeModulo = 0; }
public void Reset() { this.gzipHeaderSubstate = GzipHeaderState.ReadingID1; this.gzipFooterSubstate = GzipHeaderState.ReadingCRC; this.expectedCrc32 = 0; this.expectedOutputStreamSize = 0; }
public void Reset() { _gzipHeaderSubstate = GzipHeaderState.ReadingID1; _gzipFooterSubstate = GzipHeaderState.ReadingCRC; _expectedCrc32 = 0; _expectedOutputStreamSizeModulo = 0; }
public bool ReadFooter(InputBuffer input) { input.SkipToByteBoundary(); if (gzipFooterSubstate == GzipHeaderState.ReadingCRC) { while (loopCounter < 4) { var bits = input.GetBits(8); if (bits < 0) { return(false); } expectedCrc32 |= (uint)bits << (8 * loopCounter); loopCounter++; } gzipFooterSubstate = GzipHeaderState.ReadingFileSize; loopCounter = 0; } if (gzipFooterSubstate == GzipHeaderState.ReadingFileSize) { if (loopCounter == 0) { expectedOutputStreamSizeModulo = 0; } while (loopCounter < 4) { var bits = input.GetBits(8); if (bits < 0) { return(false); } expectedOutputStreamSizeModulo |= (uint)bits << (8 * loopCounter); loopCounter++; } } return(true); }
public bool ReadFooter(InputBuffer input) { input.SkipToByteBoundary(); if (this.gzipFooterSubstate == GzipHeaderState.ReadingCRC) { while (this.loopCounter < 4) { int bits = input.GetBits(8); if (bits < 0) { return(false); } this.expectedCrc32 |= (uint)(bits << (8 * this.loopCounter)); this.loopCounter++; } this.gzipFooterSubstate = GzipHeaderState.ReadingFileSize; this.loopCounter = 0; } if (this.gzipFooterSubstate == GzipHeaderState.ReadingFileSize) { if (this.loopCounter == 0) { this.expectedOutputStreamSize = 0; } while (this.loopCounter < 4) { int num2 = input.GetBits(8); if (num2 < 0) { return(false); } this.expectedOutputStreamSize |= (uint)(num2 << (8 * this.loopCounter)); this.loopCounter++; } } return(true); }
public bool ReadFooter(InputBuffer input) { input.SkipToByteBoundary(); if (this.gzipFooterSubstate == GzipHeaderState.ReadingCRC) { while (this.loopCounter < 4) { int bits = input.GetBits(8); if (bits < 0) { return false; } this.expectedCrc32 |= (uint) (bits << (8 * this.loopCounter)); this.loopCounter++; } this.gzipFooterSubstate = GzipHeaderState.ReadingFileSize; this.loopCounter = 0; } if (this.gzipFooterSubstate == GzipHeaderState.ReadingFileSize) { if (this.loopCounter == 0) { this.expectedOutputStreamSize = 0; } while (this.loopCounter < 4) { int num2 = input.GetBits(8); if (num2 < 0) { return false; } this.expectedOutputStreamSize |= (uint) (num2 << (8 * this.loopCounter)); this.loopCounter++; } } return true; }
public bool ReadHeader(InputBuffer input) { while (true) { int bits; switch (gzipHeaderSubstate) { case GzipHeaderState.ReadingID1: bits = input.GetBits(8); if (bits < 0) { return false; } if (bits != GZipConstants.ID1) { throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader)); } gzipHeaderSubstate = GzipHeaderState.ReadingID2; goto case GzipHeaderState.ReadingID2; case GzipHeaderState.ReadingID2: bits = input.GetBits(8); if (bits < 0) { return false; } if (bits != GZipConstants.ID2) { throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader)); } gzipHeaderSubstate = GzipHeaderState.ReadingCM; goto case GzipHeaderState.ReadingCM; case GzipHeaderState.ReadingCM: bits = input.GetBits(8); if (bits < 0) { return false; } if (bits != GZipConstants.Deflate) { // compression mode must be 8 (deflate) throw new InvalidDataException(SR.GetString(SR.UnknownCompressionMode)); } gzipHeaderSubstate = GzipHeaderState.ReadingFLG; ; goto case GzipHeaderState.ReadingFLG; case GzipHeaderState.ReadingFLG: bits = input.GetBits(8); if (bits < 0) { return false; } gzip_header_flag = bits; gzipHeaderSubstate = GzipHeaderState.ReadingMMTime; loopCounter = 0; // 4 MMTIME bytes goto case GzipHeaderState.ReadingMMTime; case GzipHeaderState.ReadingMMTime: bits = 0; while (loopCounter < 4) { bits = input.GetBits(8); if (bits < 0) { return false; } loopCounter++; } gzipHeaderSubstate = GzipHeaderState.ReadingXFL; loopCounter = 0; goto case GzipHeaderState.ReadingXFL; case GzipHeaderState.ReadingXFL: // ignore XFL bits = input.GetBits(8); if (bits < 0) { return false; } gzipHeaderSubstate = GzipHeaderState.ReadingOS; goto case GzipHeaderState.ReadingOS; case GzipHeaderState.ReadingOS: // ignore OS bits = input.GetBits(8); if (bits < 0) { return false; } gzipHeaderSubstate = GzipHeaderState.ReadingXLen1; goto case GzipHeaderState.ReadingXLen1; case GzipHeaderState.ReadingXLen1: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.ExtraFieldsFlag) == 0) { goto case GzipHeaderState.ReadingFileName; } bits = input.GetBits(8); if (bits < 0) { return false; } gzip_header_xlen = bits; gzipHeaderSubstate = GzipHeaderState.ReadingXLen2; goto case GzipHeaderState.ReadingXLen2; case GzipHeaderState.ReadingXLen2: bits = input.GetBits(8); if (bits < 0) { return false; } gzip_header_xlen |= (bits << 8); gzipHeaderSubstate = GzipHeaderState.ReadingXLenData; loopCounter = 0; // 0 bytes of XLEN data read so far goto case GzipHeaderState.ReadingXLenData; case GzipHeaderState.ReadingXLenData: bits = 0; while (loopCounter < gzip_header_xlen) { bits = input.GetBits(8); if (bits < 0) { return false; } loopCounter++; } gzipHeaderSubstate = GzipHeaderState.ReadingFileName; loopCounter = 0; goto case GzipHeaderState.ReadingFileName; case GzipHeaderState.ReadingFileName: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.FileNameFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.ReadingComment; goto case GzipHeaderState.ReadingComment; } do { bits = input.GetBits(8); if (bits < 0) { return false; } if (bits == 0) { // see '\0' in the file name string break; } } while (true); gzipHeaderSubstate = GzipHeaderState.ReadingComment; goto case GzipHeaderState.ReadingComment; case GzipHeaderState.ReadingComment: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CommentFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; goto case GzipHeaderState.ReadingCRC16Part1; } do { bits = input.GetBits(8); if (bits < 0) { return false; } if (bits == 0) { // see '\0' in the file name string break; } } while (true); gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; goto case GzipHeaderState.ReadingCRC16Part1; case GzipHeaderState.ReadingCRC16Part1: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CRCFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.Done; goto case GzipHeaderState.Done; } bits = input.GetBits(8); // ignore crc if (bits < 0) { return false; } gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2; goto case GzipHeaderState.ReadingCRC16Part2; case GzipHeaderState.ReadingCRC16Part2: bits = input.GetBits(8); // ignore crc if (bits < 0) { return false; } gzipHeaderSubstate = GzipHeaderState.Done; goto case GzipHeaderState.Done; case GzipHeaderState.Done: return true; default: Debug.Assert(false, "We should not reach unknown state!"); throw new InvalidDataException(SR.GetString(SR.UnknownState)); } } }
public bool ReadFooter(InputBuffer input) { input.SkipToByteBoundary(); if (gzipFooterSubstate == GzipHeaderState.ReadingCRC) { while (loopCounter < 4) { int bits = input.GetBits(8); if (bits < 0) { return false; } expectedCrc32 |= ((uint)bits << (8 * loopCounter)); loopCounter++; } gzipFooterSubstate = GzipHeaderState.ReadingFileSize; loopCounter = 0; } if (gzipFooterSubstate == GzipHeaderState.ReadingFileSize) { if (loopCounter == 0) expectedOutputStreamSizeModulo = 0; while (loopCounter < 4) { int bits = input.GetBits(8); if (bits < 0) { return false; } expectedOutputStreamSizeModulo |= ((uint) bits << (8 * loopCounter)); loopCounter++; } } return true; }
public bool ReadHeader(InputBuffer input) { while (true) { int bits; switch (gzipHeaderSubstate) { case GzipHeaderState.ReadingID1: bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits != GZipConstants.ID1) { throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader)); } gzipHeaderSubstate = GzipHeaderState.ReadingID2; goto case GzipHeaderState.ReadingID2; case GzipHeaderState.ReadingID2: bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits != GZipConstants.ID2) { throw new InvalidDataException(SR.GetString(SR.CorruptedGZipHeader)); } gzipHeaderSubstate = GzipHeaderState.ReadingCM; goto case GzipHeaderState.ReadingCM; case GzipHeaderState.ReadingCM: bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits != GZipConstants.Deflate) { throw new InvalidDataException(SR.GetString(SR.UnknownCompressionMode)); } gzipHeaderSubstate = GzipHeaderState.ReadingFLG; ; goto case GzipHeaderState.ReadingFLG; case GzipHeaderState.ReadingFLG: bits = input.GetBits(8); if (bits < 0) { return(false); } gzip_header_flag = bits; gzipHeaderSubstate = GzipHeaderState.ReadingMMTime; loopCounter = 0; // 4 MMTIME bytes goto case GzipHeaderState.ReadingMMTime; case GzipHeaderState.ReadingMMTime: bits = 0; while (loopCounter < 4) { bits = input.GetBits(8); if (bits < 0) { return(false); } loopCounter++; } gzipHeaderSubstate = GzipHeaderState.ReadingXFL; loopCounter = 0; goto case GzipHeaderState.ReadingXFL; case GzipHeaderState.ReadingXFL: // ignore XFL bits = input.GetBits(8); if (bits < 0) { return(false); } gzipHeaderSubstate = GzipHeaderState.ReadingOS; goto case GzipHeaderState.ReadingOS; case GzipHeaderState.ReadingOS: // ignore OS bits = input.GetBits(8); if (bits < 0) { return(false); } gzipHeaderSubstate = GzipHeaderState.ReadingXLen1; goto case GzipHeaderState.ReadingXLen1; case GzipHeaderState.ReadingXLen1: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.ExtraFieldsFlag) == 0) { goto case GzipHeaderState.ReadingFileName; } bits = input.GetBits(8); if (bits < 0) { return(false); } gzip_header_xlen = bits; gzipHeaderSubstate = GzipHeaderState.ReadingXLen2; goto case GzipHeaderState.ReadingXLen2; case GzipHeaderState.ReadingXLen2: bits = input.GetBits(8); if (bits < 0) { return(false); } gzip_header_xlen |= bits << 8; gzipHeaderSubstate = GzipHeaderState.ReadingXLenData; loopCounter = 0; // 0 bytes of XLEN data read so far goto case GzipHeaderState.ReadingXLenData; case GzipHeaderState.ReadingXLenData: bits = 0; while (loopCounter < gzip_header_xlen) { bits = input.GetBits(8); if (bits < 0) { return(false); } loopCounter++; } gzipHeaderSubstate = GzipHeaderState.ReadingFileName; loopCounter = 0; goto case GzipHeaderState.ReadingFileName; case GzipHeaderState.ReadingFileName: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.FileNameFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.ReadingComment; goto case GzipHeaderState.ReadingComment; } do { bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits == 0) { break; } } while (true); gzipHeaderSubstate = GzipHeaderState.ReadingComment; goto case GzipHeaderState.ReadingComment; case GzipHeaderState.ReadingComment: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CommentFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; goto case GzipHeaderState.ReadingCRC16Part1; } do { bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits == 0) { break; } } while (true); gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; goto case GzipHeaderState.ReadingCRC16Part1; case GzipHeaderState.ReadingCRC16Part1: if ((gzip_header_flag & (int)GZipOptionalHeaderFlags.CRCFlag) == 0) { gzipHeaderSubstate = GzipHeaderState.Done; goto case GzipHeaderState.Done; } bits = input.GetBits(8); // ignore crc if (bits < 0) { return(false); } gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2; goto case GzipHeaderState.ReadingCRC16Part2; case GzipHeaderState.ReadingCRC16Part2: bits = input.GetBits(8); // ignore crc if (bits < 0) { return(false); } gzipHeaderSubstate = GzipHeaderState.Done; goto case GzipHeaderState.Done; case GzipHeaderState.Done: return(true); default: Debug.Assert(false, "We should not reach unknown state!"); throw new InvalidDataException(SR.GetString(SR.UnknownState)); } } }
public bool ReadHeader(InputBuffer input) { int bits; switch (this.gzipHeaderSubstate) { case GzipHeaderState.ReadingID1: bits = input.GetBits(8); if (bits >= 0) { if (bits != 0x1f) { throw new InvalidDataException(SR.GetString("CorruptedGZipHeader")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingID2; break; } return(false); case GzipHeaderState.ReadingID2: break; case GzipHeaderState.ReadingCM: goto Label_00A5; case GzipHeaderState.ReadingFLG: goto Label_00CE; case GzipHeaderState.ReadingMMTime: goto Label_00F1; case GzipHeaderState.ReadingXFL: goto Label_0128; case GzipHeaderState.ReadingOS: goto Label_013D; case GzipHeaderState.ReadingXLen1: goto Label_0152; case GzipHeaderState.ReadingXLen2: goto Label_017B; case GzipHeaderState.ReadingXLenData: goto Label_01A8; case GzipHeaderState.ReadingFileName: goto Label_01E5; case GzipHeaderState.ReadingComment: goto Label_0212; case GzipHeaderState.ReadingCRC16Part1: goto Label_0240; case GzipHeaderState.ReadingCRC16Part2: goto Label_026A; case GzipHeaderState.Done: goto Label_0280; default: throw new InvalidDataException(SR.GetString("UnknownState")); } bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits != 0x8b) { throw new InvalidDataException(SR.GetString("CorruptedGZipHeader")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingCM; Label_00A5: bits = input.GetBits(8); if (bits < 0) { return(false); } if (bits != 8) { throw new InvalidDataException(SR.GetString("UnknownCompressionMode")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingFLG; Label_00CE: bits = input.GetBits(8); if (bits < 0) { return(false); } this.gzip_header_flag = bits; this.gzipHeaderSubstate = GzipHeaderState.ReadingMMTime; this.loopCounter = 0; Label_00F1: bits = 0; while (this.loopCounter < 4) { if (input.GetBits(8) < 0) { return(false); } this.loopCounter++; } this.gzipHeaderSubstate = GzipHeaderState.ReadingXFL; this.loopCounter = 0; Label_0128: if (input.GetBits(8) < 0) { return(false); } this.gzipHeaderSubstate = GzipHeaderState.ReadingOS; Label_013D: if (input.GetBits(8) < 0) { return(false); } this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen1; Label_0152: if ((this.gzip_header_flag & 4) == 0) { goto Label_01E5; } bits = input.GetBits(8); if (bits < 0) { return(false); } this.gzip_header_xlen = bits; this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen2; Label_017B: bits = input.GetBits(8); if (bits < 0) { return(false); } this.gzip_header_xlen |= bits << 8; this.gzipHeaderSubstate = GzipHeaderState.ReadingXLenData; this.loopCounter = 0; Label_01A8: bits = 0; while (this.loopCounter < this.gzip_header_xlen) { if (input.GetBits(8) < 0) { return(false); } this.loopCounter++; } this.gzipHeaderSubstate = GzipHeaderState.ReadingFileName; this.loopCounter = 0; Label_01E5: if ((this.gzip_header_flag & 8) == 0) { this.gzipHeaderSubstate = GzipHeaderState.ReadingComment; } else { do { bits = input.GetBits(8); if (bits < 0) { return(false); } }while (bits != 0); this.gzipHeaderSubstate = GzipHeaderState.ReadingComment; } Label_0212: if ((this.gzip_header_flag & 0x10) == 0) { this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; } else { do { bits = input.GetBits(8); if (bits < 0) { return(false); } }while (bits != 0); this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; } Label_0240: if ((this.gzip_header_flag & 2) == 0) { this.gzipHeaderSubstate = GzipHeaderState.Done; goto Label_0280; } if (input.GetBits(8) < 0) { return(false); } this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2; Label_026A: if (input.GetBits(8) < 0) { return(false); } this.gzipHeaderSubstate = GzipHeaderState.Done; Label_0280: return(true); }
public bool ReadHeader(InputBuffer input) { int bits; switch (this.gzipHeaderSubstate) { case GzipHeaderState.ReadingID1: bits = input.GetBits(8); if (bits >= 0) { if (bits != 0x1f) { throw new InvalidDataException(SR.GetString("CorruptedGZipHeader")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingID2; break; } return false; case GzipHeaderState.ReadingID2: break; case GzipHeaderState.ReadingCM: goto Label_00A5; case GzipHeaderState.ReadingFLG: goto Label_00CE; case GzipHeaderState.ReadingMMTime: goto Label_00F1; case GzipHeaderState.ReadingXFL: goto Label_0128; case GzipHeaderState.ReadingOS: goto Label_013D; case GzipHeaderState.ReadingXLen1: goto Label_0152; case GzipHeaderState.ReadingXLen2: goto Label_017B; case GzipHeaderState.ReadingXLenData: goto Label_01A8; case GzipHeaderState.ReadingFileName: goto Label_01E5; case GzipHeaderState.ReadingComment: goto Label_0212; case GzipHeaderState.ReadingCRC16Part1: goto Label_0240; case GzipHeaderState.ReadingCRC16Part2: goto Label_026A; case GzipHeaderState.Done: goto Label_0280; default: throw new InvalidDataException(SR.GetString("UnknownState")); } bits = input.GetBits(8); if (bits < 0) { return false; } if (bits != 0x8b) { throw new InvalidDataException(SR.GetString("CorruptedGZipHeader")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingCM; Label_00A5: bits = input.GetBits(8); if (bits < 0) { return false; } if (bits != 8) { throw new InvalidDataException(SR.GetString("UnknownCompressionMode")); } this.gzipHeaderSubstate = GzipHeaderState.ReadingFLG; Label_00CE: bits = input.GetBits(8); if (bits < 0) { return false; } this.gzip_header_flag = bits; this.gzipHeaderSubstate = GzipHeaderState.ReadingMMTime; this.loopCounter = 0; Label_00F1: bits = 0; while (this.loopCounter < 4) { if (input.GetBits(8) < 0) { return false; } this.loopCounter++; } this.gzipHeaderSubstate = GzipHeaderState.ReadingXFL; this.loopCounter = 0; Label_0128: if (input.GetBits(8) < 0) { return false; } this.gzipHeaderSubstate = GzipHeaderState.ReadingOS; Label_013D: if (input.GetBits(8) < 0) { return false; } this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen1; Label_0152: if ((this.gzip_header_flag & 4) == 0) { goto Label_01E5; } bits = input.GetBits(8); if (bits < 0) { return false; } this.gzip_header_xlen = bits; this.gzipHeaderSubstate = GzipHeaderState.ReadingXLen2; Label_017B: bits = input.GetBits(8); if (bits < 0) { return false; } this.gzip_header_xlen |= bits << 8; this.gzipHeaderSubstate = GzipHeaderState.ReadingXLenData; this.loopCounter = 0; Label_01A8: bits = 0; while (this.loopCounter < this.gzip_header_xlen) { if (input.GetBits(8) < 0) { return false; } this.loopCounter++; } this.gzipHeaderSubstate = GzipHeaderState.ReadingFileName; this.loopCounter = 0; Label_01E5: if ((this.gzip_header_flag & 8) == 0) { this.gzipHeaderSubstate = GzipHeaderState.ReadingComment; } else { do { bits = input.GetBits(8); if (bits < 0) { return false; } } while (bits != 0); this.gzipHeaderSubstate = GzipHeaderState.ReadingComment; } Label_0212: if ((this.gzip_header_flag & 0x10) == 0) { this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; } else { do { bits = input.GetBits(8); if (bits < 0) { return false; } } while (bits != 0); this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part1; } Label_0240: if ((this.gzip_header_flag & 2) == 0) { this.gzipHeaderSubstate = GzipHeaderState.Done; goto Label_0280; } if (input.GetBits(8) < 0) { return false; } this.gzipHeaderSubstate = GzipHeaderState.ReadingCRC16Part2; Label_026A: if (input.GetBits(8) < 0) { return false; } this.gzipHeaderSubstate = GzipHeaderState.Done; Label_0280: return true; }
public void Reset() { this.gzipHeaderSubstate = GzipHeaderState.ReadingID1; this.gzipFooterSubstate = GzipHeaderState.ReadingCRC; this.expectedCrc32 = 0; this.expectedOutputStreamSize = 0; }