コード例 #1
0
ファイル: ArcG2.cs プロジェクト: tenyuhuang/GARbro
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var g2ent = entry as G2Entry;

            if (null == g2ent)
            {
                return(base.OpenEntry(arc, entry));
            }

            int entry_size = (int)g2ent.Size;
            int offset     = 0;
            var decoders   = new G2Scheme[4];

            for (int i = 0; i < 4 && offset < entry_size; ++i)
            {
                decoders[i] = G2MetaScheme.CreateInstance(g2ent.Keys[i]);
                if (null != decoders[i])
                {
                    offset += EntryChunkSize;
                }
            }
            var output          = new byte[entry_size];
            var input           = new byte[EntryChunkSize];
            int current_decoder = 0;

            offset = 0;
            while (offset < entry_size)
            {
                int current_chunk_size = Math.Min(EntryChunkSize, entry_size - offset);
                if (null != decoders[current_decoder])
                {
                    arc.File.View.Read(g2ent.Offset + offset, input, 0, (uint)current_chunk_size);
                    decoders[current_decoder].Decrypt(input, 0, output, offset, current_chunk_size);
                }
                else
                {
                    arc.File.View.Read(g2ent.Offset + offset, output, offset, (uint)current_chunk_size);
                }
                current_decoder = (current_decoder + 1) & 3;
                offset         += current_chunk_size;
            }
            return(new MemoryStream(output));
        }
コード例 #2
0
ファイル: ArcG2.cs プロジェクト: Casidi/GARbro
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var g2ent = entry as G2Entry;
            if (null == g2ent)
                return base.OpenEntry (arc, entry);

            int entry_size = (int)g2ent.Size;
            int offset = 0;
            var decoders = new G2Scheme[4];
            for (int i = 0; i < 4 && offset < entry_size; ++i)
            {
                decoders[i] = G2MetaScheme.CreateInstance (g2ent.Keys[i]);
                if (null != decoders[i])
                    offset += EntryChunkSize;
            }
            var output = new byte[entry_size];
            var input = new byte[EntryChunkSize];
            int current_decoder = 0;
            offset = 0;
            while (offset < entry_size)
            {
                int current_chunk_size = Math.Min (EntryChunkSize, entry_size - offset);
                if (null != decoders[current_decoder])
                {
                    arc.File.View.Read (g2ent.Offset+offset, input, 0, (uint)current_chunk_size);
                    decoders[current_decoder].Decrypt (input, 0, output, offset, current_chunk_size);
                }
                else
                {
                    arc.File.View.Read (g2ent.Offset+offset, output, offset, (uint)current_chunk_size);
                }
                current_decoder = (current_decoder + 1) & 3;
                offset += current_chunk_size;
            }
            return new MemoryStream (output);
        }