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."); }
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); }