diff --git a/LibHac/Nca.cs b/LibHac/Nca.cs index 8ec75bad..26477910 100644 --- a/LibHac/Nca.cs +++ b/LibHac/Nca.cs @@ -61,19 +61,7 @@ namespace LibHac NcaSection section = ParseSection(i); if (section == null) continue; Sections[i] = section; - ValidateMasterHash(i); } - - //foreach (NcaSection pfsSection in Sections.Where(x => x != null && x.Type == SectionType.Pfs0)) - //{ - // Stream sectionStream = OpenSection(pfsSection.SectionNum, false, false); - // if (sectionStream == null) continue; - - // var pfs = new Pfs(sectionStream); - // if (!pfs.FileExists("main.npdm")) continue; - - // pfsSection.IsExefs = true; - //} } /// @@ -161,7 +149,7 @@ namespace LibHac public Stream OpenSection(int index, bool raw, IntegrityCheckLevel integrityCheckLevel) { Stream rawStream = OpenRawSection(index); - + if (raw || rawStream == null) return rawStream; NcaSection sect = Sections[index]; @@ -379,7 +367,7 @@ namespace LibHac break; case NcaHashType.Ivfc when sect.Header.EncryptionType == NcaEncryptionType.AesCtrEx: CheckBktrKey(sect); - break; + return; case NcaHashType.Ivfc: offset = sect.Header.IvfcInfo.LevelHeaders[0].LogicalOffset; size = 1 << sect.Header.IvfcInfo.LevelHeaders[0].BlockSizePower; @@ -414,8 +402,6 @@ namespace LibHac public long Size { get; set; } public Validity MasterHashValidity { get; set; } - public bool IsExefs { get; internal set; } - public byte[] GetMasterHash() { var hash = new byte[Crypto.Sha256DigestSize]; diff --git a/hactoolnet/ProcessNca.cs b/hactoolnet/ProcessNca.cs index 53517d80..1b87a1e8 100644 --- a/hactoolnet/ProcessNca.cs +++ b/hactoolnet/ProcessNca.cs @@ -80,7 +80,13 @@ namespace hactoolnet if (ctx.Options.ExefsOutDir != null || ctx.Options.ExefsOut != null) { - NcaSection section = nca.Sections.FirstOrDefault(x => x?.IsExefs == true); + if (nca.Header.ContentType != ContentType.Program) + { + ctx.Logger.LogMessage("NCA's content type is not \"Program\""); + return; + } + + NcaSection section = nca.Sections[(int)ProgramPartitionType.Code]; if (section == null) { @@ -154,10 +160,12 @@ namespace hactoolnet NcaSection sect = nca.Sections[i]; if (sect == null) continue; + bool isExefs = nca.Header.ContentType == ContentType.Program && i == (int)ProgramPartitionType.Code; + sb.AppendLine($" Section {i}:"); PrintItem(sb, colLen, " Offset:", $"0x{sect.Offset:x12}"); PrintItem(sb, colLen, " Size:", $"0x{sect.Size:x12}"); - PrintItem(sb, colLen, " Partition Type:", sect.IsExefs ? "ExeFS" : sect.Type.ToString()); + PrintItem(sb, colLen, " Partition Type:", isExefs ? "ExeFS" : sect.Type.ToString()); PrintItem(sb, colLen, " Section CTR:", sect.Header.Ctr); switch (sect.Header.HashType) diff --git a/hactoolnet/ProcessSwitchFs.cs b/hactoolnet/ProcessSwitchFs.cs index ab1844d4..fe2e89cd 100644 --- a/hactoolnet/ProcessSwitchFs.cs +++ b/hactoolnet/ProcessSwitchFs.cs @@ -45,7 +45,7 @@ namespace hactoolnet return; } - NcaSection section = title.MainNca.Sections.FirstOrDefault(x => x.IsExefs); + NcaSection section = title.MainNca.Sections[(int)ProgramPartitionType.Code]; if (section == null) { diff --git a/hactoolnet/ProcessXci.cs b/hactoolnet/ProcessXci.cs index d2e5aabf..1ac4037d 100644 --- a/hactoolnet/ProcessXci.cs +++ b/hactoolnet/ProcessXci.cs @@ -69,7 +69,7 @@ namespace hactoolnet return; } - NcaSection exefsSection = mainNca.Sections.FirstOrDefault(x => x.IsExefs); + NcaSection exefsSection = mainNca.Sections[(int)ProgramPartitionType.Code]; if (exefsSection == null) {