From db7c7ee2734a9ec634cf6e0fa367f67013127917 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 19 Feb 2025 15:47:05 -0500 Subject: [PATCH] Add simple info check (fixes #18) --- NDecrypt.Core/DSTool.cs | 34 ++++++++++++++++++++++++++++++++-- NDecrypt.Core/ThreeDSTool.cs | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/NDecrypt.Core/DSTool.cs b/NDecrypt.Core/DSTool.cs index 7489b64..a52d47e 100644 --- a/NDecrypt.Core/DSTool.cs +++ b/NDecrypt.Core/DSTool.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using SabreTools.IO.Extensions; using SabreTools.Models.Nitro; using SabreTools.Serialization.Wrappers; @@ -590,8 +591,37 @@ namespace NDecrypt.Core /// public string? GetInformation(string filename) { - // TODO: Get decryption status - return null; + try + { + // Open the file for reading + using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + + // Deserialize the cart information + var cart = Nitro.Create(input); + if (cart?.Model == null) + return "Error: Not a DS or DSi Rom!"; + + // Get a string builder for the status + var sb = new StringBuilder(); + sb.Append("Secure Area: "); + + // Get the encryption status + bool? decrypted = CheckIfDecrypted(input); + if (decrypted == null) + sb.Append("Empty"); + else if (decrypted == true) + sb.Append("Decrypted"); + else + sb.Append("English"); + + // Return the status for the secure area + return sb.ToString(); + } + catch (Exception ex) + { + Console.WriteLine(ex); + return null; + } } #endregion diff --git a/NDecrypt.Core/ThreeDSTool.cs b/NDecrypt.Core/ThreeDSTool.cs index 66272ad..cd77360 100644 --- a/NDecrypt.Core/ThreeDSTool.cs +++ b/NDecrypt.Core/ThreeDSTool.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using SabreTools.IO.Extensions; using SabreTools.Models.N3DS; using SabreTools.Serialization.Wrappers; @@ -871,14 +872,40 @@ namespace NDecrypt.Core } #endregion - + #region Info /// public string? GetInformation(string filename) { - // TODO: Get decryption status - return null; + try + { + // Open the file for reading + using var input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + + // Deserialize the cart information + var cart = N3DS.Create(input); + if (cart?.Model == null) + return "Error: Not a 3DS cart image!"; + + // Get a string builder for the status + var sb = new StringBuilder(); + + // Iterate over all 8 NCCH partitions + for (int p = 0; p < 8; p++) + { + bool decrypted = cart.PossiblyDecrypted(p); + sb.AppendLine($"Partition {p}: {(decrypted ? "Decrypted" : "Encrypted")}"); + } + + // Return the status for all partitions + return sb.ToString(); + } + catch (Exception ex) + { + Console.WriteLine(ex); + return null; + } } #endregion