Skip to content

Commit

Permalink
Fix incorrect size being used
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Nov 15, 2024
1 parent ce54eb2 commit dc4bd15
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions NDecrypt.Core/ThreeDSTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ private void DecryptExeFSFileEntries(N3DS cart, int index, Stream input, Stream
output.Seek(exeFsFilesOffset + fileHeader.FileOffset, SeekOrigin.Begin);

// Setup and perform the encryption
uint exeFsSize = cart.GetExeFSSize(index);
PerformAESOperation(exeFsSize,
PerformAESOperation(fileHeader.FileSize,
firstCipher,
secondCipher,
input,
Expand Down Expand Up @@ -650,10 +649,6 @@ private bool EncryptExeFS(N3DS cart, int index, Stream input, Stream output)
return false;
}

// Get the ExeFS offset
uint exeFsHeaderOffset = cart.GetExeFSOffset(index);
uint exeFsFilesOffset = exeFsHeaderOffset + cart.MediaUnitSize;

// For all but the original crypto method, process each of the files in the table
var backupHeader = cart.BackupHeader;
if (backupHeader!.Flags!.CryptoMethod != CryptoMethod.Original)
Expand All @@ -662,6 +657,10 @@ private bool EncryptExeFS(N3DS cart, int index, Stream input, Stream output)
// Encrypt the filename table
EncryptExeFSFilenameTable(cart, index, input, output);

// Get the ExeFS offset
uint exeFsHeaderOffset = cart.GetExeFSOffset(index);
uint exeFsFilesOffset = exeFsHeaderOffset + cart.MediaUnitSize;

// Seek to the ExeFS
input.Seek(exeFsHeaderOffset, SeekOrigin.Begin);
output.Seek(exeFsHeaderOffset, SeekOrigin.Begin);
Expand Down Expand Up @@ -769,8 +768,7 @@ private void EncryptExeFSFileEntries(N3DS cart, int index, Stream input, Stream
output.Seek(exeFsFilesOffset + fileHeader.FileOffset, SeekOrigin.Begin);

// Setup and perform the encryption
uint exeFsSize = cart.GetExeFSSize(index);
PerformAESOperation(exeFsSize,
PerformAESOperation(fileHeader.FileSize,
firstCipher,
secondCipher,
input,
Expand Down

0 comments on commit dc4bd15

Please sign in to comment.