Fix installer system CMD handling

This commit is contained in:
d0k3 2020-07-31 10:45:35 +02:00
parent e744be504b
commit 829880994f
2 changed files with 12 additions and 7 deletions

View File

@ -21,8 +21,10 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) {
proto.n_entries = max_cnt_idx + 1; proto.n_entries = max_cnt_idx + 1;
proto.n_cmacs = content_count; proto.n_cmacs = content_count;
proto.unknown = 1; proto.unknown = 1;
memset(proto.cmac, 0x00, 0x10);
cmd = (CmdHeader*) malloc(CMD_SIZE(&proto)); cmd = (CmdHeader*) malloc(CMD_SIZE(&proto));
if (!cmd) return NULL; if (!cmd) return NULL;
memset(cmd, 0x00, CMD_SIZE(&proto));
memcpy(cmd, &proto, sizeof(CmdHeader)); memcpy(cmd, &proto, sizeof(CmdHeader));
cmd->unknown = 0x0; // this means no CMACs, only valid for NAND cmd->unknown = 0x0; // this means no CMACs, only valid for NAND
@ -52,10 +54,9 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) {
} }
} }
// set CMACs to 0xFF // set CMACs to 0x00
u8* cnt_cmac = (u8*) (cnt_id_2nd + cmd->n_cmacs); u8* cnt_cmac = (u8*) (cnt_id_2nd + cmd->n_cmacs);
memset(cmd->cmac, 0xFF, 0x10); memset(cnt_cmac, 0x00, 0x10 * cmd->n_entries);
memset(cnt_cmac, 0xFF, 0x10 * cmd->n_entries);
// we still need to fix / set the CMACs inside the CMD file! // we still need to fix / set the CMACs inside the CMD file!
return cmd; return cmd;

View File

@ -1361,10 +1361,12 @@ u32 InstallCiaSystemData(CiaStub* cia, const char* drv) {
TicketCommon* ticket = &(cia->ticket); TicketCommon* ticket = &(cia->ticket);
TitleMetaData* tmd = &(cia->tmd); TitleMetaData* tmd = &(cia->tmd);
TmdContentChunk* content_list = cia->content_list; TmdContentChunk* content_list = cia->content_list;
bool syscmd = ((*drv == '1') || (*drv == '4'));
bool sdtie = ((*drv == 'A') || (*drv == 'B'));
u32 content_count = getbe16(tmd->content_count); u32 content_count = getbe16(tmd->content_count);
u8* title_id = ticket->title_id; u8* title_id = ticket->title_id;
bool sdtie = ((*drv == 'A') || (*drv == 'B'));
bool syscmd = (((*drv == '1') || (*drv == '4')) ||
(((*drv == '2') || (*drv == '5')) && (title_id[3] != 0x04)));
char path_titledb[32]; char path_titledb[32];
char path_ticketdb[32]; char path_ticketdb[32];
@ -1404,7 +1406,6 @@ u32 InstallCiaSystemData(CiaStub* cia, const char* drv) {
// build the cmd // build the cmd
cmd = BuildAllocCmdData(tmd); cmd = BuildAllocCmdData(tmd);
if (!cmd) return 1; if (!cmd) return 1;
cmd->unknown = 0xFFFFFFFE; // mark this as custom built
// generate all the paths // generate all the paths
snprintf(path_titledb, 32, "%2.2s/dbs/title.db", snprintf(path_titledb, 32, "%2.2s/dbs/title.db",
@ -1489,7 +1490,10 @@ u32 InstallCiaSystemData(CiaStub* cia, const char* drv) {
InitImgFS(path_bak); InitImgFS(path_bak);
// fix CMACs where required // fix CMACs where required
if (!syscmd) FixFileCmac(path_cmd, true); if (!syscmd) {
cmd->unknown = 0xFFFFFFFE; // mark this as custom built
FixFileCmac(path_cmd, true);
}
return 0; return 0;
} }