@@ -1494,7 +1494,7 @@ u32 UninstallGameDataTie(const char* path, bool remove_tie, bool remove_ticket,
1494
1494
}
1495
1495
1496
1496
u32 InstallCiaContent (const char * drv , const char * path_content , u32 offset , u32 size ,
1497
- TmdContentChunk * chunk , const u8 * title_id , const u8 * titlekey , bool cxi_fix ) {
1497
+ TmdContentChunk * chunk , const u8 * title_id , const u8 * titlekey , bool cxi_fix , bool cdn_decrypt ) {
1498
1498
char dest [256 ];
1499
1499
1500
1500
// create destination path and ensure it exists
@@ -1547,7 +1547,7 @@ u32 InstallCiaContent(const char* drv, const char* path_content, u32 offset, u32
1547
1547
for (u32 i = 0 ; (i < size ) && (ret == 0 ); i += STD_BUFFER_SIZE ) {
1548
1548
u32 read_bytes = min (STD_BUFFER_SIZE , (size - i ));
1549
1549
if (fvx_read (& ofile , buffer , read_bytes , & bytes_read ) != FR_OK ) ret = 1 ;
1550
- if (cia_crypto && (DecryptCiaContentSequential (buffer , read_bytes , ctr_in , titlekey ) != 0 )) ret = 1 ;
1550
+ if (( cia_crypto || cdn_decrypt ) && (DecryptCiaContentSequential (buffer , read_bytes , ctr_in , titlekey ) != 0 )) ret = 1 ;
1551
1551
if ((i == 0 ) && cxi_fix && (SetNcchSdFlag (buffer ) != 0 )) ret = 1 ;
1552
1552
if (i == 0 ) sha_init (SHA256_MODE );
1553
1553
sha_update (buffer , read_bytes );
@@ -1820,7 +1820,7 @@ u32 InstallFromCiaFile(const char* path_cia, const char* path_dest) {
1820
1820
u16 index = getbe16 (chunk -> index );
1821
1821
if (!(cnt_index [index /8 ] & (1 << (7 - (index %8 ))))) continue ; // don't try to install missing contents
1822
1822
if (InstallCiaContent (path_dest , path_cia , next_offset , size ,
1823
- chunk , title_id , titlekey , false) != 0 ) {
1823
+ chunk , title_id , titlekey , false, false ) != 0 ) {
1824
1824
free (cia );
1825
1825
return 1 ;
1826
1826
}
@@ -1926,6 +1926,8 @@ u32 BuildInstallFromTmdFileBuffered(const char* path_tmd, const char* path_dest,
1926
1926
free (ticket_tmp );
1927
1927
return 1 ;
1928
1928
}
1929
+ memcpy (ticket -> titlekey , ticket_tmp -> titlekey , 0x10 );
1930
+ ticket -> commonkey_idx = ticket_tmp -> commonkey_idx ;
1929
1931
free (ticket_tmp );
1930
1932
} else {
1931
1933
Ticket * ticket_tmp = NULL ;
@@ -1983,7 +1985,7 @@ u32 BuildInstallFromTmdFileBuffered(const char* path_tmd, const char* path_dest,
1983
1985
return 1 ;
1984
1986
}
1985
1987
if (install && (InstallCiaContent (path_dest , path_content , 0 , (u32 ) getbe64 (chunk -> size ),
1986
- chunk , title_id , titlekey , false) != 0 )) {
1988
+ chunk , title_id , titlekey , false, cdn ) != 0 )) {
1987
1989
ShowPrompt (false, "ID %016llX.%08lX\nInstall content failed" , getbe64 (title_id ), getbe32 (chunk -> id ));
1988
1990
return 1 ;
1989
1991
}
@@ -2023,7 +2025,7 @@ u32 InstallFromTmdFile(const char* path_tmd, const char* path_dest) {
2023
2025
void * buffer = (void * ) malloc (sizeof (CiaStub ));
2024
2026
if (!buffer ) return 1 ;
2025
2027
2026
- u32 ret = BuildInstallFromTmdFileBuffered (path_tmd , path_dest , false , true, buffer , true);
2028
+ u32 ret = BuildInstallFromTmdFileBuffered (path_tmd , path_dest , true , true, buffer , true);
2027
2029
2028
2030
free (buffer );
2029
2031
return ret ;
@@ -2088,7 +2090,7 @@ u32 BuildInstallFromNcchFile(const char* path_ncch, const char* path_dest, bool
2088
2090
TmdContentChunk * chunk = cia -> content_list ;
2089
2091
memset (chunk , 0 , sizeof (TmdContentChunk )); // nothing else to do
2090
2092
if ((!install && (InsertCiaContent (path_dest , path_ncch , 0 , 0 , chunk , NULL , false, true, false) != 0 )) ||
2091
- (install && (InstallCiaContent (path_dest , path_ncch , 0 , 0 , chunk , title_id , NULL , true) != 0 ))) {
2093
+ (install && (InstallCiaContent (path_dest , path_ncch , 0 , 0 , chunk , title_id , NULL , true, false ) != 0 ))) {
2092
2094
free (cia );
2093
2095
return 1 ;
2094
2096
}
@@ -2167,7 +2169,7 @@ u32 BuildInstallFromNcsdFile(const char* path_ncsd, const char* path_dest, bool
2167
2169
if ((!install && (InsertCiaContent (path_dest , path_ncsd ,
2168
2170
offset , size , chunk ++ , NULL , false, (i == 0 ), false) != 0 )) ||
2169
2171
(install && (InstallCiaContent (path_dest , path_ncsd ,
2170
- offset , size , chunk ++ , title_id , NULL , (i == 0 )) != 0 ))) {
2172
+ offset , size , chunk ++ , title_id , NULL , (i == 0 ), false ) != 0 ))) {
2171
2173
free (cia );
2172
2174
return 1 ;
2173
2175
}
@@ -2255,7 +2257,7 @@ u32 BuildInstallFromNdsFile(const char* path_nds, const char* path_dest, bool in
2255
2257
TmdContentChunk * chunk = cia -> content_list ;
2256
2258
memset (chunk , 0 , sizeof (TmdContentChunk )); // nothing else to do
2257
2259
if ((!install && (InsertCiaContent (path_dest , path_nds , 0 , 0 , chunk , NULL , false, false, false) != 0 )) ||
2258
- (install && (InstallCiaContent (path_dest , path_nds , 0 , 0 , chunk , title_id , NULL , false) != 0 ))) {
2260
+ (install && (InstallCiaContent (path_dest , path_nds , 0 , 0 , chunk , title_id , NULL , false, false ) != 0 ))) {
2259
2261
free (cia );
2260
2262
return 1 ;
2261
2263
}
0 commit comments