Add Wii U encryption support to context structure and cleanup logic

This commit is contained in:
2026-03-16 11:11:40 +00:00
parent 5857e16662
commit 93357cbf1f
2 changed files with 32 additions and 0 deletions

View File

@@ -344,6 +344,15 @@ typedef struct aaruformat_context
void *ps3_plaintext_regions; ///< Parsed Ps3PlaintextRegion array (max 32), NULL if not loaded
uint32_t ps3_plaintext_region_count; ///< Number of plaintext regions
bool ps3_encryption_initialized; ///< Whether lazy init has occurred
// Wii U encryption support (lazy-initialized on first use)
uint8_t *wiiu_disc_key; ///< Cached disc key (16 bytes), NULL if not loaded
void *wiiu_partition_regions; ///< Parsed WiiuPartitionRegion array, NULL if not loaded
uint32_t wiiu_partition_region_count; ///< Number of partition regions
bool wiiu_encryption_initialized; ///< Whether lazy init has occurred
uint8_t *wiiu_encrypted_block_cache; ///< Cached re-encrypted 0x8000-byte physical sector
uint64_t wiiu_cached_physical_sector; ///< Physical sector number of cached block
bool wiiu_cache_valid; ///< Whether the encrypted block cache is valid
} aaruformat_context;
/** \struct DumpHardwareEntriesWithData

View File

@@ -5293,6 +5293,29 @@ AARU_EXPORT int AARU_CALL aaruf_close(void *context)
ctx->ps3_plaintext_region_count = 0;
ctx->ps3_encryption_initialized = false;
// Free Wii U encryption context
if(ctx->wiiu_disc_key != NULL)
{
memset(ctx->wiiu_disc_key, 0, 16);
free(ctx->wiiu_disc_key);
ctx->wiiu_disc_key = NULL;
}
if(ctx->wiiu_partition_regions != NULL)
{
// Wipe keys from partition regions before freeing
uint32_t wiiu_count = ctx->wiiu_partition_region_count;
uint8_t *region_mem = (uint8_t *)ctx->wiiu_partition_regions;
// Each region entry contains a 16-byte key at offset 8; wipe the entire block
memset(region_mem, 0, wiiu_count * 24);
free(ctx->wiiu_partition_regions);
ctx->wiiu_partition_regions = NULL;
}
ctx->wiiu_partition_region_count = 0;
ctx->wiiu_encryption_initialized = false;
free(ctx->wiiu_encrypted_block_cache);
ctx->wiiu_encrypted_block_cache = NULL;
ctx->wiiu_cache_valid = false;
free(ctx->sector_id);
free(ctx->sector_ied);
free(ctx->sector_cpr_mai);