Skip to content

Commit

Permalink
Missed a couple
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Aug 8, 2024
1 parent 96ed279 commit 96f9715
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions NDecrypt.N3DS/ThreeDSTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ private void ProcessExeFSFileEntries(Cart cart,
continue;

// Get MiB-aligned block count and extra byte count
uint datalenM = ((fileHeader.FileSize) / (1024 * 1024));
uint datalenB = ((fileHeader.FileSize) % (1024 * 1024));
uint ctroffset = ((fileHeader.FileOffset + cart.MediaUnitSize()) / 0x10);
uint datalenM = fileHeader.FileSize / (1024 * 1024);
uint datalenB = fileHeader.FileSize % (1024 * 1024);
uint ctroffset = (fileHeader.FileOffset + cart.MediaUnitSize()) / 0x10;

// Create the ExeFS AES ciphers for this partition
byte[] exefsIVWithOffsetForHeader = AddToByteArray(cart.ExeFSIV(partitionIndex), (int)ctroffset);
Expand Down Expand Up @@ -571,8 +571,10 @@ private static void UpdateDecryptCryptoAndMasks(Cart cart, int partitionIndex, B
uint partitionOffsetMU = cart.Header!.PartitionsTable![partitionIndex]!.Offset;
uint partitionOffset = partitionOffsetMU * cart.MediaUnitSize();

// Write the new CryptoMethod
// Seek to the CryptoMethod location
writer.BaseStream.Seek(partitionOffset + 0x18B, SeekOrigin.Begin);

// Write the new CryptoMethod
writer.Write((byte)CryptoMethod.Original);
writer.Flush();

Expand Down Expand Up @@ -660,7 +662,8 @@ private bool EncryptRomFS(Cart cart,
// Encrypting RomFS for partitions 1 and up always use Key0x2C
if (partitionIndex > 0)
{
if (backupHeader!.Flags?.BitMasks.HasFlag(BitMasks.FixedCryptoKey) == true) // except if using zero-key
// Except if using zero-key
if (backupHeader!.Flags!.BitMasks.HasFlag(BitMasks.FixedCryptoKey))
{
NormalKey[partitionIndex] = 0x00;
}
Expand Down Expand Up @@ -719,15 +722,14 @@ private static void UpdateEncryptCryptoAndMasks(Cart cart, int partitionIndex, B
// Get the backup header
var backupHeader = cart.CardInfoHeader!.InitialData!.BackupHeader;

// Write the new CryptoMethod
// Seek to the CryptoMethod location
writer.BaseStream.Seek(partitionOffset + 0x18B, SeekOrigin.Begin);

// For partitions 1 and up, set crypto-method to 0x00
// If partition 0, restore crypto-method from backup flags
if (partitionIndex > 0)
writer.Write((byte)CryptoMethod.Original);
else
writer.Write((byte)backupHeader!.Flags!.CryptoMethod);
// Write the new CryptoMethod
// - For partitions 1 and up, set crypto-method to 0x00
// - If partition 0, restore crypto-method from backup flags
byte cryptoMethod = partitionIndex > 0 ? (byte)CryptoMethod.Original : (byte)backupHeader!.Flags!.CryptoMethod;
writer.Write(cryptoMethod);
writer.Flush();

// Seek to the BitMasks location
Expand Down

0 comments on commit 96f9715

Please sign in to comment.