internal NintendoContentMetaBaseSource(NintendoContentMetaBase contentMetaBase, bool isUpdateDigest) { this.m_isUpdateDigest = isUpdateDigest; this.m_contentMetaBase = contentMetaBase; byte[] bytes = contentMetaBase.GetBytes(); ISource source = (ISource) new MemorySource(bytes, 0, bytes.Length); List <ISource> list = contentMetaBase.GetContentSourceList().Select <Tuple <ISource, NintendoContentInfo>, ISource>((Func <Tuple <ISource, NintendoContentInfo>, ISource>)(tuple => tuple.Item1)).ToList <ISource>(); for (int index = 0; index < list.Count; ++index) { long contentInfoIdDataSize = contentMetaBase.GetContentInfoIdDataSize(); long infoIdDataOffset = contentMetaBase.GetContentInfoIdDataOffset(index); ISource baseSource = (ISource) new AdaptedSource(source, (ISource) new SubSource(list[index], 0L, contentInfoIdDataSize), infoIdDataOffset, contentInfoIdDataSize); long contentInfoHashSize = contentMetaBase.GetContentInfoHashSize(); long contentInfoHashOffset = contentMetaBase.GetContentInfoHashOffset(index); source = (ISource) new AdaptedSource(baseSource, list[index], contentInfoHashOffset, contentInfoHashSize); } if (isUpdateDigest) { long digestSize = contentMetaBase.GetDigestSize(); long digestOffset = contentMetaBase.GetDigestOffset(); source = (ISource) new AdaptedSource(source, (ISource) new Sha256StreamHashSource((ISource) new SubSource(source, 0L, digestOffset)), digestOffset, digestSize); } this.m_source = source; this.Size = this.m_source.Size; }
public NintendoContentMetaXmlSource(NintendoContentMetaBase contentMetaBase, ISource metaHashSource, long metaSize) { this.m_contentMetaBase = contentMetaBase; this.m_MetaHashSource = metaHashSource; NintendoContentMetaReader contentMetaReader = new NintendoContentMetaReader(contentMetaBase.GetBytes()); ContentMetaModel contentMetaModel1 = this.PrepareContentMetaModel(contentMetaBase.GetContentMetaDescryptor()); contentMetaModel1.Type = contentMetaReader.GetType(); contentMetaModel1.SetUInt64Id(contentMetaReader.GetId()); contentMetaModel1.Version = contentMetaReader.GetVersion(); contentMetaModel1.AttributeList = ((ContentMetaAttribute)contentMetaReader.GetAttributes()).ToStringList(); contentMetaModel1.RequiredDownloadSystemVersion = contentMetaReader.GetRequiredDownloadSystemVersion(); byte[] bytes1 = new byte[NintendoContentMeta.GetDigestSize()]; contentMetaModel1.SetDigestBytes(bytes1); List <NintendoContentInfo> contentInfoList = contentMetaReader.GetContentInfoList(); if (contentInfoList.Count > 0) { contentMetaModel1.ContentList = new List <ContentModel>(); foreach (NintendoContentInfo nintendoContentInfo in contentInfoList) { ContentModel contentModel = new ContentModel(); contentModel.Type = nintendoContentInfo.Type; contentModel.Size = nintendoContentInfo.Size; byte[] bytes2 = new byte[NintendoContentMeta.GetContentInfoHashSize()]; contentModel.SetIdBytes(bytes2); contentModel.SetHashBytes(bytes2); contentMetaModel1.ContentList.Add(contentModel); } } contentMetaModel1.ContentList = contentMetaModel1.ContentList ?? new List <ContentModel>(); this.m_MetaModel = new ContentModel(); contentMetaModel1.ContentList.Add(this.m_MetaModel); this.m_MetaModel.Type = "Meta"; this.m_MetaModel.Size = metaSize; byte[] bytes3 = new byte[NintendoContentMeta.GetContentInfoHashSize()]; this.m_MetaModel.SetIdBytes(bytes3); this.m_MetaModel.SetHashBytes(bytes3); List <NintendoContentMetaInfo> contentMetaInfoList = contentMetaReader.GetContentMetaInfoList(); if (contentMetaInfoList.Count > 0) { contentMetaModel1.ContentMetaList = new List <ContentMetaModel>(); foreach (NintendoContentMetaInfo nintendoContentMetaInfo in contentMetaInfoList) { ContentMetaModel contentMetaModel2 = new ContentMetaModel(); contentMetaModel2.Type = nintendoContentMetaInfo.Type; contentMetaModel2.SetUInt64Id(nintendoContentMetaInfo.Id); contentMetaModel2.Version = nintendoContentMetaInfo.Version; contentMetaModel2.AttributeList = ((ContentMetaAttribute)nintendoContentMetaInfo.Attributes).ToStringList(); contentMetaModel1.ContentMetaList.Add(contentMetaModel2); } } this.m_model = contentMetaModel1; this.Size = (long)this.GetBytes().Length; }
internal NintendoContentMetaArchiveSource(NintendoContentMetaBase contentMeta, int keyEncryptionKeyIndex, KeyConfiguration config, bool isProdEncryption, bool isGameCard) { NintendoContentMetaReader contentMetaReader = new NintendoContentMetaReader(contentMeta.GetBytes()); ISource source1 = contentMeta.GetSource(); PartitionFileSystemInfo partitionFileSystemInfo = new PartitionFileSystemInfo(); partitionFileSystemInfo.version = 0; partitionFileSystemInfo.entries.Add(new PartitionFileSystemInfo.EntryInfo() { type = "source", name = contentMeta.GetEntryName(), offset = 0UL, size = (ulong)source1.Size }); PartitionFileSystemMeta partitionFileSystemMeta = new PartitionFileSystemMeta(); List <ConcatenatedSource.Element> elements = new List <ConcatenatedSource.Element>(); PartitionFileSystemInfo fileSystemInfo = partitionFileSystemInfo; byte[] buffer = partitionFileSystemMeta.Create(fileSystemInfo); ConcatenatedSource.Element element1 = new ConcatenatedSource.Element((ISource) new MemorySource(buffer, 0, buffer.Length), "meta", 0L); ConcatenatedSource.Element element2 = new ConcatenatedSource.Element(source1, "body", element1.Source.Size); elements.Add(element1); elements.Add(element2); ISource source2 = (ISource) new ConcatenatedSource(elements); this.m_source = (ISource) new NintendoContentArchiveSource(new NintendoContentFileSystemInfo() { distributionType = isGameCard ? (byte)1 : (byte)0, contentType = (byte)1, keyGeneration = (byte)0, programId = contentMetaReader.GetId(), contentIndex = 0U, keyAreaEncryptionKeyIndex = (byte)keyEncryptionKeyIndex, isProdEncryption = isProdEncryption, fsEntries = { new NintendoContentFileSystemInfo.EntryInfo() { type = "source", formatType = "PartitionFs", sourceInterface = (SourceInterface) new CliCompatibleSource(source2), version = (ushort)2, hashType = (byte)0, encryptionType = (byte)0 } }, numFsEntries = 1 }, config, false); this.Size = this.m_source.Size; }
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); }
public NintendoContentMetaBase(List <Tuple <ISource, NintendoContentInfo> > contentSourceList, string type, string metaPath) : this(contentSourceList, NintendoContentMetaBase.ExtractContentMetaDescriptor(type, metaPath, contentSourceList.Select <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>((Func <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>)(tuple => tuple.Item2)).ToList <NintendoContentInfo>()), false) { }
public NintendoContentMetaBase(List <Tuple <ISource, NintendoContentInfo> > contentSourceList, byte[] buffer, ContentMetaModel model, bool isProdEncryption) : this(contentSourceList, NintendoContentMetaBase.ExtractContentMetaDescriptor(buffer, model, contentSourceList.Select <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>((Func <Tuple <ISource, NintendoContentInfo>, NintendoContentInfo>)(tuple => tuple.Item2)).ToList <NintendoContentInfo>()), isProdEncryption) { }
private static ContentMetaDescriptor ExtractContentMetaDescriptor(string type, string metaPath, List <NintendoContentInfo> contentInfoList) { ulong applicationId = 0; byte attributes = 0; NintendoExtendedHeader extendedHeader = (NintendoExtendedHeader)null; List <NintendoContentMetaInfo> contentMetaInfoList = new List <NintendoContentMetaInfo>(); uint num1 = NintendoContentMetaBase.GetDefaultDownloadSystemVersion(); ulong id; uint version; if (type.Equals("SystemUpdate")) { ContentMetaModel contentMeta1 = NintendoContentMetaBase.GetDeserializedModel <SystemUpdateModel>(metaPath, false).ContentMeta; if (contentMeta1.Type != "SystemUpdate") { throw new ArgumentException("The content meta type is not SystemUpdate."); } id = contentMeta1.GetUInt64Id(); version = contentMeta1.Version; foreach (ContentMetaModel contentMeta2 in contentMeta1.ContentMetaList) { contentMetaInfoList.Add(new NintendoContentMetaInfo(contentMeta2.Type, contentMeta2.GetUInt64Id(), contentMeta2.Version, (byte)ContentMetaAttributeExtension.FromStringList((IEnumerable <string>)contentMeta2.AttributeList))); } } else { DotMetaReader dotMetaReader = new DotMetaReader(metaPath); id = dotMetaReader.GetContentMetaId(); version = dotMetaReader.GetVersion(); attributes = dotMetaReader.GetContentMetaAttributes(); num1 = dotMetaReader.GetRequiredDownloadSystemVersion().GetValueOrDefault(num1); if (!(type == "Application")) { if (!(type == "AddOnContent")) { if (type == "Patch") { applicationId = dotMetaReader.GetApplicationId(); uint?requiredSystemVersion1 = dotMetaReader.GetRequiredSystemVersion(); uint requiredSystemVersion2 = requiredSystemVersion1.HasValue ? requiredSystemVersion1.Value : NintendoContentMeta.GetRequiredSystemVersion(); extendedHeader = (NintendoExtendedHeader) new NintendoPatchExtendedHeader(dotMetaReader.GetApplicationId(), requiredSystemVersion2); version = NintendoContentMetaBase.ShiftVersion(version, "Patch"); } } else { applicationId = dotMetaReader.GetApplicationId(); extendedHeader = (NintendoExtendedHeader) new NintendoAddOnContentExtendedHeader(dotMetaReader.GetApplicationId(), dotMetaReader.GetRequiredApplicationVersion(), dotMetaReader.GetAddOnContentTag()); version = NintendoContentMetaBase.ShiftVersion(version, "AddOnContent"); } } else { long num2 = (long)id + 2048L; uint?requiredSystemVersion = dotMetaReader.GetRequiredSystemVersion(); int num3 = requiredSystemVersion.HasValue ? (int)requiredSystemVersion.Value : (int)NintendoContentMeta.GetRequiredSystemVersion(); extendedHeader = (NintendoExtendedHeader) new NintendoApplicationExtendedHeader((ulong)num2, (uint)num3); version = NintendoContentMetaBase.ShiftVersion(version, "Application"); } } return(new ContentMetaDescriptor(type, id, version, attributes, applicationId, num1, contentInfoList, contentMetaInfoList, extendedHeader, new byte[NintendoContentMeta.GetDigestSize()])); }