Extract main RomFS from XCIs

This commit is contained in:
Alex Barney 2018-08-14 17:38:32 -06:00
parent 1e813818c0
commit 86741d3c92
2 changed files with 45 additions and 0 deletions

View file

@ -165,6 +165,7 @@ namespace hactoolnet
sb.AppendLine(" --securedir <dir> Specify secure XCI directory path.");
sb.AppendLine(" --logodir <dir> Specify logo XCI directory path.");
sb.AppendLine(" --outdir <dir> Specify XCI directory path.");
sb.AppendLine(" --romfsdir <dir> Specify main RomFS directory path.");
sb.AppendLine("Switch FS options:");
sb.AppendLine(" --sdseed <seed> Set console unique seed for SD card NAX0 encryption.");
sb.AppendLine(" --listapps List application info.");

View file

@ -221,6 +221,11 @@ namespace hactoolnet
if (ctx.Options.OutDir != null && xci.RootPartition != null)
{
var root = xci.RootPartition;
if (root == null)
{
ctx.Logger.LogMessage("Could not find root partition");
return;
}
foreach (var sub in root.Files)
{
@ -230,6 +235,45 @@ namespace hactoolnet
subPfs.Extract(subDir, ctx.Logger);
}
}
if (ctx.Options.RomfsOutDir != null)
{
if (xci.SecurePartition == null)
{
ctx.Logger.LogMessage("Could not find secure partition");
return;
}
Nca mainNca = null;
foreach (var fileEntry in xci.SecurePartition.Files.Where(x => x.Name.EndsWith(".nca")))
{
var ncaStream = xci.SecurePartition.OpenFile(fileEntry);
var nca = new Nca(ctx.Keyset, ncaStream, true);
if (nca.Header.ContentType == ContentType.Program)
{
mainNca = nca;
}
}
if (mainNca == null)
{
ctx.Logger.LogMessage("Could not find Program NCA");
return;
}
var romfsSection = mainNca.Sections.FirstOrDefault(x => x.Type == SectionType.Romfs);
if (romfsSection == null)
{
ctx.Logger.LogMessage("NCA has no RomFS section");
return;
}
var romfs = new Romfs(mainNca.OpenSection(romfsSection.SectionNum, false));
romfs.Extract(ctx.Options.RomfsOutDir, ctx.Logger);
}
}
}