Exemple #1
0
 public NpkStream(NpkArchive arc, NpkEntry entry)
 {
     m_file       = arc.File;
     m_encryption = arc.Encryption;
     m_segment    = entry.Segments.GetEnumerator();
     NextSegment();
 }
Exemple #2
0
        public override ArcFile TryOpen(ArcView file)
        {
            int count = file.View.ReadInt32(0x18);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            var key = QueryEncryption(file.Name);

            if (null == key)
            {
                return(null);
            }
            var aes = Aes.Create();

            try
            {
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.PKCS7;
                aes.Key     = key;
                aes.IV      = file.View.ReadBytes(8, 0x10);
                uint index_size = file.View.ReadUInt32(0x1C);
                using (var decryptor = aes.CreateDecryptor())
                    using (var enc_index = file.CreateStream(0x20, index_size))
                        using (var dec_index = new CryptoStream(enc_index, decryptor, CryptoStreamMode.Read))
                            using (var index = new ArcView.Reader(dec_index))
                            {
                                var dir = ReadIndex(index, count, file.MaxOffset);
                                if (null == dir)
                                {
                                    return(null);
                                }
                                var arc = new NpkArchive(file, this, dir, aes);
                                aes = null; // object ownership passed to NpkArchive, don't dispose
                                return(arc);
                            }
            }
            finally
            {
                if (aes != null)
                {
                    aes.Dispose();
                }
            }
        }
Exemple #3
0
 public NpkStream(NpkArchive arc, NpkEntry entry)
 {
     m_file = arc.File;
     m_encryption = arc.Encryption;
     m_segment = entry.Segments.GetEnumerator();
     NextSegment();
 }
Exemple #4
0
 public override ArcFile TryOpen(ArcView file)
 {
     int count = file.View.ReadInt32 (0x18);
     if (!IsSaneCount (count))
         return null;
     var key = QueryEncryption();
     if (null == key)
         return null;
     var aes = Aes.Create();
     try
     {
         aes.Mode = CipherMode.CBC;
         aes.Padding = PaddingMode.PKCS7;
         aes.Key = key;
         aes.IV = file.View.ReadBytes (8, 0x10);
         uint index_size = file.View.ReadUInt32 (0x1C);
         using (var decryptor = aes.CreateDecryptor())
         using (var enc_index = file.CreateStream (0x20, index_size))
         using (var dec_index = new CryptoStream (enc_index, decryptor, CryptoStreamMode.Read))
         using (var index = new ArcView.Reader (dec_index))
         {
             var dir = ReadIndex (index, count, file.MaxOffset);
             if (null == dir)
                 return null;
             var arc = new NpkArchive (file, this, dir, aes);
             aes = null; // object ownership passed to NpkArchive, don't dispose
             return arc;
         }
     }
     finally
     {
         if (aes != null)
             aes.Dispose();
     }
 }