hactoolnet: Add NPDM converter

This commit is contained in:
MonsterDruide1 2022-09-28 14:23:24 +02:00
parent 6f6836c302
commit 8232ff7ed6
5 changed files with 40 additions and 2 deletions

View file

@ -55,6 +55,8 @@ NCA options:
--romfsdir <dir> Specify RomFS directory path.
--listromfs List files in RomFS.
--basenca Set Base NCA to use with update partitions.
NPDM options:
--json <file> Specify file path for saving JSON representation of program permissions to.
KIP1 options:
--uncompressed <f> Specify file path for saving uncompressed KIP1.
RomFS options:

View file

@ -68,6 +68,7 @@ internal static class CliParser
new CliOption("title", 1, (o, a) => o.TitleId = ParseTitleId(o, a[0])),
new CliOption("bench", 1, (o, a) => o.BenchType = a[0]),
new CliOption("cpufreq", 1, (o, a) => o.CpuFrequencyGhz = ParseDouble(o, a[0])),
new CliOption("json", 1, (o, a) => o.JsonFile = a[0]),
new CliOption("replacefile", 2, (o, a) =>
{
@ -190,6 +191,7 @@ internal static class CliParser
case "ini1": return FileType.Ini1;
case "ndv0": return FileType.Ndv0;
case "bench": return FileType.Bench;
case "npdm": return FileType.Npdm;
}
options.ParseErrorMessage ??= "Specified type is invalid.";
@ -274,6 +276,8 @@ internal static class CliParser
sb.AppendLine(" --romfsdir <dir> Specify RomFS directory path.");
sb.AppendLine(" --listromfs List files in RomFS.");
sb.AppendLine(" --basenca Set Base NCA to use with update partitions.");
sb.AppendLine("NPDM options:");
sb.AppendLine(" --json <file> Specify file path for saving JSON representation of program permissions to.");
sb.AppendLine("KIP1 options:");
sb.AppendLine(" --uncompressed <f> Specify file path for saving uncompressed KIP1.");
sb.AppendLine("RomFS options:");
@ -370,4 +374,4 @@ internal static class CliParser
public int ArgsNeeded { get; }
public Action<Options, string[]> Assigner { get; }
}
}
}

View file

@ -63,6 +63,7 @@ internal class Options
public ulong TitleId;
public string BenchType;
public double CpuFrequencyGhz;
public string JsonFile;
public string ParseErrorMessage;
public bool IsParseSuccessful;
@ -99,7 +100,8 @@ internal enum FileType
Kip1,
Ini1,
Ndv0,
Bench
Bench,
Npdm
}
internal class Context

View file

@ -0,0 +1,27 @@
using System.IO;
using System.Text.Json;
using LibHac.FsSystem;
using LibHac.Tools.FsSystem;
using LibHac.Tools.Npdm;
namespace hactoolnet;
internal static class ProcessNpdm
{
public static void Process(Context ctx)
{
using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.Read))
{
var npdm = new NpdmBinary(file.AsStream(), ctx.KeySet);
if(ctx.Options.JsonFile != null)
{
string json = JsonSerializer.Serialize(npdm, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(ctx.Options.JsonFile, json);
}
}
}
}

View file

@ -182,6 +182,9 @@ public static class Program
case FileType.Bench:
ProcessBench.Process(ctx);
break;
case FileType.Npdm:
ProcessNpdm.Process(ctx);
break;
default:
throw new ArgumentOutOfRangeException();
}