@@ -25,10 +25,9 @@ static const uint8_t pkg_vita_4[] = { 0xaf, 0x07, 0xfd, 0x59, 0x65, 0x25, 0x27,
25
25
// https://github.com/TheOfficialFloW/VitaShell/blob/1.74/sfo.h#L29
26
26
static void parse_sfo_content (const uint8_t * sfo , uint32_t sfo_size , char * category , char * title , char * content , char * min_version , char * pkg_version )
27
27
{
28
-
29
28
if (get32le (sfo ) != 0x46535000 )
30
29
{
31
- fatal ("ERROR: incorrect sfo signature\n" );
30
+ sys_error ("ERROR: incorrect sfo signature\n" );
32
31
}
33
32
34
33
uint32_t keys = get32le (sfo + 8 );
@@ -44,7 +43,7 @@ static void parse_sfo_content(const uint8_t* sfo, uint32_t sfo_size, char* categ
44
43
{
45
44
if (i * 16 + 20 + 2 > sfo_size )
46
45
{
47
- fatal ("ERROR: sfo information is too small\n" );
46
+ sys_error ("ERROR: sfo information is too small\n" );
48
47
}
49
48
50
49
char * key = (char * )sfo + keys + get16le (sfo + i * 16 + 20 );
@@ -79,7 +78,7 @@ static void parse_sfo_content(const uint8_t* sfo, uint32_t sfo_size, char* categ
79
78
80
79
if (title_index < 0 )
81
80
{
82
- fatal ("ERROR: cannot find title from sfo file, pkg is probably corrupted\n" );
81
+ sys_error ("ERROR: cannot find title from sfo file, pkg is probably corrupted\n" );
83
82
}
84
83
85
84
char * value = (char * )sfo + values + get32le (sfo + title_index * 16 + 20 + 12 );
@@ -168,11 +167,11 @@ static void parse_sfo(sys_file f, uint64_t sfo_offset, uint32_t sfo_size, char*
168
167
uint8_t sfo [16 * 1024 ];
169
168
if (sfo_size < 16 )
170
169
{
171
- fatal ("ERROR: sfo information is too small\n" );
170
+ sys_error ("ERROR: sfo information is too small\n" );
172
171
}
173
172
if (sfo_size > sizeof (sfo ))
174
173
{
175
- fatal ("ERROR: sfo information is too big, pkg file is probably corrupted\n" );
174
+ sys_error ("ERROR: sfo information is too big, pkg file is probably corrupted\n" );
176
175
}
177
176
sys_read (f , sfo_offset , sfo , sfo_size );
178
177
@@ -200,7 +199,7 @@ static void find_psp_sfo(const aes128_key* key, const aes128_key* ps3_key, const
200
199
if (pkg_size < enc_offset + name_offset + name_size ||
201
200
pkg_size < enc_offset + data_offset + data_size )
202
201
{
203
- fatal ("ERROR: pkg file is too short, possibly corrupted\n" );
202
+ sys_error ("ERROR: pkg file is too short, possibly corrupted\n" );
204
203
}
205
204
206
205
const aes128_key * item_key = psp_type == 0x90 ? key : ps3_key ;
@@ -215,11 +214,11 @@ static void find_psp_sfo(const aes128_key* key, const aes128_key* ps3_key, const
215
214
uint8_t sfo [16 * 1024 ];
216
215
if (data_size < 16 )
217
216
{
218
- fatal ("ERROR: sfo information is too small\n" );
217
+ sys_error ("ERROR: sfo information is too small\n" );
219
218
}
220
219
if (data_size > sizeof (sfo ))
221
220
{
222
- fatal ("ERROR: sfo information is too big, pkg file is probably corrupted\n" );
221
+ sys_error ("ERROR: sfo information is too big, pkg file is probably corrupted\n" );
223
222
}
224
223
225
224
sys_read (pkg , enc_offset + data_offset , sfo , (uint32_t )data_size );
@@ -272,7 +271,8 @@ typedef enum {
272
271
273
272
int main (int argc , char * argv [])
274
273
{
275
- printf ("pkg2zip v1.8\n" );
274
+ sys_output_init ();
275
+ sys_output ("pkg2zip v1.8\n" );
276
276
277
277
int zipped = 1 ;
278
278
int cso = 5 ;
@@ -309,10 +309,10 @@ int main(int argc, char* argv[])
309
309
if (pkg_arg == NULL )
310
310
{
311
311
fprintf (stderr , "ERROR: no pkg file specified\n" );
312
- fatal ("Usage: %s [-x] [-c[N]] file.pkg [zRIF]\n" , argv [0 ]);
312
+ sys_error ("Usage: %s [-x] [-c[N]] file.pkg [zRIF]\n" , argv [0 ]);
313
313
}
314
314
315
- printf ("[*] loading...\n" );
315
+ sys_output ("[*] loading...\n" );
316
316
317
317
uint64_t pkg_size ;
318
318
sys_file pkg = sys_open (pkg_arg , & pkg_size );
@@ -322,7 +322,7 @@ int main(int argc, char* argv[])
322
322
323
323
if (get32be (pkg_header ) != 0x7f504b47 || get32be (pkg_header + PKG_HEADER_SIZE ) != 0x7F657874 )
324
324
{
325
- fatal ("ERROR: not a pkg file\n" );
325
+ sys_error ("ERROR: not a pkg file\n" );
326
326
}
327
327
328
328
// http://www.psdevwiki.com/ps3/PKG_files
@@ -337,11 +337,11 @@ int main(int argc, char* argv[])
337
337
338
338
if (pkg_size < total_size )
339
339
{
340
- fatal ("ERROR: pkg file is too small\n" );
340
+ sys_error ("ERROR: pkg file is too small\n" );
341
341
}
342
342
if (pkg_size < enc_offset + item_count * 32 )
343
343
{
344
- fatal ("ERROR: pkg file is too small\n" );
344
+ sys_error ("ERROR: pkg file is too small\n" );
345
345
}
346
346
347
347
uint32_t content_type = 0 ;
@@ -402,7 +402,7 @@ int main(int argc, char* argv[])
402
402
}
403
403
else
404
404
{
405
- fatal ("ERROR: unsupported content type 0x%x" , content_type );
405
+ sys_error ("ERROR: unsupported content type 0x%x" , content_type );
406
406
}
407
407
408
408
aes128_key ps3_key ;
@@ -476,7 +476,7 @@ int main(int argc, char* argv[])
476
476
const char * rif_contentid = (char * )rif + (type == PKG_TYPE_VITA_PSM ? 0x50 : 0x10 );
477
477
if (strncmp (rif_contentid , content , 0x30 ) != 0 )
478
478
{
479
- fatal ("ERROR: zRIF content id '%s' doesn't match pkg '%s'\n" , rif_contentid , content );
479
+ sys_error ("ERROR: zRIF content id '%s' doesn't match pkg '%s'\n" , rif_contentid , content );
480
480
}
481
481
}
482
482
}
@@ -496,42 +496,42 @@ int main(int argc, char* argv[])
496
496
type_str = content_type == 0xe ? "PSP-Go" : content_type == 0xf ? "PSP-Mini" : "PSP-NeoGeo" ;
497
497
}
498
498
snprintf (root , sizeof (root ), "%s [%.9s] [%s]%s" , title , id , type_str , ext );
499
- printf ("[*] unpacking %s\n" , type_str );
499
+ sys_output ("[*] unpacking %s\n" , type_str );
500
500
}
501
501
else if (type == PKG_TYPE_PSX )
502
502
{
503
503
snprintf (root , sizeof (root ), "%s [%.9s] [PSX]%s" , title , id , ext );
504
- printf ("[*] unpacking PSX\n" );
504
+ sys_output ("[*] unpacking PSX\n" );
505
505
}
506
506
else if (type == PKG_TYPE_VITA_DLC )
507
507
{
508
508
snprintf (root , sizeof (root ), "%s [%.9s] [%s] [DLC-%s]%s" , title , id , get_region (id ), id2 , ext );
509
- printf ("[*] unpacking DLC\n" );
509
+ sys_output ("[*] unpacking DLC\n" );
510
510
}
511
511
else if (type == PKG_TYPE_VITA_PATCH )
512
512
{
513
513
snprintf (root , sizeof (root ), "%s [%.9s] [%s] [PATCH] [v%s]%s" , title , id , get_region (id ), pkg_version , ext );
514
- printf ("[*] unpacking PATCH\n" );
514
+ sys_output ("[*] unpacking PATCH\n" );
515
515
}
516
516
else if (type == PKG_TYPE_VITA_PSM )
517
517
{
518
518
snprintf (root , sizeof (root ), "%.9s [%s]%s" , id , get_region (id ), ext );
519
- printf ("[*] unpacking PSM\n" );
519
+ sys_output ("[*] unpacking PSM\n" );
520
520
}
521
521
else if (type == PKG_TYPE_VITA_APP )
522
522
{
523
523
snprintf (root , sizeof (root ), "%s [%.9s] [%s]%s" , title , id , get_region (id ), ext );
524
- printf ("[*] unpacking APP\n" );
524
+ sys_output ("[*] unpacking APP\n" );
525
525
}
526
526
else
527
527
{
528
528
assert (0 );
529
- fatal ("ERROR: unsupported type\n" );
529
+ sys_error ("ERROR: unsupported type\n" );
530
530
}
531
531
532
532
if (zipped )
533
533
{
534
- printf ("[*] creating '%s' archive\n" , root );
534
+ sys_output ("[*] creating '%s' archive\n" , root );
535
535
}
536
536
537
537
out_begin (root , zipped );
@@ -603,10 +603,10 @@ int main(int argc, char* argv[])
603
603
else
604
604
{
605
605
assert (0 );
606
- fatal ("ERROR: unsupported type\n" );
606
+ sys_error ("ERROR: unsupported type\n" );
607
607
}
608
608
609
- printf ("[*] decrypting...\n" );
609
+ sys_output ("[*] decrypting...\n" );
610
610
char path [1024 ];
611
611
612
612
int sce_sys_package_created = 0 ;
@@ -631,12 +631,12 @@ int main(int argc, char* argv[])
631
631
if (pkg_size < enc_offset + name_offset + name_size ||
632
632
pkg_size < enc_offset + data_offset + data_size )
633
633
{
634
- fatal ("ERROR: pkg file is too short, possibly corrupted\n" );
634
+ sys_error ("ERROR: pkg file is too short, possibly corrupted\n" );
635
635
}
636
636
637
637
if (name_size >= ZIP_MAX_FILENAME )
638
638
{
639
- fatal ("ERROR: pkg file contains file with very long name\n" );
639
+ sys_error ("ERROR: pkg file contains file with very long name\n" );
640
640
}
641
641
642
642
const aes128_key * item_key ;
@@ -654,7 +654,7 @@ int main(int argc, char* argv[])
654
654
aes128_ctr_xor (item_key , iv , name_offset / 16 , (uint8_t * )name , name_size );
655
655
name [name_size ] = 0 ;
656
656
657
- printf ("[%u/%u] %s\n" , item_index + 1 , item_count , name );
657
+ sys_output ("[%u/%u] %s\n" , item_index + 1 , item_count , name );
658
658
659
659
if (flags == 4 || flags == 18 )
660
660
{
@@ -770,12 +770,12 @@ int main(int argc, char* argv[])
770
770
{
771
771
if (!sce_sys_package_created )
772
772
{
773
- printf ("[*] creating sce_sys/package\n" );
773
+ sys_output ("[*] creating sce_sys/package\n" );
774
774
snprintf (path , sizeof (path ), "%s/sce_sys/package" , root );
775
775
out_add_folder (path );
776
776
}
777
777
778
- printf ("[*] creating sce_sys/package/head.bin\n" );
778
+ sys_output ("[*] creating sce_sys/package/head.bin\n" );
779
779
snprintf (path , sizeof (path ), "%s/sce_sys/package/head.bin" , root );
780
780
781
781
out_begin_file (path , 0 );
@@ -792,7 +792,7 @@ int main(int argc, char* argv[])
792
792
}
793
793
out_end_file ();
794
794
795
- printf ("[*] creating sce_sys/package/tail.bin\n" );
795
+ sys_output ("[*] creating sce_sys/package/tail.bin\n" );
796
796
snprintf (path , sizeof (path ), "%s/sce_sys/package/tail.bin" , root );
797
797
798
798
out_begin_file (path , 0 );
@@ -807,7 +807,7 @@ int main(int argc, char* argv[])
807
807
}
808
808
out_end_file ();
809
809
810
- printf ("[*] creating sce_sys/package/stat.bin\n" );
810
+ sys_output ("[*] creating sce_sys/package/stat.bin\n" );
811
811
snprintf (path , sizeof (path ), "%s/sce_sys/package/stat.bin" , root );
812
812
813
813
uint8_t stat [768 ] = { 0 };
@@ -820,16 +820,16 @@ int main(int argc, char* argv[])
820
820
{
821
821
if (type == PKG_TYPE_VITA_PSM )
822
822
{
823
- printf ("[*] creating RO/License\n" );
823
+ sys_output ("[*] creating RO/License\n" );
824
824
snprintf (path , sizeof (path ), "%s/RO/License" , root );
825
825
out_add_folder (path );
826
826
827
- printf ("[*] creating RO/License/FAKE.rif\n" );
827
+ sys_output ("[*] creating RO/License/FAKE.rif\n" );
828
828
snprintf (path , sizeof (path ), "%s/RO/License/FAKE.rif" , root );
829
829
}
830
830
else
831
831
{
832
- printf ("[*] creating sce_sys/package/work.bin\n" );
832
+ sys_output ("[*] creating sce_sys/package/work.bin\n" );
833
833
snprintf (path , sizeof (path ), "%s/sce_sys/package/work.bin" , root );
834
834
}
835
835
@@ -840,29 +840,29 @@ int main(int argc, char* argv[])
840
840
841
841
if (type == PKG_TYPE_VITA_PSM )
842
842
{
843
- printf ("[*] creating RW\n" );
843
+ sys_output ("[*] creating RW\n" );
844
844
snprintf (path , sizeof (path ), "%s/RW" , root );
845
845
out_add_folder (path );
846
846
847
- printf ("[*] creating RW/Documents\n" );
847
+ sys_output ("[*] creating RW/Documents\n" );
848
848
snprintf (path , sizeof (path ), "%s/RW/Documents" , root );
849
849
out_add_folder (path );
850
850
851
- printf ("[*] creating RW/Temp\n" );
851
+ sys_output ("[*] creating RW/Temp\n" );
852
852
snprintf (path , sizeof (path ), "%s/RW/Temp" , root );
853
853
out_add_folder (path );
854
854
855
- printf ("[*] creating RW/System\n" );
855
+ sys_output ("[*] creating RW/System\n" );
856
856
snprintf (path , sizeof (path ), "%s/RW/System" , root );
857
857
out_add_folder (path );
858
858
859
- printf ("[*] creating RW/System/content_id\n" );
859
+ sys_output ("[*] creating RW/System/content_id\n" );
860
860
snprintf (path , sizeof (path ), "%s/RW/System/content_id" , root );
861
861
out_begin_file (path , 0 );
862
862
out_write (pkg_header + 0x30 , 0x30 );
863
863
out_end_file ();
864
864
865
- printf ("[*] creating RW/System/pm.dat\n" );
865
+ sys_output ("[*] creating RW/System/pm.dat\n" );
866
866
snprintf (path , sizeof (path ), "%s/RW/System/pm.dat" , root );
867
867
868
868
uint8_t pm [1 << 16 ] = { 0 };
@@ -875,8 +875,8 @@ int main(int argc, char* argv[])
875
875
876
876
if (type == PKG_TYPE_VITA_APP || type == PKG_TYPE_VITA_PATCH )
877
877
{
878
- printf ("[*] minimum fw version required: %s\n" , min_version );
878
+ sys_output ("[*] minimum fw version required: %s\n" , min_version );
879
879
}
880
880
881
- printf ("[*] done!\n" );
881
+ sys_output ("[*] done!\n" );
882
882
}
0 commit comments