[ctrtool] Fix ctrtool bug where content wouldn't extract.

This commit is contained in:
jakcron
2018-08-20 14:17:32 +08:00
parent f585df73a4
commit b941838adb
+9 -7
View File
@@ -42,6 +42,7 @@ void cia_save(cia_context* ctx, u32 type, u32 flags)
u64 offset; u64 offset;
u64 size; u64 size;
u16 contentflags; u16 contentflags;
u16 contentindex;
u8 docrypto; u8 docrypto;
filepath* path = 0; filepath* path = 0;
ctr_tmd_body *body; ctr_tmd_body *body;
@@ -102,17 +103,18 @@ void cia_save(cia_context* ctx, u32 type, u32 flags)
chunk = (ctr_tmd_contentchunk*)(body->contentinfo + (sizeof(ctr_tmd_contentinfo) * TMD_MAX_CONTENTS)); chunk = (ctr_tmd_contentchunk*)(body->contentinfo + (sizeof(ctr_tmd_contentinfo) * TMD_MAX_CONTENTS));
for(i = 0; i < getbe16(body->contentcount); i++) { for(i = 0; i < getbe16(body->contentcount); i++) {
if(ctx->header.contentindex[i >> 3] & (0x80 >> (i & 7))) { contentflags = getbe16(chunk->type);
sprintf(tmpname, "%s.%04x.%08x", path->pathname, getbe16(chunk->index), getbe32(chunk->id)); contentindex = getbe16(chunk->index);
fprintf(stdout, "Saving content #%04x to %s\n", getbe16(chunk->index), tmpname); docrypto = (contentflags & 1) && !(flags & PlainFlag);
contentflags = getbe16(chunk->type); if(ctx->header.contentindex[contentindex >> 3] & (0x80 >> (contentindex & 7))) {
docrypto = contentflags & 1 && !(flags & PlainFlag); sprintf(tmpname, "%s.%04x.%08x", path->pathname, contentindex, getbe32(chunk->id));
fprintf(stdout, "Saving content #%04x to %s\n", contentindex, tmpname);
if(docrypto) // Decrypt if needed if(docrypto) // 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);
} }