public static InArchiveFormat CheckSignature(string fileName)
 {
     using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         try
         {
             return(FileChecker.CheckSignature((Stream)fileStream));
         }
         catch (ArgumentException ex)
         {
             return(Formats.FormatByFileName(fileName, true));
         }
     }
 }
Exemplo n.º 2
0
 private void Init(string archiveFullName)
 {
     this._FileName = archiveFullName;
     this._Format   = FileChecker.CheckSignature(archiveFullName);
     SevenZipLibraryManager.LoadLibrary((object)this, (Enum)this._Format);
     try
     {
         this._Archive = SevenZipLibraryManager.InArchive(this._Format, (object)this);
     }
     catch (SevenZipLibraryException ex)
     {
         SevenZipLibraryManager.FreeLibrary((object)this, (Enum)this._Format);
         throw;
     }
 }
Exemplo n.º 3
0
 private void Init(Stream stream)
 {
     SevenZipExtractor.ValidateStream(stream);
     this._Format = FileChecker.CheckSignature(stream);
     SevenZipLibraryManager.LoadLibrary((object)this, (Enum)this._Format);
     try
     {
         this._InStream   = stream;
         this._Archive    = SevenZipLibraryManager.InArchive(this._Format, (object)this);
         this._PackedSize = new long?(stream.Length);
     }
     catch (SevenZipLibraryException ex)
     {
         SevenZipLibraryManager.FreeLibrary((object)this, (Enum)this._Format);
         throw;
     }
 }
        public static InArchiveFormat CheckSignature(Stream stream)
        {
            if (!stream.CanRead)
            {
                throw new ArgumentException("The stream must be readable.");
            }
            if (stream.Length < 16L)
            {
                throw new ArgumentException("The stream is invalid.");
            }
            byte[] buffer = new byte[16];
            int    count  = 16;
            int    offset = 0;

            stream.Seek(0L, SeekOrigin.Begin);
            while (count > 0)
            {
                int num = stream.Read(buffer, offset, count);
                count  -= num;
                offset += num;
            }
            string str = BitConverter.ToString(buffer);

            foreach (string key in Formats.InSignatureFormats.Keys)
            {
                if (str.StartsWith(key, StringComparison.OrdinalIgnoreCase) || str.Substring(6).StartsWith(key, StringComparison.OrdinalIgnoreCase) && Formats.InSignatureFormats[key] == InArchiveFormat.Lzh)
                {
                    return(Formats.InSignatureFormats[key]);
                }
            }
            try
            {
                FileChecker.SpecialDetect(stream, 257, InArchiveFormat.Tar);
            }
            catch (ArgumentException ex)
            {
            }
            if (FileChecker.SpecialDetect(stream, 32769, InArchiveFormat.Iso) || FileChecker.SpecialDetect(stream, 34817, InArchiveFormat.Iso) || FileChecker.SpecialDetect(stream, 36865, InArchiveFormat.Iso))
            {
                return(InArchiveFormat.Iso);
            }
            throw new ArgumentException("The stream is invalid or no corresponding signature was found.");
        }