Index: es_title.c =================================================================== RCS file: /home/products/cvstree/sw_c/common/os/es/es_title.c,v retrieving revision 1.141.12.5 retrieving revision 1.141.12.7 diff -r1.141.12.5 -r1.141.12.7 34a35,121 > static IOSCAesKey __zKey = {0}; > > /* > * Assign the correct backup key as follows: > * > * If the currently running titleId is System Menu (0x0000000100000002) > * then > * Use the correct default backup key (IOSC_BACKUP_ENC_HANDLE) > * else { > * If TMD (of backup/restore titleId) has > * 1. ((ES_TITLE_TYPE_DATA==1) && (ES_TITLE_TYPE_CACHE_DATA==1)) AND > * 2. titleIds are > * a) sXA?:0x00010005735841?? - 1 data title for GH4 > * b) sZA? - sZH?:0x00010005735A41?? - 0x00010005735A48?? inclusive > * 8 data tiles for RB2 > * then > * Use the new zero backup key (backupKey2Handle) > * } > */ > #define GH4_TITLE_ID_64 0x00010005735841FFLL > #define RB2_TITLE_ID_64_START 0x00010005735A41FFLL > #define RB2_TITLE_ID_64_END 0x00010005735A48FFLL > #define GAME_CODE_REGION_MASK 0x00000000000000FFLL > > #define ES_TITLE_TYPE_DATA_MASK (ES_TITLE_TYPE_DATA|ES_TITLE_TYPE_CACHE_DATA) > > static ESError > __esAssignBackupKey(ESTitleCtx* titleCtx) > { > ESError rv = ES_ERR_OK; > ESTitleMeta *tmd = (ESTitleMeta *)(titleCtx->pTmd); > ESTitleId tid; > IOSCSecretKeyHandle backupKey2Handle; > > > /* Init with the default backup key */ > titleCtx->hTitleKey = IOSC_BACKUP_ENC_HANDLE; > > /* If currently running title is System Menu, then we're done */ > if ((ntohll((__launchCtx.pTmd)->head.titleId)) == ES_TITLE_ID_SYS_APP_64) { > esPrint(ES_DEBUG_WARN, "* Using default backup key for SysMenu\n"); > goto out; > } > > /* Get backup/restore titleId */ > tid = ntohll(tmd->head.titleId); > > /* Check for correct data title type and title Id ranges */ > if ((ntohl(tmd->head.type) & ES_TITLE_TYPE_DATA_MASK) > == ES_TITLE_TYPE_DATA_MASK) { > tid |= GAME_CODE_REGION_MASK; > esPrint(ES_DEBUG_INFO, "* Found data title (%08X), tid=%08llX\n", > ntohl(tmd->head.type), tid); > if ((tid == GH4_TITLE_ID_64) || > ((tid >= RB2_TITLE_ID_64_START) && (tid <= RB2_TITLE_ID_64_END))) { > > /* Initialize backup key 2 */ > rv = IOSC_CreateObject(&backupKey2Handle, IOSC_SECRETKEY_TYPE, > IOSC_ENC_SUBTYPE); > if (rv != IOS_ERROR_OK) { > esPrint(ES_DEBUG_ERROR,"Create backup key2 failed %d\n", rv); > goto out; > } > > rv = IOSC_ImportSecretKey(backupKey2Handle, 0, 0, > IOSC_NOSIGN_NOENC, 0, 0, (u8 *)__zKey); > if (rv != IOS_ERROR_OK) { > esPrint(ES_DEBUG_ERROR, "Import backup key2 failed %d\n", rv); > goto out; > } > > esPrint(ES_DEBUG_WARN, "* Using z backup key (handle 0x%x), " > "tid 0x%08llx\n", backupKey2Handle, tid); > > titleCtx->hTitleKey = backupKey2Handle; > } > } > > if (titleCtx->hTitleKey == IOSC_BACKUP_ENC_HANDLE) { > esPrint(ES_DEBUG_WARN, "* Using default backup key, tid 0x%08llx\n", > tid); > } > > out: > return(rv); > } > 398a486 > static ESError __esCleanUpIncompleteImport(ESTitleMeta* ); 411a500,516 > /* Clean up any incomplete import under /import for specified title ID */ > rv = __esCleanUpIncompleteImport((ESTitleMeta*)tmd); > if (rv!=ES_ERR_OK) { > if (rv==ISFS_ERROR_NOEXISTS) { > esPrint(ES_DEBUG_INFO, "nothing to clean up /import for title" > " 0x%llx, rv=%d -> OK\n", > ntohll(((ESTitleMeta*)tmd)->head.titleId), rv); > } > else { > esPrint(ES_DEBUG_ERROR, "failed to clean up /import for title" > " 0x%llx, rv=%d\n", > ntohll(((ESTitleMeta*)tmd)->head.titleId), rv); > /* To be backward compatible, we continue instead of quitting */ > // goto out; > } > } > 1180,1181c1285,1286 < ESError < esImportTitleCancel(ESTitleCtx* titleCtx) --- > static ESError > __esCleanUpIncompleteImport(ESTitleMeta* pTmdMain) 1195,1196d1299 < ES_ENTRY(); < 1198c1301 < if (titleCtx==NULL || titleCtx->fd>=0 || titleCtx->pTmd==NULL) { --- > if (pTmdMain==NULL) { 1202,1204d1304 < if (!titleCtx->valid) { < goto out; < } 1214c1314 < tid = ntohll((titleCtx->pTmd)->head.titleId); --- > tid = ntohll(pTmdMain->head.titleId); 1270a1371,1392 > return rv; > } > > ESError > esImportTitleCancel(ESTitleCtx* titleCtx) > { > ESError rv = ES_ERR_OK; > > ES_ENTRY(); > > /* sanity check */ > if (titleCtx==NULL || titleCtx->fd>=0 || titleCtx->pTmd==NULL) { > rv = ES_ERR_INVALID; > goto out; > } > if (!titleCtx->valid) { > goto out; > } > > rv = __esCleanUpIncompleteImport(titleCtx->pTmd); > > out: 3036c3158,3163 < titleCtx->hTitleKey = IOSC_BACKUP_ENC_HANDLE; --- > rv = __esAssignBackupKey(titleCtx); > if (rv != ES_ERR_OK) { > esPrint(ES_DEBUG_ERROR, "assign backup key failed %d\n", rv); > goto out; > } > 3121c3248,3254 < ctx->hTitleKey = IOSC_BACKUP_ENC_HANDLE; --- > /* Set the title key to the backup key */ > rv = __esAssignBackupKey(ctx); > if (rv != ES_ERR_OK) { > esPrint(ES_DEBUG_ERROR, "assign backup key failed %d\n", rv); > goto out; > } >