Esempio n. 1
0
        public async Task Initalize()
        {
            var headerSize = await CiaData.ReadInt32Async(0);

            CiaHeader = new CiaHeader(await CiaData.ReadArrayAsync(0, headerSize));

            var certOffset    = BitMath.Align(headerSize, 64);
            var ticketOffset  = BitMath.Align(certOffset + CiaHeader.CertificateChainSize, 64);
            var tmdOffset     = BitMath.Align(ticketOffset + CiaHeader.TicketSize, 64);
            var contentOffset = BitMath.Align(tmdOffset + CiaHeader.TmdFileSize, 64);
            var metaOffset    = BitMath.Align(contentOffset + CiaHeader.ContentSize, 64);

            TmdMetadata = await TmdMetadata.Load(CiaData.GetReadOnlyDataReference(tmdOffset, CiaHeader.TmdFileSize));

            Partitions = new NcchPartition[TmdMetadata.ContentChunkRecords.Length];
            long partitionStart = contentOffset;

            for (var i = 0; i < TmdMetadata.ContentChunkRecords.Length; i++)
            {
                var chunkRecord     = TmdMetadata.ContentChunkRecords[i];
                var partitionLength = chunkRecord.ContentSize;
                int contentIndex    = chunkRecord.ContentIndex;

                Partitions[i] = await NcchPartition.Load(CiaData.GetReadOnlyDataReference(partitionStart, partitionLength));

                partitionStart += partitionLength;
            }

            IsDlcContainer = TmdMetadata.TitleId >> 32 == 0x0004008C;
        }
Esempio n. 2
0
        public SingleNcchPartitionContainer(NcchPartition partition, int partitionIndex = 0)
        {
            if (partitionIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(partitionIndex), "Partition index must be 0 or greater");
            }

            Partitions = new NcchPartition[partitionIndex + 1];
            Partitions[partitionIndex] = partition ?? throw new ArgumentNullException(nameof(partition));
        }
Esempio n. 3
0
        public async Task Initalize()
        {
            // To-do: determine which NCSD header to use
            Header = new CartridgeNcsdHeader(await NcsdData.ReadArrayAsync(0, 0x1500));

            Partitions = new NcchPartition[Header.Partitions.Length];

            await Task.WhenAll(Enumerable.Range(0, Header.Partitions.Length).Select(async i =>
            {
                var partitionStart  = (long)Header.Partitions[i].Offset * MediaUnitSize;
                var partitionLength = (long)Header.Partitions[i].Length * MediaUnitSize;
                Partitions[i]       = await NcchPartition.Load(NcsdData.GetReadOnlyDataReference(partitionStart, partitionLength));
            }));
        }
Esempio n. 4
0
        public static async Task <NcchPartition> Load(IReadOnlyBinaryDataAccessor data)
        {
            NcchHeader?header = null;

            if (data.Length > 0)
            {
                header = new NcchHeader(await data.ReadArrayAsync(0, 0x200));
            }

            var partition = new NcchPartition(header);
            await partition.Initialize(data);

            return(partition);
        }
Esempio n. 5
0
        public static async Task <NcsdFile> Load(IReadOnlyBinaryDataAccessor data)
        {
            var header     = new CartridgeNcsdHeader(await data.ReadArrayAsync(0, 0x1500));
            var partitions = new NcchPartition[header.Partitions.Length];

            await Task.WhenAll(Enumerable.Range(0, header.Partitions.Length).Select(async i =>
            {
                var partitionStart  = (long)header.Partitions[i].Offset * MediaUnitSize;
                var partitionLength = (long)header.Partitions[i].Length * MediaUnitSize;
                partitions[i]       = await NcchPartition.Load(data.Slice(partitionStart, partitionLength));
            }));

            return(new NcsdFile(header, partitions));
        }