Пример #1
0
 public TarEntry GetNextEntry()
 {
     if (hasHitEOF)
     {
         return(null);
     }
     if (currentEntry != null)
     {
         SkipToNextEntry();
     }
     byte[] array = tarBuffer.ReadBlock();
     if (array == null)
     {
         hasHitEOF = true;
     }
     else
     {
         hasHitEOF |= TarBuffer.IsEndOfArchiveBlock(array);
     }
     if (!hasHitEOF)
     {
         try
         {
             TarHeader tarHeader = new TarHeader();
             tarHeader.ParseBuffer(array);
             if (!tarHeader.IsChecksumValid)
             {
                 throw new TarException("Header checksum is invalid");
             }
             entryOffset = 0L;
             entrySize   = tarHeader.Size;
             StringBuilder stringBuilder = null;
             if (tarHeader.TypeFlag == 76)
             {
                 byte[] array2 = new byte[512];
                 long   num    = entrySize;
                 stringBuilder = new StringBuilder();
                 while (num > 0)
                 {
                     int num2 = Read(array2, 0, (int)((num > array2.Length) ? array2.Length : num));
                     if (num2 == -1)
                     {
                         throw new InvalidHeaderException("Failed to read long name entry");
                     }
                     stringBuilder.Append(TarHeader.ParseName(array2, 0, num2).ToString());
                     num -= num2;
                 }
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 103)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 120)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 86)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag != 48 && tarHeader.TypeFlag != 0 && tarHeader.TypeFlag != 49 && tarHeader.TypeFlag != 50 && tarHeader.TypeFlag != 53)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             if (entryFactory == null)
             {
                 currentEntry = new TarEntry(array);
                 if (stringBuilder != null)
                 {
                     currentEntry.Name = stringBuilder.ToString();
                 }
             }
             else
             {
                 currentEntry = entryFactory.CreateEntry(array);
             }
             entryOffset = 0L;
             entrySize   = currentEntry.Size;
         }
         catch (InvalidHeaderException ex)
         {
             entrySize    = 0L;
             entryOffset  = 0L;
             currentEntry = null;
             throw new InvalidHeaderException($"Bad header in record {tarBuffer.CurrentRecord} block {tarBuffer.CurrentBlock} {ex.Message}");
         }
     }
     else
     {
         currentEntry = null;
     }
     return(currentEntry);
 }
Пример #2
0
 public TarEntry GetNextEntry()
 {
     //IL_00a6: Unknown result type (might be due to invalid IL or missing references)
     //IL_00ac: Expected O, but got Unknown
     if (hasHitEOF)
     {
         return(null);
     }
     if (currentEntry != null)
     {
         SkipToNextEntry();
     }
     byte[] array = tarBuffer.ReadBlock();
     if (array == null)
     {
         hasHitEOF = true;
     }
     else if (TarBuffer.IsEndOfArchiveBlock(array))
     {
         hasHitEOF = true;
     }
     if (hasHitEOF)
     {
         currentEntry = null;
     }
     else
     {
         try
         {
             TarHeader tarHeader = new TarHeader();
             tarHeader.ParseBuffer(array);
             if (!tarHeader.IsChecksumValid)
             {
                 throw new TarException("Header checksum is invalid");
             }
             entryOffset = 0L;
             entrySize   = tarHeader.Size;
             StringBuilder val = null;
             if (tarHeader.TypeFlag == 76)
             {
                 byte[] array2 = new byte[512];
                 long   num    = entrySize;
                 val = new StringBuilder();
                 while (num > 0)
                 {
                     int num2 = ((Stream)this).Read(array2, 0, (int)((num > array2.Length) ? array2.Length : num));
                     if (num2 == -1)
                     {
                         throw new InvalidHeaderException("Failed to read long name entry");
                     }
                     val.Append(((object)TarHeader.ParseName(array2, 0, num2)).ToString());
                     num -= num2;
                 }
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 103)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 120)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 86)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag != 48 && tarHeader.TypeFlag != 0 && tarHeader.TypeFlag != 53)
             {
                 SkipToNextEntry();
                 array = tarBuffer.ReadBlock();
             }
             if (entryFactory == null)
             {
                 currentEntry = new TarEntry(array);
                 if (val != null)
                 {
                     currentEntry.Name = ((object)val).ToString();
                 }
             }
             else
             {
                 currentEntry = entryFactory.CreateEntry(array);
             }
             entryOffset = 0L;
             entrySize   = currentEntry.Size;
         }
         catch (InvalidHeaderException ex)
         {
             entrySize    = 0L;
             entryOffset  = 0L;
             currentEntry = null;
             string message = $"Bad header in record {tarBuffer.CurrentRecord} block {tarBuffer.CurrentBlock} {((global::System.Exception)(object)ex).get_Message()}";
             throw new InvalidHeaderException(message);
         }
     }
     return(currentEntry);
 }