Пример #1
0
 /// <summary>
 /// Instantiate ark package file from input .hdr file.
 /// Note: will check for data files and throw exception if they're not found.
 /// </summary>
 /// <param name="pathToHdr">Full path to .hdr file</param>
 public ArkPackage(IFile hdrFile)
 {
     FileName = hdrFile.Name;
     using (var hdr = hdrFile.GetStream())
     {
         Stream actualHdr = hdr;
         uint   version   = hdr.ReadUInt32LE();
         if (version > HIGHEST_VERSION && version != ARK)
         {
             // hdr is encrypted, probably
             using (var decryptor = new HdrCryptStream(hdr))
             {
                 byte[] arr = new byte[decryptor.Length];
                 decryptor.Read(arr, 0, (int)decryptor.Length);
                 actualHdr = new MemoryStream(arr);
             }
             version = actualHdr.ReadUInt32LE();
         }
         if (version == ARK)
         {
             readOldArkHeader(hdrFile, actualHdr);
         }
         else if (version <= HIGHEST_VERSION && version >= LOWEST_VERSION)
         {
             readHeader(actualHdr, hdrFile, version);
         }
         else
         {
             throw new NotSupportedException($"Given ark file is not supported. (version {version}).");
         }
     }
 }
Пример #2
0
        public static PackageTestResult IsArk(IFile fn)
        {
            if (!fn.Name.ToLower().EndsWith(".hdr") && !fn.Name.ToLower().EndsWith(".ark"))
            {
                return(PackageTestResult.NO);
            }

            using (Stream s = fn.GetStream())
            {
                s.Position = 0;
                uint version = s.ReadUInt32LE();
                if (version == ARK) // header from Frequency
                {
                    return(PackageTestResult.YES);
                }
                if (version > HIGHEST_VERSION)
                {
                    // hdr is encrypted, probably
                    using (var decryptor = new HdrCryptStream(s))
                    {
                        version = decryptor.ReadUInt32LE();
                    }
                    if (version == 0xFFFFFFF5)
                    {
                        version = 10;
                    }
                    else if (version == 0xFFFFFFF6)
                    {
                        version = 9;
                    }
                    else if (version == 0xFFFFFFF7)
                    {
                        version = 8;                   // Hopefully?
                    }
                }
                return(version <= HIGHEST_VERSION &&
                       version >= LOWEST_VERSION ? PackageTestResult.MAYBE : PackageTestResult.NO);
            }
        }
Пример #3
0
 public static PackageTestResult IsArk(IFile fn)
 {
     using (Stream s = fn.GetStream())
     {
         s.Position = 0;
         uint version = s.ReadUInt32LE();
         if (version == ARK) // header from Frequency
         {
             return(PackageTestResult.YES);
         }
         if (version > HIGHEST_VERSION)
         {
             // hdr is encrypted, probably
             using (var decryptor = new HdrCryptStream(s))
             {
                 version = decryptor.ReadUInt32LE();
             }
         }
         return(version <= HIGHEST_VERSION &&
                version >= LOWEST_VERSION ? PackageTestResult.MAYBE : PackageTestResult.NO);
     }
 }