Add keyfile path input

This commit is contained in:
Matt Nadareski
2021-09-26 22:35:10 -07:00
parent c91d7f2708
commit 9ff0205e15
2 changed files with 62 additions and 29 deletions

View File

@@ -50,19 +50,50 @@ namespace NDecrypt.CMD
for ( ; start < args.Length; start++)
{
if (args[start] == "-c" || args[start] == "--citra")
{
decryptArgs.UseCitraKeyFile = true;
}
else if (args[start] == "-dev" || args[start] == "--development")
{
decryptArgs.Development = true;
}
else if (args[start] == "-f" || args[start] == "--force")
{
decryptArgs.Force = true;
}
else if (args[start] == "-h" || args[start] == "--hash")
{
outputHashes = true;
}
else if (args[start] == "-k" || args[start] == "--keyfile")
{
if (start == args.Length - 1)
Console.WriteLine("Invalid keyfile path: no additional arguments found!");
start++;
string tempPath = args[start];
if (string.IsNullOrWhiteSpace(tempPath))
Console.WriteLine($"Invalid keyfile path: null or empty path found!");
tempPath = Path.GetFullPath(tempPath);
if (!File.Exists(tempPath))
Console.WriteLine($"Invalid keyfile path: file {tempPath} not found!");
else
decryptArgs.KeyFile = tempPath;
}
else
{
break;
}
}
// Derive the keyfile path based on the runtime folder if not already set
if (string.IsNullOrWhiteSpace(decryptArgs.KeyFile))
{
if (decryptArgs.UseCitraKeyFile)
decryptArgs.KeyFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "aes_keys.txt");
else
decryptArgs.KeyFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "keys.bin");
}
// If we are using a Citra keyfile, there are no development keys
@@ -71,12 +102,6 @@ namespace NDecrypt.CMD
Console.WriteLine("Citra keyfiles don't contain development keys; disabling the option...");
decryptArgs.Development = false;
}
// Derive the keyfile path based on the runtime folder -- TODO: Make the keyfile path configurable
if (decryptArgs.UseCitraKeyFile)
decryptArgs.KeyFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "aes_keys.txt");
else
decryptArgs.KeyFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "keys.bin");
// Initialize the constants, if possible
decryptArgs.Initialize();
@@ -85,23 +110,13 @@ namespace NDecrypt.CMD
{
if (File.Exists(args[i]))
{
Console.WriteLine(args[i]);
ITool tool = DeriveTool(args[i], decryptArgs);
if (tool?.ProcessFile() != true)
Console.WriteLine("Processing failed!");
else if (outputHashes)
WriteHashes(args[i]);
ProcessPath(args[i], decryptArgs, outputHashes);
}
else if (Directory.Exists(args[i]))
{
foreach (string file in Directory.EnumerateFiles(args[i], "*", SearchOption.AllDirectories))
{
Console.WriteLine(file);
ITool tool = DeriveTool(file, decryptArgs);
if (tool?.ProcessFile() != true)
Console.WriteLine("Processing failed!");
else if (outputHashes)
WriteHashes(file);
ProcessPath(file, decryptArgs, outputHashes);
}
}
else
@@ -111,6 +126,22 @@ namespace NDecrypt.CMD
}
}
/// <summary>
/// Display a basic help text
/// </summary>
/// <param name="path">Path to the file to process</param>
/// <param name="decryptArgs">DecryptArgs to use during processing</param>
/// <param name="outputHashes">True to write out a hashfile, false otherwise</param>
private static void ProcessPath(string path, DecryptArgs decryptArgs, bool outputHashes)
{
Console.WriteLine(path);
ITool tool = DeriveTool(path, decryptArgs);
if (tool?.ProcessFile() != true)
Console.WriteLine("Processing failed!");
else if (outputHashes)
WriteHashes(path);
}
/// <summary>
/// Display a basic help text
/// </summary>
@@ -127,10 +158,11 @@ e, encrypt - Encrypt the input files
d, decrypt - Decrypt the input files
Possible values for [flags] (one or more can be used):
-c, --citra - Enable using aes_keys.txt instead of keys.bin
-dev, --development - Enable using development keys, if available
-f, --force - Force operation by avoiding sanity checks
-h, --hash - Output size and hashes to a companion file
-c, --citra - Enable using aes_keys.txt instead of keys.bin
-dev, --development - Enable using development keys, if available
-f, --force - Force operation by avoiding sanity checks
-h, --hash - Output size and hashes to a companion file
-k, --keyfile <path> - Path to keys.bin or aes_keys.txt
<path> can be any file or folder that contains uncompressed items.
More than one path can be specified at a time.");

View File

@@ -23,10 +23,11 @@ This tool allows you to encrypt and decrypt your personally dumped NDS and N3DS
d, decrypt - Decrypt the input files
Possible values for [flags] (one or more can be used):
-c, --citra - Enable using aes_keys.txt instead of keys.bin
-dev, --development - Enable using development keys, if available
-f, --force - Force operation by avoiding sanity checks
-h, --hash - Output size and hashes to a companion file
-c, --citra - Enable using aes_keys.txt instead of keys.bin
-dev, --development - Enable using development keys, if available
-f, --force - Force operation by avoiding sanity checks
-h, --hash - Output size and hashes to a companion file
-k, --keyfile <path> - Path to keys.bin or aes_keys.txt
<path> can be any file or folder that contains uncompressed items.
More than one path can be specified at a time.