@@ -400,21 +400,19 @@ int main_utf8(int argc, char** argv)
400
400
}
401
401
}
402
402
403
- // File too small or without expected magic
404
- if ((tmd_path == NULL ) || (tik_path == NULL )) {
405
- argv [1 ][get_trailing_slash (argv [1 ])] = 0 ;
406
- if (argv [1 ][0 ] == 0 ) {
407
- argv [1 ][0 ] = '.' ;
408
- argv [1 ][1 ] = 0 ;
409
- }
403
+ // We'll need the current path for locating files, which we set in argv[1]
404
+ argv [1 ][get_trailing_slash (argv [1 ])] = 0 ;
405
+ if (argv [1 ][0 ] == 0 ) {
406
+ argv [1 ][0 ] = '.' ;
407
+ argv [1 ][1 ] = 0 ;
410
408
}
411
409
}
412
410
413
411
// If the condition below is true, argv[1] is a directory
414
412
if ((tmd_path == NULL ) || (tik_path == NULL )) {
415
413
size_t size = strlen (argv [1 ]);
416
- tmd_path = calloc (size + 10 , 1 );
417
- tik_path = calloc (size + 10 , 1 );
414
+ tmd_path = calloc (size + 16 , 1 );
415
+ tik_path = calloc (size + 16 , 1 );
418
416
sprintf (tmd_path , "%s%ctitle.tmd" , argv [1 ], PATH_SEP );
419
417
sprintf (tik_path , "%s%ctitle.tik" , argv [1 ], PATH_SEP );
420
418
}
@@ -455,11 +453,11 @@ int main_utf8(int argc, char** argv)
455
453
uint8_t iv [16 ];
456
454
memset (iv , 0 , sizeof (iv ));
457
455
458
- sprintf (str , "%08X.app" , getbe32 (& tmd -> Contents [0 ].ID ));
456
+ sprintf (str , "%s%c% 08X.app" , argv [ 1 ], PATH_SEP , getbe32 (& tmd -> Contents [0 ].ID ));
459
457
460
458
uint32_t cnt_len = read_file (str , & cnt );
461
459
if (cnt_len == 0 ) {
462
- sprintf (str , "%08X" , getbe32 (& tmd -> Contents [0 ].ID ));
460
+ sprintf (str , "%s%c% 08X" , argv [ 1 ], PATH_SEP , getbe32 (& tmd -> Contents [0 ].ID ));
463
461
cnt_len = read_file (str , & cnt );
464
462
if (cnt_len == 0 ) {
465
463
fprintf (stderr , "ERROR: Failed to open content: %02X\n" , getbe32 (& tmd -> Contents [0 ].ID ));
@@ -476,7 +474,7 @@ int main_utf8(int argc, char** argv)
476
474
aes_crypt_cbc (& ctx , AES_DECRYPT , cnt_len , iv , cnt , cnt );
477
475
478
476
if (getbe32 (cnt ) != FST_MAGIC ) {
479
- sprintf (str , "%08X.dec" , getbe32 (& tmd -> Contents [0 ].ID ));
477
+ sprintf (str , "%s%c% 08X.dec" , argv [ 1 ], PATH_SEP , getbe32 (& tmd -> Contents [0 ].ID ));
480
478
fprintf (stderr , "ERROR: Unexpected content magic. Dumping decrypted file as '%s'.\n" , str );
481
479
file_dump (str , cnt , cnt_len );
482
480
goto out ;
@@ -497,7 +495,7 @@ int main_utf8(int argc, char** argv)
497
495
498
496
printf ("FST entries: %u\n" , entries );
499
497
500
- char path [1024 ] = { 0 };
498
+ char path [MAX_PATH ] = { 0 };
501
499
uint32_t entry [16 ];
502
500
uint32_t l_entry [16 ];
503
501
@@ -519,16 +517,16 @@ int main_utf8(int argc, char** argv)
519
517
} else {
520
518
uint32_t offset ;
521
519
memset (path , 0 , sizeof (path ));
520
+ strcpy (path , argv [1 ]);
522
521
522
+ size_t short_path = strlen (path ) + 1 ;
523
523
for (uint32_t j = 0 ; j < level ; j ++ ) {
524
- if (j > 0 )
525
- path [strlen (path )] = PATH_SEP ;
524
+ path [strlen (path )] = PATH_SEP ;
526
525
offset = getbe32 (& fe [entry [j ]].TypeName ) & 0x00FFFFFF ;
527
526
memcpy (path + strlen (path ), cnt + name_offset + offset , strlen ((char * )cnt + name_offset + offset ));
528
527
create_path (path );
529
528
}
530
- if (level > 0 )
531
- path [strlen (path )] = PATH_SEP ;
529
+ path [strlen (path )] = PATH_SEP ;
532
530
offset = getbe32 (& fe [i ].TypeName ) & 0x00FFFFFF ;
533
531
memcpy (path + strlen (path ), cnt + name_offset + offset , strlen ((char * )cnt + name_offset + offset ));
534
532
@@ -537,15 +535,15 @@ int main_utf8(int argc, char** argv)
537
535
cnt_offset <<= 5 ;
538
536
539
537
printf ("Size:%07X Offset:0x%010" PRIx64 " CID:%02X U:%02X %s\n" , getbe32 (& fe [i ].FileLength ),
540
- cnt_offset , getbe16 (& fe [i ].ContentID ), getbe16 (& fe [i ].Flags ), path );
538
+ cnt_offset , getbe16 (& fe [i ].ContentID ), getbe16 (& fe [i ].Flags ), & path [ short_path ] );
541
539
542
540
uint32_t cnt_file_id = getbe32 (& tmd -> Contents [getbe16 (& fe [i ].ContentID )].ID );
543
- sprintf (str , "%08X.app" , cnt_file_id );
541
+ sprintf (str , "%s%c% 08X.app" , argv [ 1 ], PATH_SEP , cnt_file_id );
544
542
545
543
if (!(fe [i ].Type & 0x80 )) {
546
544
src = fopen_utf8 (str , "rb" );
547
545
if (src == NULL ) {
548
- sprintf (str , "%08X" , cnt_file_id );
546
+ sprintf (str , "%s%c% 08X" , argv [ 1 ], PATH_SEP , cnt_file_id );
549
547
src = fopen_utf8 (str , "rb" );
550
548
if (src == NULL ) {
551
549
fprintf (stderr , "ERROR: Could not open: '%s'\n" , str );
0 commit comments