Fix verifying incomplete DLC CIAs. (#76)

This commit is contained in:
Steven Smith
2018-10-17 05:08:29 -07:00
committed by profi200
parent b941838adb
commit 7b0a7bfaab
+8 -3
View File
@@ -251,6 +251,7 @@ clean:
void cia_verify_contents(cia_context *ctx, u32 actions) void cia_verify_contents(cia_context *ctx, u32 actions)
{ {
u16 contentflags; u16 contentflags;
u16 contentindex;
ctr_tmd_body *body; ctr_tmd_body *body;
ctr_tmd_contentchunk *chunk; ctr_tmd_contentchunk *chunk;
u8 *verify_buf; u8 *verify_buf;
@@ -263,6 +264,10 @@ void cia_verify_contents(cia_context *ctx, u32 actions)
fseeko64(ctx->file, ctx->offset + ctx->offsetcontent, SEEK_SET); fseeko64(ctx->file, ctx->offset + ctx->offsetcontent, SEEK_SET);
for(i = 0; i < getbe16(body->contentcount); i++) for(i = 0; i < getbe16(body->contentcount); i++)
{
contentindex = getbe16(chunk->index);
if(ctx->header.contentindex[contentindex >> 3] & (0x80 >> (contentindex & 7)))
{ {
content_size = getbe64(chunk->size) & 0xffffffff; content_size = getbe64(chunk->size) & 0xffffffff;
@@ -273,8 +278,8 @@ void cia_verify_contents(cia_context *ctx, u32 actions)
if(contentflags & 1 && !(actions & PlainFlag)) // Decrypt if needed if(contentflags & 1 && !(actions & PlainFlag)) // Decrypt if needed
{ {
ctx->iv[0] = (getbe16(chunk->index) >> 8) & 0xff; ctx->iv[0] = (contentindex >> 8) & 0xff;
ctx->iv[1] = getbe16(chunk->index) & 0xff; ctx->iv[1] = contentindex & 0xff;
ctr_init_cbc_decrypt(&ctx->aes, ctx->titlekey, ctx->iv); ctr_init_cbc_decrypt(&ctx->aes, ctx->titlekey, ctx->iv);
@@ -287,7 +292,7 @@ void cia_verify_contents(cia_context *ctx, u32 actions)
ctx->tmd.content_hash_stat[i] = 2; ctx->tmd.content_hash_stat[i] = 2;
free(verify_buf); free(verify_buf);
}
chunk++; chunk++;
} }
} }