Пример #1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var nsa_arc = arc as NsaEncryptedArchive;

            if (null == nsa_arc)
            {
                var input = arc.File.CreateStream(entry.Offset, entry.Size);
                return(UnpackEntry(input, entry as NsaEntry));
            }
            var encrypted = new EncryptedViewStream(arc.File, nsa_arc.Key);
            var stream    = new StreamRegion(encrypted, entry.Offset, entry.Size);

            return(UnpackEntry(stream, entry as NsaEntry));
        }
Пример #2
0
        public override ArcFile TryOpen(ArcView file)
        {
            List <Entry> dir            = null;
            bool         zero_signature = 0 == file.View.ReadInt16(0);

            try
            {
                using (var input = file.CreateStream())
                {
                    if (zero_signature)
                    {
                        input.Seek(2, SeekOrigin.Begin);
                    }
                    dir = ReadIndex(input);
                    if (null != dir)
                    {
                        return(new ArcFile(file, this, dir));
                    }
                }
            }
            catch { /* ignore parse errors */ }
            if (zero_signature || !file.Name.HasExtension(".nsa"))
            {
                return(null);
            }

            var password = QueryPassword();

            if (string.IsNullOrEmpty(password))
            {
                return(null);
            }
            var key = Encoding.ASCII.GetBytes(password);

            using (var input = new EncryptedViewStream(file, key))
            {
                dir = ReadIndex(input);
                if (null == dir)
                {
                    return(null);
                }
                return(new NsaEncryptedArchive(file, this, dir, key));
            }
        }
Пример #3
0
        public override ArcFile TryOpen(ArcView file)
        {
            List<Entry> dir = null;
            bool zero_signature = 0 == file.View.ReadInt16 (0);
            try
            {
                using (var input = file.CreateStream())
                {
                    if (zero_signature)
                        input.Seek (2, SeekOrigin.Begin);
                    dir = ReadIndex (input);
                    if (null != dir)
                        return new ArcFile (file, this, dir);
                }
            }
            catch { /* ignore parse errors */ }
            if (zero_signature || !file.Name.EndsWith (".nsa", StringComparison.InvariantCultureIgnoreCase))
                return null;

            var password = QueryPassword();
            if (string.IsNullOrEmpty (password))
                return null;
            var key = Encoding.ASCII.GetBytes (password);

            using (var input = new EncryptedViewStream (file, key))
            {
                dir = ReadIndex (input);
                if (null == dir)
                    return null;
                return new NsaEncryptedArchive (file, this, dir, key);
            }
        }
Пример #4
0
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var nsa_arc = arc as NsaEncryptedArchive;
     if (null == nsa_arc)
     {
         var input = arc.File.CreateStream (entry.Offset, entry.Size);
         return UnpackEntry (input, entry as NsaEntry);
     }
     var encrypted = new EncryptedViewStream (arc.File, nsa_arc.Key);
     var stream = new StreamRegion (encrypted, entry.Offset, entry.Size);
     return UnpackEntry (stream, entry as NsaEntry);
 }