private static void CalculateRootPartitionHeaderSize(out long rootPartitionHeaderSize)
        {
            List <string> entryNameList = new List <string>()
            {
                "update",
                "normal",
                "secure"
            };

            rootPartitionHeaderSize = HashNameEntryPartitionFsHeaderSource <Sha256PartitionFileSystemMeta> .GetDummySize(entryNameList);

            ProdEncryptedXciArchive.CheckAlignmentPageSize(rootPartitionHeaderSize);
        }
        private static void CalculateUpdatePartitionSize(out long updatePartitionHeaderSize, out long updatePartitionSize, NintendoSubmissionPackageFileSystemInfo uppInfo)
        {
            List <string> entryNameList = new List <string>();

            updatePartitionHeaderSize = HashNameEntryPartitionFsHeaderSource <Sha256PartitionFileSystemMeta> .GetDummySize(entryNameList);

            ProdEncryptedXciArchive.CheckAlignmentPageSize(updatePartitionHeaderSize);
            if (uppInfo != null)
            {
                updatePartitionSize = XciInfo.UpdatePartitionLimitSize;
            }
            else
            {
                updatePartitionSize = XciInfo.EmptyUpdatePartitionSize;
            }
        }
        private static void CalculatePartitionSize(out long partitionHeaderSize, out long partitionSize, NintendoSubmissionPackageFileSystemInfo nspInfo, NintendoSubmissionPackageFileSystemInfo patchInfo, bool isNormal, KeyConfiguration keyConfig)
        {
            long          num           = 0;
            List <string> entryNameList = new List <string>();

            for (int index1 = 0; index1 < nspInfo.Entries.Count; ++index1)
            {
                List <Tuple <ISource, NintendoContentInfo> >      contentSourceList = new List <Tuple <ISource, NintendoContentInfo> >();
                NintendoSubmissionPackageFileSystemInfo.EntryInfo entry             = nspInfo.Entries[index1];
                for (int index2 = 0; index2 < entry.Contents.Count; ++index2)
                {
                    NintendoSubmissionPackageFileSystemInfo.ContentInfo content = entry.Contents[index2];
                    if ((!isNormal || !(content.ContentType != "Control")) && !(content.ContentType == "Meta"))
                    {
                        ISource source;
                        if (content.FsInfo != null)
                        {
                            source = (ISource) new NintendoContentArchiveSource(content.FsInfo as NintendoContentFileSystemInfo, keyConfig, false);
                        }
                        else
                        {
                            if (content.Source == null)
                            {
                                throw new NotImplementedException();
                            }
                            source = content.Source;
                        }
                        contentSourceList.Add(Tuple.Create <ISource, NintendoContentInfo>(source, new NintendoContentInfo(content.ContentType, source.Size)));
                        entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nca");
                        num += ProdEncryptedXciArchive.RoundupPageSize(source.Size);
                    }
                }
                entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt.nca");
                NintendoContentMetaArchiveSource metaArchiveSource = new NintendoContentMetaArchiveSource(entry.ContentMetaInfo == null ? new NintendoContentMetaBase(contentSourceList, entry.MetaType, entry.MetaFilePath) : new NintendoContentMetaBase(contentSourceList, entry.ContentMetaInfo.Data, entry.ContentMetaInfo.Model, true), entry.KeyIndex, keyConfig, nspInfo.IsProdEncryption, true);
                num += ProdEncryptedXciArchive.RoundupPageSize(metaArchiveSource.Size);
            }
            partitionHeaderSize = HashNameEntryPartitionFsHeaderSource <Sha256PartitionFileSystemMeta> .GetDummySize(entryNameList);

            ProdEncryptedXciArchive.CheckAlignmentPageSize(partitionHeaderSize);
            partitionSize = num;
        }
Example #4
0
        public NintendoSubmissionPackageArchive(IReadableSink outSink, NintendoSubmissionPackageFileSystemInfo fileSystemInfo, KeyConfiguration config)
        {
            this.ConnectionList = new List <Connection>();
            PartitionFileSystemMeta partitionFileSystemMeta = new PartitionFileSystemMeta();
            List <string>           entryNameList           = new List <string>();

            for (int index1 = 0; index1 < fileSystemInfo.Entries.Count; ++index1)
            {
                for (int index2 = 0; index2 < fileSystemInfo.Entries[index1].Contents.Count; ++index2)
                {
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nca");
                }
                entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt.nca");
                entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt.xml");
                if (NintendoSubmissionPackageArchiveUtils.HasProgramContent(fileSystemInfo.Entries[index1].Contents))
                {
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.programinfo.xml");
                }
                if (this.CheckNeedTicket(fileSystemInfo.Entries[index1]))
                {
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.tik");
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cert");
                }
                if (fileSystemInfo.EnableContentMetaBinaryExport)
                {
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt");
                }
                foreach (NintendoSubmissionPackageExtraData packageExtraData in fileSystemInfo.Entries[index1].ExtraData)
                {
                    entryNameList.Add(packageExtraData.EntryName);
                }
                if (NintendoSubmissionPackageArchiveUtils.HasControlContent(fileSystemInfo.Entries[index1].Contents))
                {
                    entryNameList.Add("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nacp.xml");
                }
                if (fileSystemInfo.Entries[index1].MetaType == "Application")
                {
                    entryNameList.Add("cardspec.xml");
                }
            }
            long dummySize = HashNameEntryPartitionFsHeaderSource <PartitionFileSystemMeta> .GetDummySize(entryNameList);

            long num1 = dummySize;
            List <ContentHashSource> hashSources        = new List <ContentHashSource>();
            List <ProgramInfoXml>    programInfoXmlList = new List <ProgramInfoXml>();
            PartitionFileSystemInfo  rootFsInfo         = new PartitionFileSystemInfo();

            rootFsInfo.version = (int)fileSystemInfo.Version;
            for (int index1 = 0; index1 < fileSystemInfo.Entries.Count; ++index1)
            {
                NintendoSubmissionPackageFileSystemInfo.EntryInfo entry             = fileSystemInfo.Entries[index1];
                List <Tuple <ISource, NintendoContentInfo> >      contentSourceList = new List <Tuple <ISource, NintendoContentInfo> >();
                for (int index2 = 0; index2 < entry.Contents.Count; ++index2)
                {
                    NintendoSubmissionPackageFileSystemInfo.ContentInfo content = entry.Contents[index2];
                    ISource source;
                    if (content.FsInfo != null)
                    {
                        source = (ISource) new NintendoContentArchiveSource(content.FsInfo as NintendoContentFileSystemInfo, config, this.CheckNeedLogoPartition(entry));
                    }
                    else
                    {
                        if (content.Source == null)
                        {
                            throw new NotImplementedException();
                        }
                        source = content.Source;
                    }
                    PartitionFileSystemInfo.EntryInfo entryInfo = PartitionFileSystemInfo.EntryInfo.Make("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nca", (ulong)source.Size, (ulong)(num1 - dummySize));
                    rootFsInfo.entries.Add(entryInfo);
                    IReadableSink outReadableSubSink;
                    this.AddConnection(out outReadableSubSink, source, outSink, num1);
                    SinkLinkedSource sinkLinkedSource = new SinkLinkedSource((ISink)outReadableSubSink, (ISource) new Sha256StreamHashSource(outReadableSubSink.ToSource()));
                    hashSources.Add(new ContentHashSource((ISource)sinkLinkedSource, ".nca", content.ContentType));
                    num1 += source.Size;
                    contentSourceList.Add(Tuple.Create <ISource, NintendoContentInfo>(hashSources[hashSources.Count - 1].Source, new NintendoContentInfo(content.ContentType, source.Size)));
                }
                NintendoContentMetaBase           nintendoContentMetaBase = entry.ContentMetaInfo == null ? new NintendoContentMetaBase(contentSourceList, entry.MetaType, entry.MetaFilePath) : new NintendoContentMetaBase(contentSourceList, entry.ContentMetaInfo.Data, entry.ContentMetaInfo.Model, fileSystemInfo.IsProdEncryption);
                NintendoContentMetaArchiveSource  metaArchiveSource       = new NintendoContentMetaArchiveSource(nintendoContentMetaBase, entry.KeyIndex, config, fileSystemInfo.IsProdEncryption, false);
                PartitionFileSystemInfo.EntryInfo entryInfo1 = PartitionFileSystemInfo.EntryInfo.Make("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt.nca", (ulong)metaArchiveSource.Size, (ulong)(num1 - dummySize));
                rootFsInfo.entries.Add(entryInfo1);
                IReadableSink outReadableSubSink1;
                this.AddConnection(out outReadableSubSink1, (ISource)metaArchiveSource, outSink, num1);
                ISource source1 = (ISource) new SinkLinkedSource((ISink)outReadableSubSink1, (ISource) new Sha256StreamHashSource(outReadableSubSink1.ToSource()));
                hashSources.Add(new ContentHashSource(source1, ".cnmt.nca"));
                long offset1 = num1 + metaArchiveSource.Size;
                NintendoContentMetaXmlSource contentMetaXmlSource = new NintendoContentMetaXmlSource(nintendoContentMetaBase, source1, metaArchiveSource.Size);
                num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt.xml", (ISource)contentMetaXmlSource, offset1, new ContentHashSource(source1, ".cnmt.xml"));
                if (NintendoSubmissionPackageArchiveUtils.HasProgramContent(fileSystemInfo.Entries[index1].Contents))
                {
                    ISource source2 = (ISource) new ProgramInfoXmlSource(NintendoSubmissionPackageArchiveUtils.GetProgramInfoXml(fileSystemInfo.Entries[index1].Contents, config));
                    ISource source3 = hashSources.Where <ContentHashSource>((Func <ContentHashSource, bool>)(x => x.ContentType == "Program")).Select <ContentHashSource, ISource>((Func <ContentHashSource, ISource>)(x => x.Source)).Single <ISource>();
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.programinfo.xml", source2, num1, new ContentHashSource(source3, ".programinfo.xml"));
                }
                if (fileSystemInfo.EnableContentMetaBinaryExport)
                {
                    ISource source2 = nintendoContentMetaBase.GetSource();
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.cnmt", source2, num1, new ContentHashSource(source1, ".cnmt"));
                }
                foreach (NintendoSubmissionPackageExtraData packageExtraData in entry.ExtraData)
                {
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, packageExtraData.EntryName, (ISource)packageExtraData, num1, new ContentHashSource(source1, ".jpg"));
                }
                if (NintendoSubmissionPackageArchiveUtils.HasControlContent(fileSystemInfo.Entries[index1].Contents))
                {
                    ApplicationControlPropertyXmlSource propertyXmlSource = new ApplicationControlPropertyXmlSource(NintendoSubmissionPackageArchiveUtils.GetApplicationControlProperty(fileSystemInfo.Entries[index1].Contents, config));
                    ISource source2 = hashSources.Where <ContentHashSource>((Func <ContentHashSource, bool>)(x => x.ContentType == "Control")).Select <ContentHashSource, ISource>((Func <ContentHashSource, ISource>)(x => x.Source)).Single <ISource>();
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.nacp.xml", (ISource)propertyXmlSource, num1, new ContentHashSource(source2, ".nacp.xml"));
                }
                if (this.CheckNeedTicket(fileSystemInfo.Entries[index1]))
                {
                    ulong num2 = fileSystemInfo.Entries[index1].ContentMetaInfo != null?this.GetApplicationIdFromContentMetaRawData(fileSystemInfo.Entries[index1].ContentMetaInfo.Data) : new DotMetaReader(fileSystemInfo.Entries[index1].MetaFilePath).GetContentMetaId();

                    string rightsIdText = TicketUtility.CreateRightsIdText(num2);
                    Ticket ticket       = new Ticket();
                    ticket.PublishTicket(num2, fileSystemInfo.IsProdEncryption, config);
                    TicketSource            ticketSource      = new TicketSource(ticket.Data, ticket.Length);
                    long                    offset2           = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, rightsIdText + ".tik", (ISource)ticketSource, num1, new ContentHashSource((ISource)null, ".tik"));
                    TicketCertificateSource certificateSource = new TicketCertificateSource(fileSystemInfo.IsProdEncryption, config);
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, rightsIdText + ".cert", (ISource)certificateSource, offset2, new ContentHashSource((ISource)null, ".cert"));
                }
                if (entry.MetaType == "Application")
                {
                    ISource source2 = (ISource) new CardSpecXmlSource(fileSystemInfo, config);
                    num1 = this.RegisterRootEntry(outSink, ref rootFsInfo, dummySize, ref hashSources, "cardspec.xml", source2, num1, new ContentHashSource((ISource)null, ".xml"));
                }
            }
            ISource source4 = (ISource) new HashNameEntryPartitionFsHeaderSource <PartitionFileSystemMeta>(hashSources, rootFsInfo, dummySize);
            ISink   sink    = (ISink) new SubSink((ISink)outSink, 0L, source4.Size);

            this.ConnectionList.Add(new Connection(source4, sink));
            outSink.SetSize(num1);
        }