From f349389994158e5cf2820fcf4e515195f6708e65 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 17 Dec 2020 11:08:53 -0800 Subject: [PATCH] keys.bin is only needed for 3DS, better docs --- NDecrypt/N3DS/Constants.cs | 8 ++++++-- NDecrypt/Program.cs | 26 ++++++++++++++++---------- NDecrypt/ThreeDSTool.cs | 8 ++++++++ README.md | 19 +++++++++++++------ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/NDecrypt/N3DS/Constants.cs b/NDecrypt/N3DS/Constants.cs index d4bc426..feb8330 100644 --- a/NDecrypt/N3DS/Constants.cs +++ b/NDecrypt/N3DS/Constants.cs @@ -51,14 +51,18 @@ namespace NDecrypt.N3DS /// /// Represents if all of the keys have been initialized properly /// - public static bool IsReady { get; private set; } + public static bool? IsReady { get; private set; } /// /// Setup all of the necessary constants /// /// keys.bin should be in little endian format - static Constants() + public static void Init() { + // If we're already attempted to set the constants, don't try to again + if (IsReady != null) + return; + string keyfile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "keys.bin"); if (!File.Exists(keyfile)) { diff --git a/NDecrypt/Program.cs b/NDecrypt/Program.cs index 6cd242c..5ff926d 100644 --- a/NDecrypt/Program.cs +++ b/NDecrypt/Program.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using NDecrypt.N3DS; namespace NDecrypt { @@ -43,14 +42,6 @@ namespace NDecrypt break; } - // Ensure the constants are all set - new Constants(); - if (!Constants.IsReady) - { - Console.WriteLine("Could not read keys from keys.bin. Please make sure the file exists and try again"); - return; - } - for (int i = start; i < args.Length; i++) { if (File.Exists(args[i])) @@ -68,6 +59,10 @@ namespace NDecrypt Console.WriteLine("Processing failed!"); } } + else + { + Console.WriteLine($"{args[i]} is not a file or folder. Please check your spelling and formatting and try again."); + } } } @@ -80,7 +75,18 @@ namespace NDecrypt if (!string.IsNullOrWhiteSpace(err)) Console.WriteLine($"Error: {err}"); - Console.WriteLine("Usage: NDecrypt.exe (decrypt|encrypt) [-dev] [-f] ..."); + Console.WriteLine(@"Usage: NDecrypt.exe [flags] ... + +Possible values for : +e, encrypt - Encrypt the input files +d, decrypt - Decrypt the input files + +Possible values for [flags] (one or more can be used): +-dev, --development - Enable using development keys, if available +-f, --force - Force operation by avoiding sanity checks + + can be any file or folder that contains uncompressed items. +More than one path can be specified at a time."); } private enum RomType diff --git a/NDecrypt/ThreeDSTool.cs b/NDecrypt/ThreeDSTool.cs index fd9bb9a..0572db3 100644 --- a/NDecrypt/ThreeDSTool.cs +++ b/NDecrypt/ThreeDSTool.cs @@ -44,6 +44,14 @@ namespace NDecrypt /// public bool ProcessFile() { + // Ensure the constants are all set + Constants.Init(); + if (Constants.IsReady != true) + { + Console.WriteLine("Could not read keys from keys.bin. Please make sure the file exists and try again."); + return false; + } + // Make sure we have a file to process first Console.WriteLine(filename); if (!File.Exists(filename)) diff --git a/README.md b/README.md index a0d3c2f..b1f2230 100644 --- a/README.md +++ b/README.md @@ -16,20 +16,27 @@ This tool allows you to encrypt and decrypt your personally dumped NDS and N3DS ## So how do I use this? - NDecrypt.exe [-dev] ... + NDecrypt.exe [flags] ... - Possible values for : - encrypt, e - Encrypt the incoming files - decrypt, d - Decrypt the incoming files + Possible values for : + e, encrypt - Encrypt the input files + d, decrypt - Decrypt the input files + + Possible values for [flags] (one or more can be used): + -dev, --development - Enable using development keys, if available + -f, --force - Force operation by avoiding sanity checks + + can be any file or folder that contains uncompressed items. + More than one path can be specified at a time. -**Note:** This overwrites the incoming files, so make backups if you're working on your original, personal dumps. +**Note:** This overwrites the input files, so make backups if you're working on your original, personal dumps. **Note:** Mixed folders or inputs are also accepted, you can decrypt or encrypt multiple files, regardless of their type. This being said, you can only do encrypt OR decrypt at one time. ## I feel like something is missing... -You are! In fact, you may be asking, "Hey, what was that `keys.bin` you mentioned??". I'm glad you asked. It's used only for N3DS files but is required for running the program in general. If you only plan on using NDecrypt with Nintendo DS and DSi files, you can have a completely empty `keys.bin` in the folder. Since some people don't like reading code, you need the 9 16-bit keys in little endian format (most common extraction methods produce big endian, so keep that in mind). It's recommended that you fill with 0x00 if you don't have access to a particular value so it doesn't mess up the read. They need to be in the following order: +You are! In fact, you may be asking, "Hey, what was that `keys.bin` you mentioned??". I'm glad you asked. It's used only for Nintendo 3DS and New 3DS files. Since some people don't like reading code, you need the 9 16-bit keys in little endian format (most common extraction methods produce big endian, so keep that in mind). It's recommended that you fill with 0x00 if you don't have access to a particular value so it doesn't mess up the read. They need to be in the following order: - Hardware constant - KeyX0x10