internal static NintendoSubmissionPackageFileSystemInfo GetProdNspInfo(NintendoSubmissionPackageReader nspReader, KeyConfiguration keyConfig) { ArchiveReconstructionUtils.GetContentInfoDelegate getContentInfoImpl = (ArchiveReconstructionUtils.GetContentInfoDelegate)(contentInfo => new NintendoSubmissionPackageFileSystemInfo.ContentInfo() { FsInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)ArchiveReconstructionUtils.GetProdNcaInfo(nspReader.OpenNintendoContentArchiveReader(contentInfo.Id + ".nca", keyConfig.GetKeyAreaEncryptionKeys())), ContentType = contentInfo.Type }); ArchiveReconstructionUtils.GetContentMetaInfoDelegate getContentMetaInfoImpl = (ArchiveReconstructionUtils.GetContentMetaInfoDelegate)((ref NintendoSubmissionPackageFileSystemInfo.EntryInfo entry, string contentMetaFileName, ContentMetaModel model) => ArchiveReconstructionUtils.GetCommonContentMetaInfo(ref entry, contentMetaFileName, model, nspReader, keyConfig)); NintendoSubmissionPackageFileSystemInfo nspInfo = ArchiveReconstructionUtils.GetNspInfo(nspReader, keyConfig, getContentInfoImpl, getContentMetaInfoImpl); nspInfo.IsProdEncryption = true; return(nspInfo); }
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."); }
private static NintendoSubmissionPackageFileSystemInfo GetNspInfo(NintendoSubmissionPackageReader nspReader, KeyConfiguration keyConfig, ArchiveReconstructionUtils.GetContentInfoDelegate getContentInfoImpl, ArchiveReconstructionUtils.GetContentMetaInfoDelegate getContentMetaInfoImpl) { NintendoSubmissionPackageFileSystemInfo packageFileSystemInfo = new NintendoSubmissionPackageFileSystemInfo(); packageFileSystemInfo.Version = (byte)0; foreach (Tuple <string, long> tuple in nspReader.ListFileInfo()) { string fileName = tuple.Item1; long fileSize = tuple.Item2; if (fileName.EndsWith(".cnmt.xml")) { ContentMetaModel model = ArchiveReconstructionUtils.ReadXml <ContentMetaModel>(nspReader, fileName, fileSize); string type = model.Type; if (!(type == "Application")) { if (!(type == "Patch")) { if (type == "AddOnContent") { model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <AddOnContentContentMetaModel>(nspReader, fileName, fileSize); } } else { model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <PatchContentMetaModel>(nspReader, fileName, fileSize); } } else { model = (ContentMetaModel)ArchiveReconstructionUtils.ReadXml <ApplicationContentMetaModel>(nspReader, fileName, fileSize); } NintendoSubmissionPackageFileSystemInfo.EntryInfo entry = new NintendoSubmissionPackageFileSystemInfo.EntryInfo(); entry.Contents = new List <NintendoSubmissionPackageFileSystemInfo.ContentInfo>(); foreach (ContentModel content in model.ContentList) { if (!(content.Type == "Meta")) { NintendoSubmissionPackageFileSystemInfo.ContentInfo contentInfo = getContentInfoImpl(content); entry.Contents.Add(contentInfo); } } string contentMetaFileName = Path.GetFileNameWithoutExtension(fileName) + ".nca"; getContentMetaInfoImpl(ref entry, contentMetaFileName, model); List <NintendoSubmissionPackageExtraData> list = nspReader.ListFileInfo().FindAll((Predicate <Tuple <string, long> >)(x => { if (x.Item1.StartsWith(fileName.Replace(".cnmt.xml", ""))) { return(x.Item1.EndsWith(".jpg")); } return(false); })).Select <Tuple <string, long>, NintendoSubmissionPackageExtraData>((Func <Tuple <string, long>, NintendoSubmissionPackageExtraData>)(x => { byte[] buffer = nspReader.ReadFile(x.Item1, 0L, x.Item2); return(new NintendoSubmissionPackageExtraData(x.Item1, (ISource) new MemorySource(buffer, 0, buffer.Length))); })).ToList <NintendoSubmissionPackageExtraData>(); entry.ExtraData = list; packageFileSystemInfo.Entries.Add(entry); } if (fileName == "cardspec.xml") { CardSpecModel cardSpecModel = ArchiveReconstructionUtils.ReadXml <CardSpecModel>(nspReader, fileName, fileSize); packageFileSystemInfo.CardSize = Convert.ToInt32(cardSpecModel.Size, 10); packageFileSystemInfo.CardClockRate = Convert.ToInt32(cardSpecModel.ClockRate, 10); } } return(packageFileSystemInfo); }