diff --git a/makerom/cardinfo.c b/makerom/cardinfo.c index f2ac692..e9b80a4 100644 --- a/makerom/cardinfo.c +++ b/makerom/cardinfo.c @@ -139,8 +139,12 @@ int SetCardInfoBitmask(cardinfo_hdr *hdr, cci_settings *set) } str = set->rsf->CardInfo.CryptoType; - if(!str) - bitmask |= 0;//(3*0x40); + if(!str) { + if(set->options.useExternalSdkCardInfo) + bitmask |= (3*0x40); + else + bitmask |= 0; + } else{ int val = strtol(str,NULL,10); if(val < 0 || val > 3) { diff --git a/makerom/crypto.c b/makerom/crypto.c index 9fd99ee..e83b9f7 100644 --- a/makerom/crypto.c +++ b/makerom/crypto.c @@ -153,17 +153,13 @@ u32 GetSigHashLen(u32 sig_type) { switch(sig_type){ case RSA_4096_SHA1: - return 0x14; - case RSA_4096_SHA256: - return 0x20; case RSA_2048_SHA1: - return 0x14; - case RSA_2048_SHA256: - return 0x20; case ECC_SHA1: - return 0x14; + return SHA_1_LEN; + case RSA_4096_SHA256: + case RSA_2048_SHA256: case ECC_SHA256: - return 0x20; + return SHA_256_LEN; } return 0; } diff --git a/makerom/crypto.h b/makerom/crypto.h index 617fdc8..95b1ea5 100644 --- a/makerom/crypto.h +++ b/makerom/crypto.h @@ -36,6 +36,12 @@ typedef enum CTR_SHA_256, } ctr_sha_modes; +typedef enum +{ + SHA_1_LEN = 0x14, + SHA_256_LEN = 0x20, +} sha_hash_len; + typedef enum { RSA_4096_PUBK = 0, diff --git a/makerom/romfs_gen.c b/makerom/romfs_gen.c index 04f81b6..3ad516c 100644 --- a/makerom/romfs_gen.c +++ b/makerom/romfs_gen.c @@ -202,9 +202,9 @@ int CalcRomfsSize(romfs_buildctx *ctx) //printf("predict level sizes\n"); ctx->level[3].size = romfsHdrSize + ctx->m_dataLen; // data - ctx->level[2].size = align(ctx->level[3].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * 0x20 ; - ctx->level[1].size = align(ctx->level[2].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * 0x20 ; - ctx->level[0].size = align(ctx->level[1].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * 0x20 + align(sizeof(ivfc_hdr),0x10); // hdr + ctx->level[2].size = align(ctx->level[3].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * SHA_256_LEN ; + ctx->level[1].size = align(ctx->level[2].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * SHA_256_LEN ; + ctx->level[0].size = align(ctx->level[1].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE * SHA_256_LEN + align(sizeof(ivfc_hdr),0x10); // hdr ctx->romfsHeaderSize = ctx->level[0].size; @@ -320,13 +320,13 @@ void AddDirHashKey(romfs_buildctx *ctx, u32 parent, fs_romfs_char* path, u32 dir { u32 hash = CalcPathHash(parent,path,0,fs_u16StrLen(path)); u32 index = hash % ctx->m_dirUTableEntry; - if(ctx->dirUTable[index] == 0xffffffff) ctx->dirUTable[index] = dirOffset; + if(ctx->dirUTable[index] == ROMFS_UNUSED_ENTRY) ctx->dirUTable[index] = dirOffset; else { romfs_direntry * curdir = (romfs_direntry*)(ctx->dirTable + ctx->dirUTable[index]); while(1) { - if(*(u32*)curdir->weirdoffset == 0xffffffff) + if(*(u32*)curdir->weirdoffset == ROMFS_UNUSED_ENTRY) { *(u32*)curdir->weirdoffset = dirOffset; break; @@ -343,13 +343,13 @@ void AddFileHashKey(romfs_buildctx *ctx,u32 parent, fs_romfs_char *path, u32 fil { u32 hash = CalcPathHash(parent,path,0,fs_u16StrLen(path)); u32 index = hash % ctx->m_fileUTableEntry; - if(ctx->fileUTable[index] == 0xffffffff) ctx->fileUTable[index] = fileOffset; + if(ctx->fileUTable[index] == ROMFS_UNUSED_ENTRY) ctx->fileUTable[index] = fileOffset; else { romfs_fileentry * curfile = (romfs_fileentry*)(ctx->fileTable + ctx->fileUTable[index]); while(1) { - if(*(u32*)curfile->weirdoffset == 0xffffffff) + if(*(u32*)curfile->weirdoffset == ROMFS_UNUSED_ENTRY) { *(u32*)curfile->weirdoffset = fileOffset; break; @@ -368,7 +368,7 @@ int AddFileToRomfs(romfs_buildctx *ctx, fs_file *file, u32 parent, u32 sibling) u32_to_u8(entry->parentdiroffset,parent,LE); u32_to_u8(entry->siblingoffset,sibling,LE); - u32_to_u8(entry->weirdoffset,0xffffffff,LE); + u32_to_u8(entry->weirdoffset,ROMFS_UNUSED_ENTRY,LE); // Import Name u32_to_u8(entry->namesize,file->name_len,LE); @@ -388,6 +388,7 @@ int AddFileToRomfs(romfs_buildctx *ctx, fs_file *file, u32 parent, u32 sibling) } else u64_to_u8(entry->dataoffset,0x40,LE); + AddFileHashKey(ctx,parent,file->name,ctx->u_fileTableLen); ctx->u_fileTableLen += sizeof(romfs_fileentry) + align(file->name_len,4); @@ -401,7 +402,7 @@ int AddDirToRomfs(romfs_buildctx *ctx, fs_dir *fs, u32 parent, u32 sibling) u32_to_u8(entry->parentoffset,parent,LE); u32_to_u8(entry->siblingoffset,sibling,LE); - u32_to_u8(entry->weirdoffset,0xffffffff,LE); + u32_to_u8(entry->weirdoffset,ROMFS_UNUSED_ENTRY,LE); u32 Currentdir = ctx->u_dirTableLen; @@ -485,7 +486,7 @@ void BuildIvfcHeader(romfs_buildctx *ctx) memcpy(ctx->ivfcHdr->magic,"IVFC",4); u32_to_u8(ctx->ivfcHdr->id,0x10000,LE); - u32 masterHashSize = ( align(ctx->level[1].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE ) * 0x20 ; + u32 masterHashSize = ( align(ctx->level[1].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE ) * SHA_256_LEN ; u32_to_u8(ctx->ivfcHdr->masterHashSize,masterHashSize,LE); for(int i = 1; i < 4; i++){ @@ -505,7 +506,7 @@ void GenIvfcHashTree(romfs_buildctx *ctx) u32 numHashes = align(ctx->level[i+1].size,ROMFS_BLOCK_SIZE) / ROMFS_BLOCK_SIZE; for(u32 j = 0; j < numHashes; j++){ u8 *datapos = (u8*)(ctx->level[i+1].pos + ROMFS_BLOCK_SIZE * j); - u8 *hashpos = (u8*)(ctx->level[i].pos + 0x20 * j); + u8 *hashpos = (u8*)(ctx->level[i].pos + SHA_256_LEN * j); ShaCalc(datapos, ROMFS_BLOCK_SIZE, hashpos, CTR_SHA_256); } }