Modify check for ExeFS NCA sections

This commit is contained in:
Alex Barney 2018-10-12 21:28:05 -05:00
parent 75dafd9cbe
commit e9602d35da
4 changed files with 14 additions and 20 deletions

View file

@ -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;
//}
}
/// <summary>
@ -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];

View file

@ -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)

View file

@ -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)
{

View file

@ -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)
{