Path is part of the args now

This commit is contained in:
Matt Nadareski
2024-10-12 01:42:02 -04:00
parent 993ce492b7
commit 747625c2b8
5 changed files with 35 additions and 41 deletions

View File

@@ -5,15 +5,17 @@
/// <summary>
/// Attempts to encrypt an input file
/// </summary>
/// <param name="filename">Name of the file to encrypt</param>
/// <param name="force">Indicates if the operation should be forced</param>
/// <returns>True if the file could be encrypted, false otherwise</returns>
bool EncryptFile(bool force);
bool EncryptFile(string filename, bool force);
/// <summary>
/// Attempts to decrypt an input file
/// </summary>
/// <param name="filename">Name of the file to decrypt</param>
/// <param name="force">Indicates if the operation should be forced</param>
/// <returns>True if the file could be decrypted, false otherwise</returns>
bool DecryptFile(bool force);
bool DecryptFile(string filename, bool force);
}
}

View File

@@ -14,11 +14,6 @@ namespace NDecrypt.N3DS
// https://www.3dbrew.org/wiki/CIA
public class CIATool : ITool
{
/// <summary>
/// Name of the input CIA file
/// </summary>
private readonly string filename;
/// <summary>
/// Decryption args to use while processing
/// </summary>
@@ -49,26 +44,27 @@ namespace NDecrypt.N3DS
/// </summary>
private readonly BigInteger[] NormalKey2C = new BigInteger[8];
public CIATool(string filename, DecryptArgs decryptArgs)
public CIATool(DecryptArgs decryptArgs)
{
this.filename = filename;
this.decryptArgs = decryptArgs;
}
#region Common Methods
/// <inheritdoc/>
public bool EncryptFile(bool force) => ProcessFile(encrypt: true, force);
public bool EncryptFile(string filename, bool force)
=> ProcessFile(filename, encrypt: true, force);
/// <inheritdoc/>
public bool DecryptFile(bool force) => ProcessFile(encrypt: false, force);
public bool DecryptFile(string filename, bool force)
=> ProcessFile(filename, encrypt: false, force);
/// <summary>
/// Process an input file given the input values
/// </summary>
/// <param name="encrypt">Indicates if the file should be encrypted or decrypted</param>
/// <param name="force">Indicates if the operation should be forced</param>
private bool ProcessFile(bool encrypt, bool force)
private bool ProcessFile(string filename, bool encrypt, bool force)
{
// Ensure the constants are all set
if (decryptArgs.IsReady != true)

View File

@@ -12,11 +12,6 @@ namespace NDecrypt.N3DS
{
public class ThreeDSTool : ITool
{
/// <summary>
/// Name of the input 3DS file
/// </summary>
private readonly string filename;
/// <summary>
/// Decryption args to use while processing
/// </summary>
@@ -47,26 +42,27 @@ namespace NDecrypt.N3DS
/// </summary>
private readonly BigInteger[] NormalKey2C = new BigInteger[8];
public ThreeDSTool(string filename, DecryptArgs decryptArgs)
public ThreeDSTool(DecryptArgs decryptArgs)
{
this.filename = filename;
this.decryptArgs = decryptArgs;
}
#region Common Methods
/// <inheritdoc/>
public bool EncryptFile(bool force) => ProcessFile(encrypt: true, force);
public bool EncryptFile(string filename, bool force)
=> ProcessFile(filename, encrypt: true, force);
/// <inheritdoc/>
public bool DecryptFile(bool force) => ProcessFile(encrypt: false, force);
public bool DecryptFile(string filename, bool force)
=> ProcessFile(filename, encrypt: false, force);
/// <summary>
/// Process an input file given the input values
/// </summary>
/// <param name="encrypt">Indicates if the file should be encrypted or decrypted</param>
/// <param name="force">Indicates if the operation should be forced</param>
private bool ProcessFile(bool encrypt, bool force)
private bool ProcessFile(string filename, bool encrypt, bool force)
{
// Ensure the constants are all set
if (decryptArgs.IsReady != true)

View File

@@ -10,11 +10,6 @@ namespace NDecrypt.Nitro
{
public class DSTool : ITool
{
/// <summary>
/// Name of the input DS/DSi file
/// </summary>
private readonly string filename;
#region Encryption process variables
private uint[] _cardHash = new uint[0x412];
@@ -22,15 +17,12 @@ namespace NDecrypt.Nitro
#endregion
public DSTool(string filename, DecryptArgs decryptArgs)
{
this.filename = filename;
}
public DSTool() { }
#region Encrypt
/// <inheritdoc/>
public bool EncryptFile(bool force)
public bool EncryptFile(string filename, bool force)
{
try
{
@@ -46,6 +38,10 @@ namespace NDecrypt.Nitro
return false;
}
// Reset state variables
_cardHash = new uint[0x412];
_arg2 = new uint[3];
// Encrypt the secure area
EncryptSecureArea(cart, force, reader, writer);
return true;
@@ -180,7 +176,7 @@ namespace NDecrypt.Nitro
#region Decrypt
/// <inheritdoc/>
public bool DecryptFile(bool force)
public bool DecryptFile(string filename, bool force)
{
try
{
@@ -189,13 +185,17 @@ namespace NDecrypt.Nitro
using var writer = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
// Deserialize the cart information
Cart? cart = NitroDeserializer.DeserializeStream(reader);
var cart = NitroDeserializer.DeserializeStream(reader);
if (cart == null)
{
Console.WriteLine("Error: Not a DS or DSi Rom!");
return false;
}
// Reset state variables
_cardHash = new uint[0x412];
_arg2 = new uint[3];
// Decrypt the secure area
DecryptSecureArea(cart, force, reader, writer);

View File

@@ -150,12 +150,12 @@ namespace NDecrypt
if (tool == null)
return;
if (encrypt && !tool.EncryptFile(force))
if (encrypt && !tool.EncryptFile(path, force))
{
Console.WriteLine("Encryption failed!");
return;
}
else if (!encrypt && !tool.DecryptFile(force))
else if (!encrypt && !tool.DecryptFile(path, force))
{
Console.WriteLine("Decryption failed!");
return;
@@ -204,19 +204,19 @@ More than one path can be specified at a time.");
{
case FileType.NDS:
Console.WriteLine("File recognized as Nintendo DS");
return new DSTool(filename, decryptArgs);
return new DSTool();
case FileType.NDSi:
Console.WriteLine("File recognized as Nintendo DS");
return new DSTool(filename, decryptArgs);
return new DSTool();
case FileType.iQueDS:
Console.WriteLine("File recognized as iQue DS");
return new DSTool(filename, decryptArgs);
return new DSTool();
case FileType.N3DS:
Console.WriteLine("File recognized as Nintendo 3DS");
return new ThreeDSTool(filename, decryptArgs);
return new ThreeDSTool(decryptArgs);
case FileType.N3DSCIA:
Console.WriteLine("File recognized as Nintendo 3DS CIA [CAUTION: NOT WORKING CURRENTLY]");
return new CIATool(filename, decryptArgs);
return new CIATool(decryptArgs);
case FileType.NULL:
default:
Console.WriteLine($"Unrecognized file format for {filename}. Expected *.nds, *.nds.enc, *.srl, *.dsi, *.3ds");