internal static NintendoContentFileSystemInfo GetReplacedNcaInfo(NintendoContentArchiveReader ncaReader, string descFilePath, EntryReplaceRule replaceRule) { NintendoContentFileSystemInfo commonNcaInfo = ArchiveReconstructionUtils.GetCommonNcaInfo(ncaReader); commonNcaInfo.keyAreaEncryptionKeyIndex = ncaReader.GetKeyIndex(); commonNcaInfo.isProdEncryption = false; if (descFilePath != null) { NintendoContentAdfReader.RetrieveInfoFromDesc(ref commonNcaInfo, descFilePath); } else if (replaceRule != null && commonNcaInfo.contentType == (byte)0) { throw new Exception("Replacing 'Program' content needs desc file."); } for (int fsIndex = 0; fsIndex < commonNcaInfo.numFsEntries; ++fsIndex) { string str = string.Format("fs{0}", (object)fsIndex); if (replaceRule != null && replaceRule.Path.StartsWith(str)) { EntryReplaceRule replaceRule1 = replaceRule; replaceRule1.Path = replaceRule1.Path.Substring(str.Length + 1); commonNcaInfo.fsEntries.Add(ArchiveReconstructionUtils.GetFsEntry(ncaReader, fsIndex, replaceRule1)); } else { commonNcaInfo.fsEntries.Add(ArchiveReconstructionUtils.GetFsEntry(ncaReader, fsIndex)); } } return(commonNcaInfo); }
public NintendoSubmissionPackageFileSystemInfo GetFileSystemInfo() { NintendoSubmissionPackageFileSystemInfo packageFileSystemInfo = new NintendoSubmissionPackageFileSystemInfo(); using (StreamReader streamReader = new StreamReader(this.m_adfPath, Encoding.UTF8)) { YamlStream yamlStream = new YamlStream(); yamlStream.Load((TextReader)streamReader); YamlSequenceNode child1; try { YamlMappingNode rootNode = (YamlMappingNode)yamlStream.Documents[0].RootNode; if (((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("formatType")]).Value != "NintendoSubmissionPackage") { throw new ArgumentException(); } YamlScalarNode child2 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("version")]; child1 = (YamlSequenceNode)rootNode.Children[(YamlNode) new YamlScalarNode("entries")]; packageFileSystemInfo.Version = Convert.ToByte(child2.Value); } catch { throw new ArgumentException("invalid format .adf file."); } foreach (YamlMappingNode yamlMappingNode1 in child1) { NintendoSubmissionPackageFileSystemInfo.EntryInfo entryInfo = new NintendoSubmissionPackageFileSystemInfo.EntryInfo(); entryInfo.Contents = new List <NintendoSubmissionPackageFileSystemInfo.ContentInfo>(); YamlNode child2 = yamlMappingNode1.Children[(YamlNode) new YamlScalarNode("contents")]; if (child2 is YamlSequenceNode) { foreach (YamlMappingNode yamlMappingNode2 in (YamlSequenceNode)child2) { NintendoSubmissionPackageFileSystemInfo.ContentInfo contentInfo = new NintendoSubmissionPackageFileSystemInfo.ContentInfo(); string empty1 = string.Empty; string empty2 = string.Empty; foreach (KeyValuePair <YamlNode, YamlNode> keyValuePair in yamlMappingNode2) { string str = ((YamlScalarNode)keyValuePair.Key).Value; if (!(str == "type")) { if (!(str == "contentType")) { if (!(str == "path")) { throw new ArgumentException("invalid format .adf file. invalid key is specified\n" + yamlMappingNode2.ToString()); } empty2 = ((YamlScalarNode)keyValuePair.Value).Value; } else { contentInfo.ContentType = ((YamlScalarNode)keyValuePair.Value).Value; } } else { empty1 = ((YamlScalarNode)keyValuePair.Value).Value; } } if (empty2 == null) { throw new ArgumentException("invalid format .adf file. \"path\" is not specified\n" + yamlMappingNode2.ToString()); } if (empty1 == "format") { NintendoContentAdfReader contentAdfReader = new NintendoContentAdfReader(empty2); contentInfo.FsInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)contentAdfReader.GetFileSystemInfo(); } else { if (!(empty1 == "file")) { throw new ArgumentException("invalid format .adf file. unknown \"type\" is specified\n" + yamlMappingNode2.ToString()); } FileInfo fileInfo = new FileInfo(empty2); contentInfo.Source = (ISource) new FileSource(empty2, 0L, fileInfo.Length); } entryInfo.Contents.Add(contentInfo); } } List <Tuple <string, string> > iconList = new List <Tuple <string, string> >(); List <Tuple <string, string> > nxIconList = new List <Tuple <string, string> >(); uint maxNxIconSize = 102400; foreach (KeyValuePair <YamlNode, YamlNode> keyValuePair in yamlMappingNode1) { switch (((YamlScalarNode)keyValuePair.Key).Value) { case "contents": continue; case "icon": using (IEnumerator <YamlNode> enumerator = ((YamlSequenceNode)keyValuePair.Value).GetEnumerator()) { while (enumerator.MoveNext()) { YamlMappingNode current = (YamlMappingNode)enumerator.Current; string str1 = ((YamlScalarNode)current.Children[(YamlNode) new YamlScalarNode("language")]).Value; string str2 = ((YamlScalarNode)current.Children[(YamlNode) new YamlScalarNode("path")]).Value; iconList.Add(new Tuple <string, string>(str1, str2)); } continue; } case "keyIndex": entryInfo.KeyIndex = int.Parse(((YamlScalarNode)keyValuePair.Value).Value); continue; case "metaFilePath": entryInfo.MetaFilePath = ((YamlScalarNode)keyValuePair.Value).Value; continue; case "metaType": entryInfo.MetaType = ((YamlScalarNode)keyValuePair.Value).Value; continue; case "nxIcon": using (IEnumerator <YamlNode> enumerator = ((YamlSequenceNode)keyValuePair.Value).GetEnumerator()) { while (enumerator.MoveNext()) { YamlMappingNode current = (YamlMappingNode)enumerator.Current; string str1 = ((YamlScalarNode)current.Children[(YamlNode) new YamlScalarNode("language")]).Value; string str2 = ((YamlScalarNode)current.Children[(YamlNode) new YamlScalarNode("path")]).Value; nxIconList.Add(new Tuple <string, string>(str1, str2)); } continue; } case "nxIconMaxSize": maxNxIconSize = uint.Parse(((YamlScalarNode)keyValuePair.Value).Value); continue; default: throw new ArgumentException("invalid format .adf file. invalid key is specified\n" + yamlMappingNode1.ToString()); } } if (entryInfo.MetaFilePath == null) { throw new ArgumentException(); } Tuple <int, int> cardSpec = new DotMetaReader(entryInfo.MetaFilePath).GetCardSpec(); if (cardSpec != null) { packageFileSystemInfo.CardSize = cardSpec.Item1; packageFileSystemInfo.CardClockRate = cardSpec.Item2; } else { Log.Info("\"CardSpec\" is not specified by .meta file. Size and ClockRate will be calculated automatically."); } entryInfo.ExtraData = this.CreateExtraSource(iconList, nxIconList, maxNxIconSize); packageFileSystemInfo.Entries.Add(entryInfo); } } return(packageFileSystemInfo); }
public NintendoContentFileSystemInfo GetFileSystemInfo() { NintendoContentFileSystemInfo fileSystemInfo1 = new NintendoContentFileSystemInfo(); using (StreamReader streamReader = new StreamReader(this.m_adfPath, Encoding.UTF8)) { YamlStream yamlStream = new YamlStream(); yamlStream.Load((TextReader)streamReader); YamlMappingNode rootNode; YamlSequenceNode child1; try { rootNode = (YamlMappingNode)yamlStream.Documents[0].RootNode; if (((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("formatType")]).Value != "NintendoContent") { throw new ArgumentException(); } YamlScalarNode child2 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("contentType")]; YamlScalarNode child3 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("keyGeneration")]; YamlScalarNode child4 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("programId")]; YamlScalarNode child5 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("contentIndex")]; child1 = (YamlSequenceNode)rootNode.Children[(YamlNode) new YamlScalarNode("entries")]; fileSystemInfo1.contentType = this.ConvertToContentTypeByte(child2.Value); fileSystemInfo1.keyGeneration = Convert.ToByte(child3.Value); fileSystemInfo1.programId = Convert.ToUInt64(child4.Value, 16); fileSystemInfo1.contentIndex = Convert.ToUInt32(child5.Value); } catch { throw new ArgumentException("invalid format .adf file."); } try { YamlScalarNode child2 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("keyAreaEncryptionKeyIndex")]; fileSystemInfo1.keyAreaEncryptionKeyIndex = Convert.ToByte(child2.Value); } catch { fileSystemInfo1.keyAreaEncryptionKeyIndex = (byte)0; } string descFilePath; if (fileSystemInfo1.contentType == (byte)0) { try { descFilePath = ((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("descFilePath")]).Value; } catch { throw new ArgumentException(".desc file is not specified for program content."); } } else { descFilePath = (string)null; } byte[] numArray = (byte[])null; if (descFilePath != null) { numArray = NintendoContentAdfReader.RetrieveInfoFromDesc(ref fileSystemInfo1, descFilePath); } foreach (YamlMappingNode yamlMappingNode in child1) { NintendoContentFileSystemInfo.EntryInfo entryInfo1 = new NintendoContentFileSystemInfo.EntryInfo(); string adfPath = (string)null; foreach (KeyValuePair <YamlNode, YamlNode> keyValuePair in yamlMappingNode) { switch (((YamlScalarNode)keyValuePair.Key).Value) { case "encryptionType": entryInfo1.encryptionType = Convert.ToByte(((YamlScalarNode)keyValuePair.Value).Value); continue; case "formatType": entryInfo1.formatType = ((YamlScalarNode)keyValuePair.Value).Value; continue; case "hashType": entryInfo1.hashType = Convert.ToByte(((YamlScalarNode)keyValuePair.Value).Value); continue; case "partitionType": entryInfo1.partitionType = ((YamlScalarNode)keyValuePair.Value).Value; entryInfo1.partitionIndex = this.GetPartitionIndex(entryInfo1.partitionType); continue; case "path": adfPath = ((YamlScalarNode)keyValuePair.Value).Value; continue; case "type": entryInfo1.type = ((YamlScalarNode)keyValuePair.Value).Value; continue; case "version": entryInfo1.version = Convert.ToUInt16(((YamlScalarNode)keyValuePair.Value).Value); continue; default: throw new ArgumentException("invalid format .adf file. invalid key is specified\n" + yamlMappingNode.ToString()); } } if (entryInfo1.type == null || entryInfo1.formatType == null || adfPath == null) { throw new ArgumentException("invalid format .adf file. \"type\" or \"formatType\" is not specified\n" + yamlMappingNode.ToString()); } entryInfo1.version = (ushort)2; entryInfo1.hashType = NintendoContentArchiveSource.VerifyHashType(fileSystemInfo1, entryInfo1); entryInfo1.encryptionType = NintendoContentArchiveSource.VerifyEncryptionType(fileSystemInfo1, entryInfo1); string formatType = entryInfo1.formatType; if (!(formatType == "PartitionFs")) { if (!(formatType == "RomFs")) { throw new NotImplementedException("invalid format .adf file. invalid formatType." + yamlMappingNode.ToString()); } RomFsAdfReader romFsAdfReader = new RomFsAdfReader(adfPath); entryInfo1.fileSystemInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)romFsAdfReader.GetFileSystemInfo(); } else { PartitionFileSystemInfo fileSystemInfo2 = new PartitionFsAdfReader(adfPath).GetFileSystemInfo(); if (numArray != null && entryInfo1.partitionType == "code") { IEnumerable <PartitionFileSystemInfo.EntryInfo> source = fileSystemInfo2.entries.Where <PartitionFileSystemInfo.EntryInfo>((Func <PartitionFileSystemInfo.EntryInfo, bool>)(p => p.name == "main.npdm")); if (fileSystemInfo1.contentType == (byte)0 && source.Count <PartitionFileSystemInfo.EntryInfo>() != 1) { throw new ArgumentException("\"main.npdm\" must be included in the code region."); } foreach (PartitionFileSystemInfo.EntryInfo entryInfo2 in source) { if (!((IEnumerable <byte>) this.ReadAcid(entryInfo2.path)).SequenceEqual <byte>((IEnumerable <byte>)numArray)) { throw new ArgumentException(".desc file specified differ from the one used to build code."); } } } entryInfo1.fileSystemInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)fileSystemInfo2; } fileSystemInfo1.fsEntries.Add(entryInfo1); } } fileSystemInfo1.numFsEntries = fileSystemInfo1.fsEntries.Count; fileSystemInfo1.isProdEncryption = false; return(fileSystemInfo1); }