Esempio n. 1
0
 private void CalculateHash(ByteData sourceData, long offset, int size)
 {
     if (this.m_sink.QueryStatus().IsFilled)
     {
         throw new InvalidOperationException();
     }
     this.m_sink.PushData(sourceData, offset);
 }
        public ByteData PullData(long offset, int size)
        {
            ByteData srcData   = this.m_source.PullData(offset, size);
            long     dstOffset = (long)this.HashSize * offset / (long)this.m_blockSize;

            this.CalculateAndStoreHash(srcData, dstOffset, this.m_hashLayerCount - 1);
            return(srcData);
        }
        public ByteData PullData(long offset, int size)
        {
            ByteData byteData = this.m_source.PullData(offset, size);

            if (byteData.Buffer.Count % this.BlockSize != 0)
            {
                throw new InvalidOperationException();
            }
            if (offset % (long)this.BlockSize != 0L)
            {
                throw new InvalidOperationException();
            }
            if (byteData.Buffer.Count == 0)
            {
                return(new ByteData(new ArraySegment <byte>()));
            }
            byte[] numArray = new byte[byteData.Buffer.Count];
            int    num1     = 0;
            ArraySegment <byte> buffer;

            while (true)
            {
                int num2 = num1;
                buffer = byteData.Buffer;
                int count = buffer.Count;
                if (num2 < count)
                {
                    IXtsModeEncryptor crypto       = this.m_crypto;
                    byte[]            initialTweak = this.GetInitialTweak(offset + (long)num1);
                    buffer = byteData.Buffer;
                    byte[] array = buffer.Array;
                    buffer = byteData.Buffer;
                    int    srcOffset = buffer.Offset + num1;
                    int    blockSize = this.BlockSize;
                    byte[] dst       = numArray;
                    int    dstOffset = num1;
                    crypto.EncryptBlock(initialTweak, array, srcOffset, blockSize, dst, dstOffset);
                    num1 += this.BlockSize;
                }
                else
                {
                    break;
                }
            }
            byte[] array1  = numArray;
            int    offset1 = 0;

            buffer = byteData.Buffer;
            int count1 = buffer.Count;

            return(new ByteData(new ArraySegment <byte>(array1, offset1, count1)));
        }
Esempio n. 4
0
        public int PushData(ByteData data, long offset)
        {
            int writableSize = SinkUtil.GetWritableSize(this.Size, offset, data.Buffer.Count);

            if (writableSize == 0)
            {
                return(0);
            }
            Buffer.BlockCopy((Array)data.Buffer.Array, data.Buffer.Offset, (Array)this.m_buffer, (int)offset, writableSize);
            this.m_status.FilledRangeList.MergingAdd(new Range(offset, (long)writableSize));
            this.m_status.IsFilled = SinkUtil.CheckIsFilled(this.m_status.FilledRangeList, this.Size);
            return(writableSize);
        }
Esempio n. 5
0
        public int PushData(ByteData data, long offset)
        {
            int writableSize = SinkUtil.GetWritableSize(this.Size, offset, data.Buffer.Count);

            if (writableSize == 0)
            {
                return(0);
            }
            this.m_storage.Write(offset, data.Buffer.Array);
            this.m_storage.Commit();
            this.m_status.FilledRangeList.MergingAdd(new Range(offset, (long)writableSize));
            this.m_status.IsFilled = SinkUtil.CheckIsFilled(this.m_status.FilledRangeList, this.Size);
            return(writableSize);
        }
Esempio n. 6
0
        public int PushData(ByteData data, long offset)
        {
            int count = data.Buffer.Count;

            if (offset + (long)count > this.Size)
            {
                int num = (int)(this.Size - offset);
                count = num > 0 ? num : 0;
            }
            int num1 = this.m_sink.PushData(new ByteData(new ArraySegment <byte>(data.Buffer.Array, data.Buffer.Offset, count)), this.m_offset + offset);

            this.m_status.FilledRangeList.MergingAdd(new Range(offset, (long)num1));
            this.m_status.IsFilled = SinkUtil.CheckIsFilled(this.m_status.FilledRangeList, this.Size);
            return(num1);
        }
Esempio n. 7
0
        public ByteData PullData(long offset, int size)
        {
            this.CheckAlignment(offset);
            int size1 = size;

            if (offset + (long)size1 < this.Size && (size1 & this.AlignmentSize - 1) != 0)
            {
                size1 = size1 / this.AlignmentSize * this.AlignmentSize;
            }
            ByteData byteData = this.m_source.PullData(offset, size1);

            if (offset + (long)byteData.Buffer.Count < this.Size)
            {
                this.CheckAlignment((long)byteData.Buffer.Count);
            }
            return(byteData);
        }
Esempio n. 8
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            ByteData byteData = this.m_source.PullData(this.m_offset, count);

            if (byteData.Buffer.Count == 0)
            {
                return(0);
            }
            Buffer.BlockCopy((Array)byteData.Buffer.Array, byteData.Buffer.Offset, (Array)buffer, offset, byteData.Buffer.Count);
            long offset1 = this.m_offset;
            ArraySegment <byte> buffer1 = byteData.Buffer;
            long count1 = (long)buffer1.Count;

            this.m_offset = offset1 + count1;
            buffer1       = byteData.Buffer;
            return(buffer1.Count);
        }
Esempio n. 9
0
        public ByteData PullData(long offset, int size)
        {
            ByteData byteData = this.m_source.PullData(offset, size);

            if (byteData.Buffer.Count == 0)
            {
                return(new ByteData(new ArraySegment <byte>()));
            }
            ulong num = (ulong)(this.BaseOffset + offset) / (ulong)this.BlockSize;

            byte[] numArray1 = new byte[this.m_crypto.KeySize];
            for (int index = 0; index < 4; ++index)
            {
                numArray1[7 - index] = (byte)(this.Generation >> index * 8 & (int)byte.MaxValue);
            }
            for (int index = 0; index < 8; ++index)
            {
                numArray1[15 - index] = (byte)(num >> index * 8 & (ulong)byte.MaxValue);
            }
            byte[]            numArray2 = new byte[byteData.Buffer.Count];
            ICtrModeEncryptor crypto    = this.m_crypto;

            byte[] iv = numArray1;
            ArraySegment <byte> buffer = byteData.Buffer;

            byte[] array1 = buffer.Array;
            buffer = byteData.Buffer;
            int offset1 = buffer.Offset;

            buffer = byteData.Buffer;
            int count1 = buffer.Count;

            byte[] dst       = numArray2;
            int    dstOffset = 0;

            crypto.EncryptBlock(iv, array1, offset1, count1, dst, dstOffset);
            byte[] array2  = numArray2;
            int    offset2 = 0;

            buffer = byteData.Buffer;
            int count2 = buffer.Count;

            return(new ByteData(new ArraySegment <byte>(array2, offset2, count2)));
        }
Esempio n. 10
0
 public ByteData PullData(long offset, int size)
 {
     if (this.m_buffer == null)
     {
         for (int index = 0; index < this.m_hashSources.Count; ++index)
         {
             if (!(this.m_hashSources[index].Extension != ".nca") || !(this.m_hashSources[index].Extension != ".cnmt.nca") || (!(this.m_hashSources[index].Extension != ".cnmt.xml") || !(this.m_hashSources[index].Extension != ".jpg")) || (!(this.m_hashSources[index].Extension != ".cnmt") || !(this.m_hashSources[index].Extension != ".nacp.xml") || !(this.m_hashSources[index].Extension != ".programinfo.xml")))
             {
                 if (this.m_hashSources[index].Source == null || this.m_hashSources[index].Source.Size != 32L)
                 {
                     throw new InvalidOperationException();
                 }
                 ByteData            byteData = this.m_hashSources[index].Source.PullData(0L, 16);
                 ArraySegment <byte> buffer   = byteData.Buffer;
                 if (buffer.Count != 16)
                 {
                     throw new InvalidOperationException();
                 }
                 buffer = byteData.Buffer;
                 byte[] numArray1 = new byte[buffer.Count];
                 buffer = byteData.Buffer;
                 byte[] array = buffer.Array;
                 buffer = byteData.Buffer;
                 int    offset1   = buffer.Offset;
                 byte[] numArray2 = numArray1;
                 int    dstOffset = 0;
                 buffer = byteData.Buffer;
                 int count = buffer.Count;
                 Buffer.BlockCopy((Array)array, offset1, (Array)numArray2, dstOffset, count);
                 PartitionFileSystemInfo.EntryInfo entry = this.m_partFsInfo.entries[index];
                 entry.name = Regex.Replace(entry.name, "^.{32}", BitConverter.ToString(numArray1).Replace("-", string.Empty).ToLower());
                 this.m_partFsInfo.entries[index] = entry;
             }
         }
         this.m_buffer = Activator.CreateInstance <T>().Create(this.m_partFsInfo);
         if (this.Size != (long)this.m_buffer.Length)
         {
             throw new InvalidOperationException();
         }
     }
     return(new MemorySource(this.m_buffer, 0, this.m_buffer.Length).PullData(offset, size));
 }
        public ByteData PullData(long offset, int size)
        {
            ISource source = this.m_contentMetaBase.GetSource();
            NintendoContentMetaReader  contentMetaReader = new NintendoContentMetaReader(source.PullData(0L, (int)source.Size).Buffer.Array);
            List <NintendoContentInfo> contentInfoList   = contentMetaReader.GetContentInfoList();

            for (int index = 0; index < contentInfoList.Count; ++index)
            {
                NintendoContentInfo nintendoContentInfo = contentInfoList[index];
                this.m_model.ContentList[index].SetIdBytes(nintendoContentInfo.Id);
                this.m_model.ContentList[index].SetHashBytes(nintendoContentInfo.Hash);
            }
            this.m_model.SetDigestBytes(contentMetaReader.GetDigest());
            ByteData byteData = this.m_MetaHashSource.PullData(0L, NintendoContentMeta.GetContentInfoHashSize());

            this.m_MetaModel.SetIdBytes(byteData.Buffer.Array);
            this.m_MetaModel.SetHashBytes(byteData.Buffer.Array);
            byte[] bytes = this.GetBytes();
            return(new MemorySource(bytes, 0, bytes.Length).PullData(offset, size));
        }
        private void CalculateAndStoreHash(ByteData srcData, long dstOffset, int hashLayerCount)
        {
            if (this.m_hierarchicalHashValueSinkList[hashLayerCount].QueryStatus().IsFilled)
            {
                throw new InvalidOperationException();
            }
            int num1 = 0;
            int num2 = 0;

            while (true)
            {
                int num3 = num2;
                ArraySegment <byte> buffer = srcData.Buffer;
                int count1 = buffer.Count;
                if (num3 < count1)
                {
                    buffer = srcData.Buffer;
                    int num4 = Math.Min(buffer.Count - num2, this.m_blockSize);
                    SHA256CryptoServiceProvider hashCalculator = this.m_hashCalculator;
                    buffer = srcData.Buffer;
                    byte[] array = buffer.Array;
                    buffer = srcData.Buffer;
                    int    offset = buffer.Offset + num2;
                    int    count2 = num4;
                    byte[] hash   = hashCalculator.ComputeHash(array, offset, count2);
                    num1 += this.m_hierarchicalHashValueSinkList[hashLayerCount].PushData(new ByteData(new ArraySegment <byte>(hash, 0, hash.Length)), dstOffset + (long)num1);
                    num2 += this.m_blockSize;
                }
                else
                {
                    break;
                }
            }
            if (!this.m_hierarchicalHashValueSinkList[hashLayerCount].QueryStatus().IsFilled || hashLayerCount == 0)
            {
                return;
            }
            ISource source = this.m_hierarchicalHashValueSinkList[hashLayerCount].ToSource();

            this.CalculateAndStoreHash(source.PullData(0L, (int)source.Size), 0L, hashLayerCount - 1);
        }
Esempio n. 13
0
        public ByteData PullData(long offset, int size)
        {
            int count1 = 0;

            byte[] array1  = new byte[size];
            long   offset1 = offset;

            while (count1 != size)
            {
                ConcatenatedSource.Element element = this.GetElement(offset1);
                ByteData            byteData       = element.Source.PullData(offset1 - element.Offset, size - count1);
                ArraySegment <byte> buffer         = byteData.Buffer;
                if (buffer.Count != 0)
                {
                    buffer = byteData.Buffer;
                    byte[] array2 = buffer.Array;
                    buffer = byteData.Buffer;
                    int    offset2   = buffer.Offset;
                    byte[] numArray  = array1;
                    int    dstOffset = count1;
                    buffer = byteData.Buffer;
                    int count2 = buffer.Count;
                    Buffer.BlockCopy((Array)array2, offset2, (Array)numArray, dstOffset, count2);
                    int num1 = count1;
                    buffer = byteData.Buffer;
                    int count3 = buffer.Count;
                    count1 = num1 + count3;
                    long num2 = offset1;
                    buffer = byteData.Buffer;
                    long count4 = (long)buffer.Count;
                    offset1 = num2 + count4;
                }
                else
                {
                    break;
                }
            }
            return(new ByteData(new ArraySegment <byte>(array1, 0, count1)));
        }
Esempio n. 14
0
        public int PushData(ByteData data, long offset)
        {
            int writableSize = SinkUtil.GetWritableSize(this.Size, offset, data.Buffer.Count);

            if (writableSize == 0)
            {
                return(0);
            }
            using (Stream stream1 = (Stream) new SubStream((Stream) new FileStream(this.m_filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.RandomAccess), this.m_offset, this.Size))
            {
                stream1.Seek(offset, SeekOrigin.Begin);
                Stream stream2             = stream1;
                ArraySegment <byte> buffer = data.Buffer;
                byte[] array = buffer.Array;
                buffer = data.Buffer;
                int offset1 = buffer.Offset;
                int count   = writableSize;
                stream2.Write(array, offset1, count);
            }
            this.m_status.FilledRangeList.MergingAdd(new Range(offset, (long)writableSize));
            this.m_status.IsFilled = SinkUtil.CheckIsFilled(this.m_status.FilledRangeList, this.Size);
            return(writableSize);
        }
        public ByteData PullData(long offset, int size)
        {
            if (size % 2 != 0)
            {
                throw new ArgumentException();
            }
            ByteData byteData = this.m_source.PullData(offset, size / 2);

            byte[] numArray1           = new byte[byteData.Buffer.Count];
            byte[] array               = byteData.Buffer.Array;
            ArraySegment <byte> buffer = byteData.Buffer;
            int offset1 = buffer.Offset;

            byte[] numArray2 = numArray1;
            int    dstOffset = 0;

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

            Buffer.BlockCopy((Array)array, offset1, (Array)numArray2, dstOffset, count);
            byte[] bytes = Encoding.ASCII.GetBytes(BitConverter.ToString(numArray1).Replace("-", string.Empty));
            return(new ByteData(new ArraySegment <byte>(bytes, 0, bytes.Length)));
        }
Esempio n. 16
0
        public ByteData PullData(long offset, int size)
        {
            ByteData byteData = this.m_rootPartitionFsHeaderHashSource.PullData(0L, 32);

            this.m_xciInfo.partitionFsHeaderHash = new byte[32];
            ArraySegment <byte> buffer = byteData.Buffer;

            byte[] array1 = buffer.Array;
            buffer = byteData.Buffer;
            int offset1 = buffer.Offset;

            byte[] partitionFsHeaderHash = this.m_xciInfo.partitionFsHeaderHash;
            int    dstOffset             = 0;

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

            Buffer.BlockCopy((Array)array1, offset1, (Array)partitionFsHeaderHash, dstOffset, count);
            byte[] header = this.m_xciMeta.CreateHeader(this.m_xciInfo);
            this.m_headerEncryptor.EncryptBlock(this.m_xciInfo.iv, header, XciMeta.GetEncryptionTargetOffset(), XciMeta.GetEncryptionTargetSize(), header, XciMeta.GetEncryptionTargetOffset());
            byte[] array2 = ((IEnumerable <byte>) this.m_headerSigner.SignBlock(header, 0, header.Length)).Concat <byte>((IEnumerable <byte>)header).ToArray <byte>();
            return(new ByteData(new ArraySegment <byte>(array2, 0, array2.Length)));
        }
Esempio n. 17
0
        public ByteData PullData(long offset, int size)
        {
            ByteData byteData1 = this.m_baseSource.PullData(offset, size);

            foreach (Tuple <ISource, long, long> adaptSourceInfo in this.m_adaptSourceInfos)
            {
                ISource source = adaptSourceInfo.Item1;
                long    num1   = adaptSourceInfo.Item2;
                long    num2   = adaptSourceInfo.Item3;
                if (offset < num1 + num2)
                {
                    long num3 = offset;
                    ArraySegment <byte> buffer = byteData1.Buffer;
                    long count1 = (long)buffer.Count;
                    if (num3 + count1 > num1)
                    {
                        ByteData byteData2 = source.PullData(0L, (int)num2);
                        buffer = byteData2.Buffer;
                        if (buffer.Count == 0)
                        {
                            buffer = new ArraySegment <byte>();
                            return(new ByteData(buffer));
                        }
                        buffer = byteData2.Buffer;
                        if ((long)buffer.Count != num2)
                        {
                            throw new InvalidOperationException();
                        }
                        long num4 = num1 + num2;
                        long num5 = offset;
                        buffer = byteData1.Buffer;
                        long count2 = (long)buffer.Count;
                        long num6   = num5 + count2;
                        bool flag1  = num4 <= num6;
                        bool flag2  = num1 >= offset;
                        int  num7   = 0;
                        int  num8   = 0;
                        int  num9   = 0;
                        if (flag2 & flag1)
                        {
                            num7 = (int)(num1 - offset);
                            num8 = 0;
                            num9 = (int)num2;
                        }
                        else if (flag2 && !flag1)
                        {
                            num7 = (int)(num1 - offset);
                            num8 = 0;
                            long num10 = offset;
                            buffer = byteData1.Buffer;
                            long count3 = (long)buffer.Count;
                            num9 = (int)(num10 + count3 - num1);
                        }
                        else if (!flag2 & flag1)
                        {
                            num7 = 0;
                            num8 = (int)(offset - num1);
                            num9 = (int)(num2 - (long)num8);
                        }
                        else if (!flag2 && !flag1)
                        {
                            num7   = 0;
                            num8   = (int)(offset - num1);
                            buffer = byteData1.Buffer;
                            num9   = buffer.Count;
                        }
                        buffer = byteData2.Buffer;
                        byte[] array1 = buffer.Array;
                        buffer = byteData2.Buffer;
                        int srcOffset = buffer.Offset + num8;
                        buffer = byteData1.Buffer;
                        byte[] array2 = buffer.Array;
                        buffer = byteData1.Buffer;
                        int dstOffset = buffer.Offset + num7;
                        int count4    = num9;
                        Buffer.BlockCopy((Array)array1, srcOffset, (Array)array2, dstOffset, count4);
                    }
                }
            }
            return(byteData1);
        }
Esempio n. 18
0
        public void Run()
        {
            SourceStatus sourceStatus = new SourceStatus();
            bool         flag1        = false;

            while (!flag1)
            {
                bool flag2 = false;
                foreach (Connection connection in this.m_connectionList)
                {
                    foreach (Range duplicatedDeleted in (List <Range>)connection.Source.QueryStatus().AvailableRangeList.GetDuplicatedDeletedList(connection.Sink.QueryStatus().FilledRangeList))
                    {
                        long   num1   = 0;
                        int    length = 8388608;
                        byte[] array1 = new byte[length];
                        long   num2   = 0;
                        while (num1 < duplicatedDeleted.Size)
                        {
                            int                 size  = (int)Math.Min(duplicatedDeleted.Size - num1 - num2, (long)length);
                            ByteData            data1 = connection.Source.PullData(duplicatedDeleted.Offset + num1 + num2, size);
                            ArraySegment <byte> buffer;
                            if (num2 + (long)data1.Buffer.Count <= (long)length)
                            {
                                buffer = data1.Buffer;
                                if (buffer.Count != 0 || num2 == 0L)
                                {
                                    goto label_9;
                                }
                            }
                            num1  += (long)connection.Sink.PushData(new ByteData(new ArraySegment <byte>(array1, 0, (int)num2)), duplicatedDeleted.Offset + num1);
                            num2   = 0L;
                            buffer = data1.Buffer;
                            if (buffer.Count == 0)
                            {
                                continue;
                            }
label_9:
                            buffer = data1.Buffer;
                            if (buffer.Count == size)
                            {
                                if (0L < num2)
                                {
                                    buffer = data1.Buffer;
                                    byte[] array2    = buffer.Array;
                                    int    srcOffset = 0;
                                    byte[] numArray  = array1;
                                    int    dstOffset = (int)num2;
                                    buffer = data1.Buffer;
                                    int count1 = buffer.Count;
                                    Buffer.BlockCopy((Array)array2, srcOffset, (Array)numArray, dstOffset, count1);
                                    long   num3    = num1;
                                    ISink  sink    = connection.Sink;
                                    byte[] array3  = array1;
                                    int    offset1 = 0;
                                    int    num4    = (int)num2;
                                    buffer = data1.Buffer;
                                    int      count2  = buffer.Count;
                                    int      count3  = num4 + count2;
                                    ByteData data2   = new ByteData(new ArraySegment <byte>(array3, offset1, count3));
                                    long     offset2 = duplicatedDeleted.Offset + num1;
                                    long     num5    = (long)sink.PushData(data2, offset2);
                                    num1 = num3 + num5;
                                    num2 = 0L;
                                }
                                else
                                {
                                    num1 += (long)connection.Sink.PushData(data1, duplicatedDeleted.Offset + num1);
                                }
                            }
                            else
                            {
                                buffer = data1.Buffer;
                                byte[] array2    = buffer.Array;
                                int    srcOffset = 0;
                                byte[] numArray  = array1;
                                int    dstOffset = (int)num2;
                                buffer = data1.Buffer;
                                int count1 = buffer.Count;
                                Buffer.BlockCopy((Array)array2, srcOffset, (Array)numArray, dstOffset, count1);
                                long num3 = num2;
                                buffer = data1.Buffer;
                                long count2 = (long)buffer.Count;
                                num2 = num3 + count2;
                            }
                        }
                        if (num1 > 0L)
                        {
                            flag2 = true;
                        }
                    }
                }
                flag1 = true;
                foreach (Connection connection in this.m_connectionList)
                {
                    if (!connection.Sink.QueryStatus().IsFilled)
                    {
                        flag1 = false;
                        break;
                    }
                }
                if (!flag1 && !flag2)
                {
                    throw new ApplicationException("Failed to resolve dependencies for archiving. Please contact to NintendoSDK support.");
                }
            }
        }
        internal static NintendoSubmissionPackageFileSystemInfo GetReplacedNspInfo(NintendoSubmissionPackageReader nspReader, ISource inSource, string targetEntryPath, string descFilePath, KeyConfiguration keyConfig)
        {
            bool isReplaced = false;

            ArchiveReconstructionUtils.GetContentInfoDelegate getContentInfoImpl = (ArchiveReconstructionUtils.GetContentInfoDelegate)(contentInfo =>
            {
                NintendoSubmissionPackageFileSystemInfo.ContentInfo contentInfo1 = new NintendoSubmissionPackageFileSystemInfo.ContentInfo();
                string fileName = contentInfo.Id + ".nca";
                NintendoContentArchiveReader ncaReader = nspReader.OpenNintendoContentArchiveReader(fileName, keyConfig.GetKeyAreaEncryptionKeys());
                if (targetEntryPath.StartsWith(fileName))
                {
                    contentInfo1.FsInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)ArchiveReconstructionUtils.GetReplacedNcaInfo(ncaReader, descFilePath, new EntryReplaceRule()
                    {
                        Source = inSource,
                        Path   = targetEntryPath.Substring(fileName.Length + 1)
                    });
                    isReplaced = true;
                }
                else
                {
                    contentInfo1.Source = (ISource) new FileSystemArchvieFileSource((IFileSystemArchiveReader)nspReader, fileName);
                }
                contentInfo1.ContentType = contentInfo.Type;
                return(contentInfo1);
            });
            ArchiveReconstructionUtils.GetContentMetaInfoDelegate getContentMetaInfoImpl = (ArchiveReconstructionUtils.GetContentMetaInfoDelegate)((ref NintendoSubmissionPackageFileSystemInfo.EntryInfo entry, string contentMetaFileName, ContentMetaModel model) =>
            {
                ArchiveReconstructionUtils.GetCommonContentMetaInfo(ref entry, contentMetaFileName, model, nspReader, keyConfig);
                if (!targetEntryPath.StartsWith(contentMetaFileName) || !targetEntryPath.EndsWith(".cnmt"))
                {
                    return;
                }
                NintendoContentMetaReader contentMetaReader1 = new NintendoContentMetaReader(entry.ContentMetaInfo.Data);
                ulong id1     = contentMetaReader1.GetId();
                uint version1 = contentMetaReader1.GetVersion();
                if (inSource.Size != (long)entry.ContentMetaInfo.Data.Length)
                {
                    throw new Exception(".cnmt file specified to be replaced is invalid.");
                }
                ByteData byteData          = inSource.PullData(0L, (int)inSource.Size);
                ArraySegment <byte> buffer = byteData.Buffer;
                byte[] array = buffer.Array;
                buffer = byteData.Buffer;
                int offset    = buffer.Offset;
                byte[] data   = entry.ContentMetaInfo.Data;
                int dstOffset = 0;
                int count     = byteData.Buffer.Count;
                Buffer.BlockCopy((Array)array, offset, (Array)data, dstOffset, count);
                NintendoContentMetaReader contentMetaReader2 = new NintendoContentMetaReader(entry.ContentMetaInfo.Data);
                ulong id2 = contentMetaReader2.GetId();
                if ((long)id1 != (long)id2)
                {
                    throw new ArgumentException(string.Format("Ids of content meta are different. (oldId = {0:x16}, newID = {0:x16})", (object)id1, (object)id2));
                }
                uint version2 = contentMetaReader2.GetVersion();
                Log.Info(string.Format("content meta (ID = {0:x16}) will be replaced : version {1} -> {2}", (object)id1, (object)version1, (object)version2));
                isReplaced = true;
            });
            NintendoSubmissionPackageFileSystemInfo nspInfo = ArchiveReconstructionUtils.GetNspInfo(nspReader, keyConfig, getContentInfoImpl, getContentMetaInfoImpl);

            if (isReplaced)
            {
                return(nspInfo);
            }
            throw new Exception("nothing was replaced.");
        }
Esempio n. 20
0
 public int PushData(ByteData data, long offset)
 {
     return(data.Buffer.Count);
 }