Skip to content

Commit

Permalink
Attempt to patch ARM9 secure area if all attempts to match the filesi…
Browse files Browse the repository at this point in the history
…ze fail.
  • Loading branch information
AdmiralCurtiss committed May 30, 2014
1 parent 8cd1e3c commit 49b55ff
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ static void PatchArm9( System.IO.FileStream nds, uint pos, uint len ) {
newCompressedSize = (uint)data.Length;
}

if ( newCompressedSize != len ) {
// new ARM is (still) different, attempt to find the metadata in the ARM9 secure area and replace that
byte[] newCmpSizeBytes = BitConverter.GetBytes( newCompressedSize );
for ( int i = 0; i < 0x4000; i += 4 ) {
uint maybeSize = BitConverter.ToUInt32( data, i );
if ( maybeSize == len + 0x02000000 ) {
data[i + 0] = newCmpSizeBytes[0];
data[i + 1] = newCmpSizeBytes[1];
data[i + 2] = newCmpSizeBytes[2];
data[i + 3] = (byte)( newCmpSizeBytes[3] + 0x02 );
break;
}
}
}
#if DEBUG
uint newDecompressedSize = (uint)decData.Length;
uint newAdditionalCompressedSize = newDecompressedSize - newCompressedSize;
Expand Down

0 comments on commit 49b55ff

Please sign in to comment.