diff --git a/README.md b/README.md index df8a7387..404ee7ee 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ NCA options: --basenca Set Base NCA to use with update partitions. --basetitlekey Specify single (encrypted) titlekey for the base NCA. --titlekey Specify single (encrypted) titlekey. + --suppresskeys Suppress output of decrypted keys. KIP1 options: --uncompressed Specify file path for saving uncompressed KIP1. RomFS options: diff --git a/src/hactoolnet/CliParser.cs b/src/hactoolnet/CliParser.cs index b18a7c9a..1aae7e34 100644 --- a/src/hactoolnet/CliParser.cs +++ b/src/hactoolnet/CliParser.cs @@ -20,6 +20,7 @@ internal static class CliParser new CliOption("enablehash", 'h', 0, (o, _) => o.EnableHash = true), new CliOption("disablekeywarns", 0, (o, _) => o.DisableKeyWarns = true), new CliOption("enableallkeywarns", 0, (o, _) => o.EnableAllKeyWarns = true), + new CliOption("suppresskeys", 0, (o, _) => o.SuppressKeydataOutput = true), new CliOption("keyset", 'k', 1, (o, a) => o.Keyfile = a[0]), new CliOption("titlekeys", 1, (o, a) => o.TitleKeyFile = a[0]), new CliOption("consolekeys", 1, (o, a) => o.ConsoleKeyFile = a[0]), @@ -294,6 +295,7 @@ internal static class CliParser sb.AppendLine(" --basenca Set Base NCA to use with update partitions."); sb.AppendLine(" --basetitlekey Specify single (encrypted) titlekey for the base NCA."); sb.AppendLine(" --titlekey Specify single (encrypted) titlekey for the NCA."); + sb.AppendLine(" --suppresskeys Suppress output of decrypted keys."); sb.AppendLine("KIP1 options:"); sb.AppendLine(" --uncompressed Specify file path for saving uncompressed KIP1."); sb.AppendLine("RomFS options:"); diff --git a/src/hactoolnet/Options.cs b/src/hactoolnet/Options.cs index b3f55b4d..083eefd7 100644 --- a/src/hactoolnet/Options.cs +++ b/src/hactoolnet/Options.cs @@ -18,6 +18,7 @@ internal class Options public bool EnableHash; public bool DisableKeyWarns; public bool EnableAllKeyWarns; + public bool SuppressKeydataOutput; public string Keyfile; public string TitleKeyFile; public string ConsoleKeyFile; diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs index 772f77ae..99ed6b38 100644 --- a/src/hactoolnet/ProcessNca.cs +++ b/src/hactoolnet/ProcessNca.cs @@ -239,7 +239,7 @@ internal static class ProcessNca nca.OpenEncryptedNca().WriteAllBytes(ctx.Options.CiphertextOut, ctx.Logger); } - if (!ctx.Options.ReadBench) ctx.Logger.LogMessage(ncaHolder.Print()); + if (!ctx.Options.ReadBench) ctx.Logger.LogMessage(ncaHolder.Print(ctx.Options)); IStorage OpenStorage(int index) { @@ -309,7 +309,7 @@ internal static class ProcessNca return keyGeneration - 1; } - private static string Print(this NcaHolder ncaHolder) + private static string Print(this NcaHolder ncaHolder, Options options) { Nca nca = ncaHolder.Nca; int masterKey = GetMasterKeyRevisionFromKeyGeneration(nca.Header.KeyGeneration); @@ -347,7 +347,11 @@ internal static class ProcessNca { PrintItem(sb, colLen, "Rights ID:", nca.Header.RightsId.ToArray()); PrintItem(sb, colLen, "Titlekey (Encrypted):", nca.GetEncryptedTitleKey()); - PrintItem(sb, colLen, "Titlekey (Decrypted):", nca.GetDecryptedTitleKey()); + + if (!options.SuppressKeydataOutput) + { + PrintItem(sb, colLen, "Titlekey (Decrypted):", nca.GetDecryptedTitleKey()); + } } else { @@ -367,10 +371,13 @@ internal static class ProcessNca sb.AppendLine("Key Area (Encrypted):"); PrintItem(sb, colLen, "Key (RSA-OAEP Encrypted):", nca.Header.GetKeyArea().ToArray()); - sb.AppendLine("Key Area (Decrypted):"); - for (int i = 0; i < 2; i++) + if (!options.SuppressKeydataOutput) { - PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i)); + sb.AppendLine("Key Area (Decrypted):"); + for (int i = 0; i < 2; i++) + { + PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i)); + } } } else if (version == NcaVersion.Nca0FixedKey) @@ -392,10 +399,13 @@ internal static class ProcessNca PrintItem(sb, colLen, $" Key {i} (Encrypted):", nca.Header.GetEncryptedKey(i).ToArray()); } - sb.AppendLine("Key Area (Decrypted):"); - for (int i = 0; i < keyCount; i++) + if (!options.SuppressKeydataOutput) { - PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i)); + sb.AppendLine("Key Area (Decrypted):"); + for (int i = 0; i < keyCount; i++) + { + PrintItem(sb, colLen, $" Key {i} (Decrypted):", nca.GetDecryptedKey(i)); + } } } }