Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix potential crash encrypting with Modcrypt, invalid header hash generation and corruption of Modcrypt after arm9 changes #36

Merged
merged 5 commits into from
May 12, 2024

Conversation

pleonex
Copy link
Member

@pleonex pleonex commented May 11, 2024

Fix several bugs related to Modcrypt (d)encryption and ROM header hash generation, especially after changes on the arm9 and/or its code parameters (such as compression length):

  • Potential unhandled exception, calculating the key for Modcrypt (d)encryption for retail software. This may happen during ROM reading or writing.
    • The reason is that by default BigInteger are signed values and after the bitwise OR operation, the sign may be affected changing a 22-bytes length number to a 6-bytes length number.
  • Fix generation of arm9 secure area when its code parameters changes. The hash was calculated with arm9 content before patching the code parameter values such as file compressed length.
  • Fix program HMAC generation: it was calculated with an old value of arm9 secure are hash
  • Fix corruption of modcrypt content: the content was encrypted with an old arm9 secure hash which is part of the key.

Also fix the build by installing .NET 6 SDK and bumping .NET 8 SDK.

Quality check list

  • Related code has been tested automatically or manually: tested with the problematic software and updated tests
  • Related documentation is updated
  • I acknowledge I have read and filled this checklist and accept the
    developer certificate of origin

Acceptance criteria

The Modcrypt key generation does not fail.
Every hash of the encrypted content is valid after changing the arm9 content.

Follow-up work

None

Example

N/A

@pleonex pleonex added the bug Something isn't working label May 11, 2024
@pleonex pleonex self-assigned this May 11, 2024
pleonex added 4 commits May 11, 2024 15:27
It happens when code parameters (arm9 length) change
PorgramMac needs valid secure area hash
Modcrypt use the arm9secure hash for the key, but we don't use the newly generated but an old one
@pleonex pleonex changed the title 🐛 Potential crash generating modcrypt key on retail software 🐛 Fix potential crash encrypting with Modcrypt, invalid DSi hash generation and corruption of Modcrypt after arm9 changes May 12, 2024
@pleonex pleonex changed the title 🐛 Fix potential crash encrypting with Modcrypt, invalid DSi hash generation and corruption of Modcrypt after arm9 changes 🐛 Fix potential crash encrypting with Modcrypt, invalid header hash generation and corruption of Modcrypt after arm9 changes May 12, 2024
@pleonex pleonex marked this pull request as ready for review May 12, 2024 12:12
@pleonex pleonex merged commit b43ecce into main May 12, 2024
5 checks passed
@pleonex pleonex deleted the feature/fix-modcrypt-key branch May 12, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant