hactoolnet: Add option to load keys from dev.keys

This commit is contained in:
Alex Barney 2019-03-14 18:00:52 -05:00
parent 85a3b56902
commit d288a24c4e
4 changed files with 7 additions and 3 deletions

View file

@ -51,7 +51,6 @@ namespace NandReader
var nand = new Nand(stream, keyset);
FatFileSystemProvider user = nand.OpenSystemPartition();
SwitchFs sdfs = SwitchFs.OpenNandPartition(keyset, user);
;
}
}

View file

@ -13,6 +13,7 @@ namespace hactoolnet
new CliOption("intype", 't', 1, (o, a) => o.InFileType = ParseFileType(a[0])),
new CliOption("raw", 'r', 0, (o, a) => o.Raw = true),
new CliOption("verify", 'y', 0, (o, a) => o.Validate = true),
new CliOption("dev", 'd', 0, (o, a) => o.UseDevKeys = true),
new CliOption("enablehash", 'h', 0, (o, a) => o.EnableHash = true),
new CliOption("keyset", 'k', 1, (o, a) => o.Keyfile = a[0]),
new CliOption("titlekeys", 1, (o, a) => o.TitleKeyFile = a[0]),
@ -162,6 +163,7 @@ namespace hactoolnet
sb.AppendLine(" -r, --raw Keep raw data, don\'t unpack.");
sb.AppendLine(" -y, --verify Verify all hashes in the input file.");
sb.AppendLine(" -h, --enablehash Enable hash checks when reading the input file.");
sb.AppendLine(" -d, --dev Decrypt with development keys instead of retail.");
sb.AppendLine(" -k, --keyset Load keys from an external file.");
sb.AppendLine(" -t, --intype=type Specify input file type [nca, xci, romfs, pfs0, pk11, pk21, ini1, kip1, switchfs, save, ndv0, keygen, romfsbuild, pfsbuild]");
sb.AppendLine(" --titlekeys <file> Load title keys from an external file.");

View file

@ -10,6 +10,7 @@ namespace hactoolnet
public FileType InFileType = FileType.Nca;
public bool Raw;
public bool Validate;
public bool UseDevKeys;
public bool EnableHash;
public string Keyfile;
public string TitleKeyFile;

View file

@ -113,8 +113,10 @@ namespace hactoolnet
private static void OpenKeyset(Context ctx)
{
string keyFileName = ctx.Options.UseDevKeys ? "dev.keys" : "prod.keys";
string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string homeKeyFile = Path.Combine(home, ".switch", "prod.keys");
string homeKeyFile = Path.Combine(home, ".switch", keyFileName);
string homeTitleKeyFile = Path.Combine(home, ".switch", "title.keys");
string homeConsoleKeyFile = Path.Combine(home, ".switch", "console.keys");
string keyFile = ctx.Options.Keyfile;
@ -147,7 +149,7 @@ namespace hactoolnet
string dir = ctx.Options.OutDir;
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, "prod.keys"), ExternalKeys.PrintCommonKeys(ctx.Keyset));
File.WriteAllText(Path.Combine(dir, keyFileName), ExternalKeys.PrintCommonKeys(ctx.Keyset));
File.WriteAllText(Path.Combine(dir, "console.keys"), ExternalKeys.PrintUniqueKeys(ctx.Keyset));
File.WriteAllText(Path.Combine(dir, "title.keys"), ExternalKeys.PrintTitleKeys(ctx.Keyset));
}