private static NintendoContentFileSystemInfo.EntryInfo GetFsEntry(NintendoContentArchiveReader ncaReader, int fsIndex, EntryReplaceRule replaceRule)
        {
            NintendoContentArchiveFsHeaderInfo fsInfo = (NintendoContentArchiveFsHeaderInfo)null;
            IFileSystemArchiveReader           systemArchiveReader = ncaReader.OpenFileSystemArchiveReader(fsIndex, ref fsInfo);

            NintendoContentFileSystemInfo.EntryInfo commonFsEntry = ArchiveReconstructionUtils.GetCommonFsEntry(fsInfo, fsIndex);
            Tuple <long, long> tuple = systemArchiveReader.GetFileFragmentList(replaceRule.Path).First <Tuple <long, long> >();
            long offset = tuple.Item1;

            if (tuple.Item2 == replaceRule.Source.Size)
            {
                AdaptedSource adaptedSource = new AdaptedSource((ISource) new FileSystemArchvieBaseSource(systemArchiveReader), replaceRule.Source, offset, replaceRule.Source.Size);
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)adaptedSource);
            }
            else if (commonFsEntry.formatType == "RomFs")
            {
                RomFsArchiveSource romFsArchiveSource = new RomFsArchiveSource(ArchiveReconstructionUtils.GetRomFsInfo(systemArchiveReader, replaceRule));
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)romFsArchiveSource);
            }
            else if (commonFsEntry.formatType == "PartitionFs")
            {
                PartitionFsArchiveSource partitionFsArchiveSource = new PartitionFsArchiveSource(ArchiveReconstructionUtils.GetPartitionFsInfo(systemArchiveReader, replaceRule));
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)partitionFsArchiveSource);
            }
            return(commonFsEntry);
        }
        public ProdEncryptedXciArchive(ISink outSink, ISource xciSource, KeyConfiguration keyConfig)
        {
            this.ConnectionList = new List <Connection>();
            this.m_rng          = new RNGCryptoServiceProvider();
            this.m_keyConfig    = keyConfig;
            this.SetCryptor(this.m_keyConfig);
            byte[]              keyArea  = new byte[(int)XciInfo.PageSize * (int)XciInfo.CardKeyAreaPageCount];
            ByteData            byteData = xciSource.PullData(0L, (int)XciInfo.PageSize * (int)XciInfo.CardKeyAreaPageCount);
            ArraySegment <byte> buffer1  = byteData.Buffer;

            byte[] array = buffer1.Array;
            buffer1 = byteData.Buffer;
            int offset = buffer1.Offset;

            byte[] numArray  = keyArea;
            int    dstOffset = 0;

            buffer1 = byteData.Buffer;
            int count = buffer1.Count;

            Buffer.BlockCopy((Array)array, offset, (Array)numArray, dstOffset, count);
            byte[]        buffer2       = this.EncryptKeyArea(keyArea);
            MemorySource  memorySource  = new MemorySource(buffer2, 0, buffer2.Length);
            AdaptedSource adaptedSource = new AdaptedSource(xciSource, (ISource)memorySource, 0L, memorySource.Size);

            outSink.SetSize(adaptedSource.Size);
            this.ConnectionList.Add(new Connection((ISource)adaptedSource, outSink));
        }