Fix NAX0 decryption

Decryption would fail because the encrypted file wasn't always a multiple of the encryption sector length.
This makes sure the data to be decrypted is a multiple of the sector length.
This commit is contained in:
Alex Barney 2018-06-14 11:54:19 -05:00
parent 42849efaa4
commit 1856b5db23

5
nax0.c
View file

@ -129,8 +129,9 @@ void nax0_save(nax0_ctx_t *ctx) {
fprintf(stderr, "Failed to read file!\n");
exit(EXIT_FAILURE);
}
aes_xts_decrypt(ctx->aes_ctx, buf, buf, read_size, (ofs - 0x4000) >> 14, 0x4000);
uint64_t dec_size = (read_size + 0x3FFF) & ~0x3FFF;
aes_xts_decrypt(ctx->aes_ctx, buf, buf, dec_size, (ofs - 0x4000) >> 14, 0x4000);
if (fwrite(buf, 1, read_size, f_dec) != read_size) {
fprintf(stderr, "Failed to write file!\n");