Exemplo n.º 1
0
        public EncryptedStream(Stream output, NpaEntry entry, EncryptionScheme scheme, int arc_key)
        {
            m_read_mode        = false;
            m_encrypted_length = GetEncryptedLength(entry, scheme.TitleId);
            int key = NpaOpener.GetKeyFromEntry(entry, scheme, arc_key);

            m_stream    = output;
            m_encrypted = new Lazy <byte[]> (() => new byte[m_encrypted_length]);
            m_base_pos  = m_stream.Position;

            byte[] decrypt_table = NpaOpener.GenerateKeyTable(scheme);
            byte[] encrypt_table = new byte[256];
            for (int i = 0; i < 256; ++i)
            {
                encrypt_table[decrypt_table[i]] = (byte)i;
            }

            if (NpaTitleId.LAMENTO == scheme.TitleId)
            {
                Encrypt = (i, x) => encrypt_table[(x + key) & 0xff];
            }
            else
            {
                Encrypt = (i, x) => encrypt_table[(x + key + i) & 0xff];
            }
        }
Exemplo n.º 2
0
 public NpaArchive(ArcView arc, ArchiveFormat impl, ICollection <Entry> dir,
                   EncryptionScheme scheme, int key)
     : base(arc, impl, dir)
 {
     Scheme      = scheme;
     Key         = key;
     m_key_table = new Lazy <byte[]> (() => NpaOpener.GenerateKeyTable(scheme));
 }
Exemplo n.º 3
0
        public EncryptedStream(NpaArchive arc, NpaEntry entry)
        {
            m_read_mode        = true;
            m_encrypted_length = GetEncryptedLength(entry, arc.Scheme.TitleId);
            if (m_encrypted_length > entry.Size)
            {
                m_encrypted_length = (int)entry.Size;
            }
            int key = NpaOpener.GetKeyFromEntry(entry, arc.Scheme, arc.Key);

            m_stream    = arc.File.CreateStream(entry.Offset, entry.Size);
            m_encrypted = new Lazy <byte[]> (() => InitEncrypted(key, arc.Scheme.TitleId, arc.KeyTable));
            m_base_pos  = m_stream.Position;
        }
Exemplo n.º 4
0
        public Indexer(IEnumerable <Entry> source_list, NpaOptions options)
        {
            m_entries = new List <NpaEntry> (source_list.Count());
            var title_id = null != options.Scheme ? options.Scheme.TitleId : NpaTitleId.NotEncrypted;

            m_key = NpaOpener.GetArchiveKey(title_id, options.Key1, options.Key2);

            foreach (var entry in source_list)
            {
                string name = entry.Name;
                try
                {
                    var dir       = Path.GetDirectoryName(name);
                    int folder_id = 0;
                    if (!string.IsNullOrEmpty(dir))
                    {
                        folder_id = AddDirectory(dir);
                    }

                    bool compress = options.CompressContents;
                    if (compress) // don't compress images
                    {
                        compress = !FormatCatalog.Instance.LookupFileName(name).OfType <ImageFormat>().Any();
                    }
                    var npa_entry = new NpaEntry
                    {
                        Name     = name,
                        IsPacked = compress,
                        RawName  = m_encoding.GetBytes(name),
                        FolderId = folder_id,
                    };
                    ++m_file_count;
                    AddEntry(npa_entry);
                }
                catch (EncoderFallbackException X)
                {
                    throw new InvalidFileName(name, arcStrings.MsgIllegalCharacters, X);
                }
            }
        }