forked from anaria28/NOR-Dump-Tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NORDumpTool.c
824 lines (712 loc) · 41.8 KB
/
NORDumpTool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
// Knowledge and information sources : ps3devwiki.com | ps3hax.net | your friend google
// Thanks to all people sharing their findings and knowledge!
//
// Aim of this code:
// - Check as much as possible a NOR dump in order to validate it
// - Run some statistics on the dump (% of '00' 'FF' ...)
// - Extract some specific console information (S/N, MAC, and so on)
//
// Versions :
// 0.9.5 Increased portability to Windows via MinGW32
// 0.9.4 Fixed stupid mistake in ReadSection() (Thx @Sarah1331)
// 0.9.3 Added checking of area filled with unique byte(s) e.g. in flash format: 0x210 -> 0x3FF : full of FF
// 0.9.2 memory allocation fix (Thx @judges) in CheckPerConsoleData() + fixed wrong English (mixed French...) in main()
// 0.9.1 Added -D option to display a specific section in Hex or ASCII
// 0.9.0 First public release
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <openssl/md5.h>
#ifdef __MINGW32__
// for windows
#define MKDIR(x,y) mkdir(x)
#else
// for the real world
#define MKDIR(x,y) mkdir(x,y)
#endif
#define TYPE_HEX 0
#define TYPE_ASCII 1
#define DISPLAY_ALWAYS 2
#define DISPLAY_FAIL 4
#define NB_OPTIONS 8
#define OPTION_SPLIT 0x01
#define OPTION_MD5 0x02
#define OPTION_EXTRACT 0x04
#define OPTION_STATS 0x08
#define OPTION_CHECK_GENERIC 0x10
#define OPTION_CHECK_PERPS3 0x20
#define OPTION_DISPLAY_AREA 0x40
#define OPTION_CHECK_FILLED 0x80
#define NOR_FILE_SIZE 0x1000000
#define DATA_BUFFER_SIZE 0x100
#define MIN00 3083652
#define MAX00 4867070
#define MINFF 1748186
#define MAXFF 1758252
#define MAXOTHERS 83886
enum TOCnames {
asecure_loader = 0,
eEID,
cISD,
cCSD,
trvk_prg0,
trvk_prg1,
trvk_pkg0,
trvk_pkg1,
ros0,
ros1,
cvtrm,
CELL_EXTNOR_AREA,
bootldr,
FlashStart,
FlashFormat,
FlashRegion,
CRL1,
CRL2,
DRL1,
DRL2,
TotalSections
};
struct Options {
char *Name;
int Type;
uint32_t Start;
uint32_t Size;
};
struct Sections {
char *name;
uint32_t Offset;
uint32_t Size;
int DisplayType;
int Check;
char *Pattern;
};
static struct Sections SectionTOC[] = {
{ "asecure_loader", 0x000800, 0x02E800, 0, 0, NULL },
{ "eEID", 0x02F000, 0x010000, 0, 0, NULL },
{ "cISD", 0x03F000, 0x0800, 0, 0, NULL },
{ "cCSD", 0x03F800, 0x0800, 0, 0, NULL },
{ "trvk_prg0", 0x040000, 0x020000, 0, 0, NULL },
{ "trvk_prg1", 0x060000, 0x020000, 0, 0, NULL },
{ "trvk_pkg0", 0x080000, 0x020000, 0, 0, NULL },
{ "trvk_pkg1", 0x0A0000, 0x020000, 0, 0, NULL },
{ "ros0", 0x0C0000, 0x700000, 0, 0, NULL },
{ "ros1", 0x7C0000, 0x700000, 0, 0, NULL },
{ "cvtrm", 0xEC0000, 0x040000, 0, 0, NULL },
{ "CELL_EXTNOR_AREA", 0xF20000, 0x020000, 0, 0, NULL },
{ "bootldr", 0xFC0000, 0x040000, 0, 0, NULL },
{ "FlashStart", 0x000000, 0x0200, 0, 0, NULL },
{ "FlashFormat", 0x000200, 0x0200, 0, 0, NULL },
{ "FlashRegion", 0x000400, 0x0400, 0, 0, NULL },
{ "CRL1", 0xF40000, 0x20000, 0, 0, NULL },
{ "DRL1", 0xF60000, 0x20000, 0, 0, NULL },
{ "CRL2", 0xF80000, 0x20000, 0, 0, NULL },
{ "DRL2", 0xFA0000, 0x20000, 0, 0, NULL },
{ NULL, 0, 0, 0, 0, NULL }
};
struct IndividualSystemData {
char *IDPSTargetID; // 0x02F077 (NOR) 0x80877 (NAND)
char *SKU; //
char *metldrOffset0; // 0x081E (NOR) 0x4081E (NAND)
char *metldrOffset1; // 0x0842 (NOR) 0x40842 (NAND)
uint32_t bootldrSize;
char *bootldrOffset0; // 0xFC0002 (NOR) 0x02 (NAND)
char *bootldrOffset1; // 0xFC0012 (NOR) 0x12 (NAND)
char *MinFW;
};
static struct IndividualSystemData CheckPerSKU[] = {
{ "01", "DEH-Z1010", "1420", "113E", 0x2D020, "2CFE", "2CFE", "<= 0.80.004" },
{ "01", "DECR-1000", "EC40", "0EC0", 0x2A840, "2A7F", "2A7F", "<= 0.85.009" },
{ "01", "DEH-H1001-D?", "EC40", "0EC0", 0x2A830, "2A7F", "2A7F", "<= 0.85.009" },
{ "01", "DEH-H1000A-E (COK-001) DEX", "EC70", "0EC3", 0x2A1E0, "2A1A", "2A1A", "< 095.001" },
{ "01", "CECHAxx (COK-001)", "EE10", "0EDD", 0x2A430, "2A3F", "2A3F", "1" },
{ "01", "CECHAxx (COK-001) factory FW 1.00", "EDA0", "0ED6", 0x2A2E0, "2A2A", "2A2A", "1" },
{ "01", "CECHAxx (COK-001)", "EDE0", "0EDA", 0x2A3B0, "2A37", "2A37", "1" },
{ "01", "DECHAxx (COK-001) DEX", "EDA0", "0ED6", 0x2A2E0, "2A2A", "2A2A", "1" },
{ "02", "CECHBxx (COK-001)", "EDA0", "0ED6", 0x2A2E0, "2A2A", "2A2A", "1" },
{ "03", "CECHCxx (COK-002)", "EDA0", "0ED6", 0x2A2E0, "2A2A", "2A2A", "1" },
{ "03", "CECHCxx (COK-002) factory FW 1.00", "EBF0", "0EBB", 0x30480, "3044", "3044", "1" },
{ "03", "CECHCxx (COK-002)", "EDE0", "0EDA", 0x2A3B0, "2A37", "2A37", "1" },
{ "03", "CECHExx (COK-002)", "EA60", "0EA2", 0x2EE70, "2EE3", "2EE3", NULL },
{ "04", "Namco System 357 (COK-002) ARC", "E7B0", "0E77", 0x2E900, "2E8C", "2E8C", "1.90?" },
{ "04", "CECHExx (COK-002)", "EE10", "0EDD", 0x2A430, "2A3F", "2A3F", "1" },
{ "05", "CECHGxx (SEM-001)", "E7B0", "0E77", 0x2E900, "2E8C", "2E8C", "1.9" },
{ "05", "CECHGxx (SEM-001)", "E7B0", "0E77", 0x2F200, "2F1C", "2F1C", "2.3" },
{ "05", "CECHGxx (SEM-001)", "E8C0", "0E88", 0x2EF80, "2EF4", "2EF4", "2.3" },
{ "06", "CECHHxx (DIA-001)", "E7B0", "0E77", 0x2F200, "2F1C", "2F1C", "2.3" },
{ "06", "CECHHxx (DIA-001)", "E8C0", "0E88", 0x2EF80, "2EF4", "2EF4", "2.3" },
{ "06", "CECHHxx (DIA-001)", "E8E0", "0E8A", 0x2EF80, "2EF4", "2EF4", "1.97" },
{ "06", "CECHHxx (DIA-001)", "EA60", "0EA2", 0x2EE70, "2EE3", "2EE3", "1.97" },
{ "06", "CECHMxx (DIA-001)", "EA60", "0EA2", 0x2EE70, "2EE3", "2EE3", "1.97" },
{ "07", "CECHJxx (DIA-002) factory FW 2.30 - datecode 8B", "E8E0", "0E8A", 0x2EF80, "2EF4", "2EF4", "2.3" },
{ "07", "CECHJxx (DIA-002)", "EA60", "0EA2", 0x2EE70, "2EE3", "2EE3", "2.3" },
{ "07", "CECHKxx (DIA-002) datecode 8C", "EA60", "0EA2", 0x2EE70, "2EE3", "2EE3", "2.3" },
{ "07", "DECHJxx (DIA-002) DEX", "E8D0", "0E89", 0x2EAF0, "2EAB", "2EAB", "2.16" },
{ "08", "Namco System 357 (VER-001) ARC", "E8D0", "0E89", 0x2EAF0, "2EAB", "2EAB", "2.45?" },
{ "08", "CECHLxx/CECHPxx (VER-001) ", "E8D0", "0E89", 0x2EAF0, "2EAB", "2EAB", "2.45" },
{ "08", "CECHLxx (VER-001)", "E8D0", "0E89", 0x2EB70, "2EB3", "2EB3", "2.45" },
{ "08", "CECHLxx (VER-001) factory FW 2.30", "E890", "0E85", 0x2F170, "2F13", "2F13", "2.3" },
{ "09", "CECH-20xx (DYN-001) factory FW 2.76", "E890", "0E85", 0x2F170, "2F13", "2F13", "2.7" },
{ "09", "DECR-1400 (DEB-001) DECR factory FW 2.60", "E890", "0E85", 0x2F170, "2F13", "2F13", "2.6" },
{ "09", "CECH-20xx (DYN-001)", "E920", "0E8E", 0x2F3F0, "2F3B", "2F3B", "2.7" },
{ "0A", "CECH-21xx (SUR-001)", "E920", "0E8E", 0x2F4F0, "2F4B", "2F4B", "3.2" },
{ "0B", "CECH-25xx (JTP-001) factory FW 3.40 datecode 0C", "E920", "0E8E", 0x2F4F0, "2F4B", "2F4B", "3.4" },
{ "0B", "CECH-25xx (JSD-001) factory FW 3.41 datecode 0C", "E920", "0E8E", 0x2F4F0, "2F4B", "2F4B", "3.4" },
{ "0B", "CECH-25xx (JSD-001) factory FW 3.56 datecode 0D", "E960", "0E92", 0x2F570, "2F53", "2F53", "3.5" },
{ "0B", "CECH-25xx (JTP-001) factory FW 3.56 datecode 1A", "E960", "0E92", 0x2F570, "2F53", "2F53", "3.5" },
{ "0B", "CECH-25xx (JTP-001) factory FW 3.56 datecode 1A", "E960", "0E92", 0x2F5F0, "2F5B", "2F5B", "3.56" },
{ "0B", "CECH-25xx (JSD-001) factory FW 3.56 datecode 1B", "E960", "0E92", 0x2F5F0, "2F5B", "2F5B", "3.56" },
{ "0B", "CECH-25xx (JTP-001) factory FW 3.56 datecode 1B", "E960", "0E92", 0x2F5F0, "2F5B", "2F5B", "3.56" },
{ "0B", "CECH-25xx (JSD-001) factory FW 3.60 datecode 1B", "F920", "0F8E", 0x2FFF0, "2FFB", "2FFB", "3.6" },
{ "0B", "CECH-25xx (JTP-001) factory FW 3.60", "F920", "0F8E", 0x2FFF0, "2FFB", "2FFB", "3.6" },
{ "0C", "CECH-30xx (KTE-001) factory FW 3.65", "F920", "0F8E", 0x2FFF0, "2FFB", "2FFB", "3.6" },
{ "0D", "CECH-40xx (MSX-001 or MPX-001)", "F9B0", "0F97", 0x301F0, "301B", "301B", "4.20" },
{ NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL}
};
void MD5SumFileSection ( char *section_text, FILE *fd, uint32_t pos, uint32_t len ) {
uint8_t digest[MD5_DIGEST_LENGTH];
size_t read_len;
int i;
uint32_t buf_len = 0x10;
uint8_t buf[buf_len];
MD5_CTX md5_ctx;
MD5_Init ( &md5_ctx );
fseek ( fd, pos, SEEK_SET );
for ( i = 0; i < NOR_FILE_SIZE; i += buf_len ) {
read_len = fread ( buf, 1, buf_len, fd );
MD5_Update ( &md5_ctx, buf, read_len );
}
MD5_Final ( digest, &md5_ctx );
printf ( "%s", section_text );
for ( i = 0; i < MD5_DIGEST_LENGTH; i++ )
printf ( "%02x", digest[i] );
printf ( "\n" );
}
int ExtractSection ( char *section_name, FILE *src, uint32_t pos, uint32_t len ) {
uint8_t *buf = NULL;
FILE *dst;
dst = fopen ( section_name, "wb" );
if ( !dst ) {
printf ( "Failed to open %s\n", section_name );
return ( EXIT_FAILURE );
}
fseek ( src, pos, SEEK_SET );
if ( ( buf = malloc ( len + 1 ) ) != NULL )
fread ( buf, len, 1, src );
else
return ( EXIT_FAILURE );
fwrite ( buf, len, 1, dst );
printf ( "Extraction done for %s\n", section_name );
fclose ( dst );
free( buf );
return ( EXIT_SUCCESS );
}
void Statistics ( FILE *fd ) {
// Calculate some statistics on bytes percentages
int i;
int Counter;
uint32_t CountOthers = 0;
uint32_t CountByte[0xFF + 1] = { 0 };
char low[] = "Too Low";
char high[] = "Too High";
char good[] = "Good";
char *ret00 = NULL;
char *retFF = NULL;
char *retOthers = NULL;
printf ( "******************************\n" );
printf ( "* Statistics *\n" );
printf ( "******************************\n" );
fseek ( fd, 0, SEEK_SET );
for ( i = 0; i < NOR_FILE_SIZE; i++ )
CountByte[fgetc ( fd )] += 1;
/* wtf is this trying to do ??? */
for ( Counter = 0x01; Counter < 0xFF; Counter++ ) {
if ( CountOthers < CountByte[Counter] )
CountOthers = CountByte[Counter];
}
if ( CountByte[0x00] < MIN00 )
ret00 = low;
else if ( CountByte[0x00] > MAX00 )
ret00 = high;
else
ret00 = good;
if ( CountByte[0xFF] < MINFF )
retFF = low;
else if ( CountByte[0xFF] > MAXFF )
retFF = high;
else
retFF = good;
if ( CountOthers > MAXOTHERS )
retOthers = high;
else
retOthers = good;
printf ( "Bytes '00' found %d times, %2.2f%% %s\n", CountByte[0x00], (double) CountByte[0x00] * 100 / (double) NOR_FILE_SIZE, ret00 );
printf ( "Bytes 'FF' found %d times, %2.2f%% %s\n", CountByte[0xFF], (double) CountByte[0xFF] * 100 / (double) NOR_FILE_SIZE, retFF );
printf ( "Other bytes found %d times maximum, %2.2f%% %s\n", CountOthers, (double) CountOthers * 100 / (double) NOR_FILE_SIZE, retOthers );
}
void GetSection ( FILE *fd, uint32_t pos, uint32_t len, uint8_t type, char *section_data ) {
// Reads area from file and put it in section_data pointer
// In Parameters:
// FILE *fd : File to read from
// uint32_t pos : Offset to read from
// uint8_t len : Length of data to read
// uint8_t type : Print out in Hex or ASCII
// uint8_t *section_data : Data to return
int i;
*section_data = 0;
fseek ( fd, pos, SEEK_SET );
if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_HEX ) {
for ( i = 0; i < len; i++ ) {
sprintf ( section_data, "%s%02X", section_data, fgetc ( fd ) );
}
}
else if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_ASCII ) {
fread ( section_data, len, 1, fd );
section_data[len] = 0;
}
}
int ReadSection ( char *section_name, FILE *fd, uint32_t pos, uint32_t len, uint8_t type, uint8_t flag, char *pattern ) {
// Reads area from file and check it with a given pattern
// In Parameters:
// char *section_name : Name to print out for the section
// FILE *fd : File to read from
// uint32_t pos : Offset to read from
// uint32_t len : Length of data to read
// uint8_t type : Print out in Hex or ASCII, always or only if fail to check
// uint8_t flag : Check a given pattern
// uint8_t *pattern : Pattern to check, has to be the same size of data read
int i;
int ret = EXIT_SUCCESS;
char buf[0x100] = { 0 };
fseek ( fd, pos, SEEK_SET );
for ( i = 0; i < len; i++ ) {
if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_HEX )
sprintf ( buf, "%s%02X", buf, fgetc ( fd ) );
else if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_ASCII )
sprintf ( buf, "%s%c", buf, fgetc ( fd ) );
}
if ( ( ( type ) & ( 1 << 1 ) ) == DISPLAY_ALWAYS )
printf ( "Section: %s: read %s \n", section_name, buf );
if ( flag ) {
for ( i = 0; i < len; i++ ) {
if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_ASCII ) {
if ( buf[i] != pattern[i] ) {
ret = EXIT_FAILURE;
if ( ( ( type ) & ( 1 << 2 ) ) == DISPLAY_FAIL )
printf ( "Section: %s: read %s ! mismatch pattern '%s' !\n", section_name, buf, pattern );
return ( ret );
}
}
else if ( ( ( type ) & ( 1 << 0 ) ) == TYPE_HEX ) {
if ( ( buf[i * 2] != pattern[i * 2] ) || ( buf[i * 2 + 1] != pattern[i * 2 + 1] ) ) {
ret = EXIT_FAILURE;
if ( ( ( type ) & ( 1 << 2 ) ) == DISPLAY_FAIL )
printf ( "Section: %s: read %s ! mismatch pattern '%s' !\n", section_name, buf, pattern );
return ( ret );
}
}
}
}
return ( ret );
}
int CheckGenericData ( FILE *fd ) {
int i = 0;
int ret = EXIT_SUCCESS;
struct Sections SectionGenericData[] = {
{ "Flash Magic Number ", SectionTOC[FlashStart].Offset + 0x10, 0x10, TYPE_HEX + DISPLAY_FAIL, 1, "000000000FACE0FF00000000DEADBEEF" },
{ "Flash Format Type ", SectionTOC[FlashFormat].Offset, 0x10, TYPE_HEX + DISPLAY_FAIL, 1, "49464900000000010000000200000000" },
{ "FlashRegion Entry Count", SectionTOC[FlashRegion].Offset + 0x0004, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, "0000000B" },
{ "FlashRegion Length ", SectionTOC[FlashRegion].Offset + 0x0008, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000EFFC00" },
{ "FlashRegion 1 offset ", SectionTOC[FlashRegion].Offset + 0x0010, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000000400" },
{ "FlashRegion 1 length ", SectionTOC[FlashRegion].Offset + 0x0018, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000002E800" },
{ "FlashRegion 1 name ", SectionTOC[FlashRegion].Offset + 0x0020, 0x0E, TYPE_ASCII + DISPLAY_FAIL, 1, "asecure_loader" },
{ "FlashRegion 2 offset ", SectionTOC[FlashRegion].Offset + 0x0040, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000002EC00" },
{ "FlashRegion 2 length ", SectionTOC[FlashRegion].Offset + 0x0048, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000010000" },
{ "FlashRegion 2 name ", SectionTOC[FlashRegion].Offset + 0x0050, 0x04, TYPE_ASCII + DISPLAY_FAIL, 1, "eEID" },
{ "FlashRegion 3 offset ", SectionTOC[FlashRegion].Offset + 0x0070, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000003EC00" },
{ "FlashRegion 3 length ", SectionTOC[FlashRegion].Offset + 0x0078, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000000800" },
{ "FlashRegion 3 name ", SectionTOC[FlashRegion].Offset + 0x0080, 0x04, TYPE_ASCII + DISPLAY_FAIL, 1, "cISD" },
{ "FlashRegion 4 offset ", SectionTOC[FlashRegion].Offset + 0x00A0, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000003F400" },
{ "FlashRegion 4 length ", SectionTOC[FlashRegion].Offset + 0x00A8, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000000800" },
{ "FlashRegion 4 name ", SectionTOC[FlashRegion].Offset + 0x00B0, 0x04, TYPE_ASCII + DISPLAY_FAIL, 1, "cCSD" },
{ "FlashRegion 5 offset ", SectionTOC[FlashRegion].Offset + 0x00D0, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000003FC00" },
{ "FlashRegion 5 length ", SectionTOC[FlashRegion].Offset + 0x00D8, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000020000" },
{ "FlashRegion 5 name ", SectionTOC[FlashRegion].Offset + 0x00E0, 0x09, TYPE_ASCII + DISPLAY_FAIL, 1, "trvk_prg0" },
{ "FlashRegion 6 offset ", SectionTOC[FlashRegion].Offset + 0x0100, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000005FC00" },
{ "FlashRegion 6 length ", SectionTOC[FlashRegion].Offset + 0x0108, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000020000" },
{ "FlashRegion 6 name ", SectionTOC[FlashRegion].Offset + 0x0110, 0x09, TYPE_ASCII + DISPLAY_FAIL, 1, "trvk_prg1" },
{ "FlashRegion 7 offset ", SectionTOC[FlashRegion].Offset + 0x0130, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000007FC00" },
{ "FlashRegion 7 length ", SectionTOC[FlashRegion].Offset + 0x0138, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000020000" },
{ "FlashRegion 7 name ", SectionTOC[FlashRegion].Offset + 0x0140, 0x09, TYPE_ASCII + DISPLAY_FAIL, 1, "trvk_pkg0" },
{ "FlashRegion 8 offset ", SectionTOC[FlashRegion].Offset + 0x0160, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "000000000009FC00" },
{ "FlashRegion 8 length ", SectionTOC[FlashRegion].Offset + 0x0168, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000020000" },
{ "FlashRegion 8 name ", SectionTOC[FlashRegion].Offset + 0x0170, 0x09, TYPE_ASCII + DISPLAY_FAIL, 1, "trvk_pkg1" },
{ "FlashRegion 9 offset ", SectionTOC[FlashRegion].Offset + 0x0190, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "00000000000BFC00" },
{ "FlashRegion 9 length ", SectionTOC[FlashRegion].Offset + 0x0198, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000700000" },
{ "FlashRegion 9 name ", SectionTOC[FlashRegion].Offset + 0x01A0, 0x04, TYPE_ASCII + DISPLAY_FAIL, 1, "ros0" },
{ "FlashRegion 10 offset ", SectionTOC[FlashRegion].Offset + 0x01C0, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "00000000007BFC00" },
{ "FlashRegion 10 length ", SectionTOC[FlashRegion].Offset + 0x01C8, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000700000" },
{ "FlashRegion 10 name ", SectionTOC[FlashRegion].Offset + 0x01D0, 0x04, TYPE_ASCII + DISPLAY_FAIL, 1, "ros1" },
{ "FlashRegion 11 offset ", SectionTOC[FlashRegion].Offset + 0x01F0, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000EBFC00" },
{ "FlashRegion 11 length ", SectionTOC[FlashRegion].Offset + 0x01F8, 0x08, TYPE_HEX + DISPLAY_FAIL, 1, "0000000000040000" },
{ "FlashRegion 11 name ", SectionTOC[FlashRegion].Offset + 0x0200, 0x05, TYPE_ASCII + DISPLAY_FAIL, 1, "cvtrm" },
{ NULL, 0, 0, 0, 0, NULL }
};
printf ( "******************************\n" );
printf ( "* Generic Data *\n" );
printf ( "******************************\n" );
while ( SectionGenericData[i].name != NULL ) {
ret |= ReadSection ( SectionGenericData[i].name,
fd,
SectionGenericData[i].Offset,
SectionGenericData[i].Size,
SectionGenericData[i].DisplayType,
SectionGenericData[i].Check,
SectionGenericData[i].Pattern );
i++;
}
return ( ret );
}
int CheckPerConsoleData ( FILE *fd ) {
int i = 0;
int SKUFound = 0;
int ret = EXIT_SUCCESS;
char *buf = malloc ( 0x100 );
char *IDPSTargetID = malloc ( 3 );
char *metldrOffset0 = malloc ( 5 );
char *metldrOffset1 = malloc ( 5 );
char *bootldrOffset0 = malloc ( 5 );
char *bootldrOffset1 = malloc ( 5 );
struct Sections SectionPerConsole[] = {
{ "mtldr size and rev ", SectionTOC[asecure_loader].Offset + 0x40, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "mtldr size and pcn ", SectionTOC[asecure_loader].Offset + 0x50, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID0 - IDPS ", SectionTOC[eEID].Offset + 0x70, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID0 static ", SectionTOC[eEID].Offset + 0x80, 0x04, TYPE_HEX + DISPLAY_ALWAYS, 1, "0012000B" },
{ "EID0 pcn ", SectionTOC[eEID].Offset + 0x84, 0x0B, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID3 - ckp_mgt_id ", SectionTOC[eEID].Offset + 0x12A8, 0x08, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID3 static ", SectionTOC[eEID].Offset + 0x12B0, 0x04, TYPE_HEX + DISPLAY_ALWAYS, 1, "000100D0" },
{ "EID3 pcn ", SectionTOC[eEID].Offset + 0x12B4, 0x0B, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID5 - IDPS ", SectionTOC[eEID].Offset + 0x13D0, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "EID5 static ", SectionTOC[eEID].Offset + 0x13E0, 0x04, TYPE_HEX + DISPLAY_ALWAYS, 1, "00120730" },
{ "EID5 pcn ", SectionTOC[eEID].Offset + 0x13E4, 0x0B, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "PS3 MAC Address ", SectionTOC[cISD].Offset + 0x40, 0x06, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 Magic Number ", SectionTOC[cISD].Offset + 0x60, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, "7F49444C" },
{ "cISD1 - CID ", SectionTOC[cISD].Offset + 0x6C, 0x04, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 - eCID ", SectionTOC[cISD].Offset + 0x70, 0x20, TYPE_ASCII + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 - board_id ", SectionTOC[cISD].Offset + 0x90, 0x08, TYPE_ASCII + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 - kiban_id ", SectionTOC[cISD].Offset + 0x98, 0x0c, TYPE_ASCII + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 -0x3F0A4 Data", SectionTOC[cISD].Offset + 0xA4, 0x06, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 -0x3F0B0 Data", SectionTOC[cISD].Offset + 0xB0, 0x08, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cISD1 - ckp_mgt_id ", SectionTOC[cISD].Offset + 0xB8, 0x08, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cvtrm - pck/puk ", SectionTOC[cvtrm].Offset + 0x1D748, 0x14, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "HDD information ", SectionTOC[CELL_EXTNOR_AREA].Offset + 0x204, 0x1C, TYPE_ASCII + DISPLAY_ALWAYS, 0, NULL },
{ "PS3 Serial Number ", SectionTOC[CELL_EXTNOR_AREA].Offset + 0x230, 0x10, TYPE_ASCII + DISPLAY_ALWAYS, 0, NULL },
{ "Bootldr hdr and rev", SectionTOC[bootldr].Offset, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "Bootldr hdr and pcn", SectionTOC[bootldr].Offset + 0x10, 0x10, TYPE_HEX + DISPLAY_ALWAYS, 0, NULL },
{ "cvtrm SCEI magicnbr", SectionTOC[cvtrm].Offset, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, "53434549" },
{ "cvtrm hdr ", SectionTOC[cvtrm].Offset + 0x004004, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, "5654524D" },
{ "cvtrm hdr bis ", SectionTOC[cvtrm].Offset + 0x024004, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, "5654524D" },
{ NULL, 0, 0, 0, 0, NULL }
};
printf ( "******************************\n" );
printf ( "* Per Console Data *\n" );
printf ( "******************************\n" );
while ( SectionPerConsole[i].name != NULL ) {
ret |= ReadSection ( SectionPerConsole[i].name,
fd,
SectionPerConsole[i].Offset,
SectionPerConsole[i].Size,
SectionPerConsole[i].DisplayType,
SectionPerConsole[i].Check,
SectionPerConsole[i].Pattern );
i++;
}
GetSection ( fd, SectionTOC[asecure_loader].Offset + 0x40, 0x04, TYPE_HEX, buf );
ret |= ReadSection ( "metldr hdr", fd, SectionTOC[asecure_loader].Offset + 0x50, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, buf );
GetSection ( fd, SectionTOC[bootldr].Offset, 0x04, TYPE_HEX, buf );
ret |= ReadSection ( "Bootldr hdr", fd, SectionTOC[bootldr].Offset + 0x10, 0x04, TYPE_HEX + DISPLAY_FAIL, 1, buf );
GetSection ( fd, SectionTOC[eEID].Offset + 0x77, 0x01, TYPE_HEX, IDPSTargetID );
GetSection ( fd, SectionTOC[asecure_loader].Offset + 0x1E, 0x02, TYPE_HEX, metldrOffset0 );
GetSection ( fd, SectionTOC[asecure_loader].Offset + 0x42, 0x02, TYPE_HEX, metldrOffset1 );
GetSection ( fd, SectionTOC[bootldr].Offset + 0x02, 0x02, TYPE_HEX, bootldrOffset0 );
GetSection ( fd, SectionTOC[bootldr].Offset + 0x12, 0x02, TYPE_HEX, bootldrOffset1 );
i = 0;
while ( CheckPerSKU[i].IDPSTargetID != NULL ) {
if ( ( strcmp ( CheckPerSKU[i].IDPSTargetID, IDPSTargetID ) == 0 ) &&
( strcmp ( CheckPerSKU[i].metldrOffset0, metldrOffset0 ) == 0 ) &&
( strcmp ( CheckPerSKU[i].metldrOffset1, metldrOffset1 ) == 0 ) &&
( strcmp ( CheckPerSKU[i].bootldrOffset0, bootldrOffset0 ) == 0 ) &&
( strcmp ( CheckPerSKU[i].bootldrOffset1, bootldrOffset1 ) == 0 ) ) {
printf ( "PS3 SKU : %s minimum FW : %s ( item %d in list ) \n", CheckPerSKU[i].SKU, CheckPerSKU[i].MinFW, i );
SKUFound = 1;
}
i++;
}
if ( !SKUFound ) {
printf ( "Data found in NOR to identify the SKU are:\n- TargetID:'%s'\n", IDPSTargetID );
printf ( "- metldr Offset 0:'%s'\n", metldrOffset0 );
printf ( "- metldr Offset 1:'%s'\n", metldrOffset1 );
printf ( "- bootldr Offset 0:'%s'\n", bootldrOffset0 );
printf ( "- bootldr Offset 1:'%s'\n", bootldrOffset1 );
}
free( IDPSTargetID );
free( metldrOffset0 );
free( metldrOffset1 );
free( bootldrOffset0 );
free( bootldrOffset1 );
free( buf );
return ( ret );
}
int CheckFilledData ( FILE *fd ) {
int i = 0;
int j = 0;
int ret = EXIT_SUCCESS;
int ret2 = EXIT_SUCCESS;
uint32_t bootldrSize;
uint32_t bootldrFilledSize;
uint32_t metldrSize;
uint32_t metldrFilledSize;
char *metldrOffset0 = malloc ( 5 );
char *bootldrOffset0 = malloc ( 5 );
printf ( "******************************\n" );
printf ( "* Area filled with 00 or FF *\n" );
printf ( "******************************\n" );
GetSection ( fd, SectionTOC[asecure_loader].Offset + 0x42, 0x02, TYPE_HEX, metldrOffset0 );
metldrSize = ( strtol ( metldrOffset0, NULL, 16 ) ) * 0x10 + 0x40;
metldrFilledSize = 0x2F000 - metldrSize - SectionTOC[asecure_loader].Offset - 0x40;
GetSection ( fd, SectionTOC[bootldr].Offset + 0x02, 0x02, TYPE_HEX, bootldrOffset0 );
bootldrSize = ( strtol ( bootldrOffset0, NULL, 16 ) ) * 0x10 + 0x40;
bootldrFilledSize = 0x1000000 - bootldrSize - SectionTOC[bootldr].Offset;
struct Sections SectionFilled[] = {
{ "flashformat", 0x000210, 0x01F0, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ "asecure_loader", SectionTOC[asecure_loader].Offset + 0x40 + metldrSize, metldrFilledSize, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "eEID", 0x030DD0, 0xE230, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ "cISD", 0x03F270, 0x0590, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ "cCSD", 0x03F850, 0x07B0, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
//{ "trvk_prg0", 0x04xxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "trvk_prg1", 0x06xxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "trvk_pkg0", 0x08xxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "trvk_pkg1", 0x0Axxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "ros0", 0x0Cxxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "ros1", 0x7Cxxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
//{ "cvtrm", 0xECxxxx, 0x0xxxxx, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to investigate
{ "CELL_EXTNOR_AREA", 0xF20040, 0x01C0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xF20240, 0x01FDC0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xF40030, 0x01FFD0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xF60060, 0x93A0, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to calculate the correct start, size seems to be found at 0xF60000E on 2 bytes ?
{ "CELL_EXTNOR_AREA", 0xF69530, 0x06D0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xF69C00, 0x015400, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ "CELL_EXTNOR_AREA", 0xF80030, 0x01FFD0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xFA0060, 0x93A0, TYPE_HEX + DISPLAY_FAIL, 1, "00" }, // need to calculate the correct start, size seems to be found at 0xFA0000E on 2 bytes ?
{ "CELL_EXTNOR_AREA", 0xFA9530, 0x06D0, TYPE_HEX + DISPLAY_FAIL, 1, "00" },
{ "CELL_EXTNOR_AREA", 0xFA9C00, 0x015400, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ "bootldr", SectionTOC[bootldr].Offset + bootldrSize, bootldrFilledSize, TYPE_HEX + DISPLAY_FAIL, 1, "FF" },
{ NULL, 0, 0, 0, 0, NULL }
};
while ( SectionFilled[i].name != NULL ) {
for ( j = 0; j < SectionFilled[i].Size; j++ ) {
if ( ( ret2 = ReadSection ( SectionFilled[i].name,
fd,
SectionFilled[i].Offset + j,
1,
SectionFilled[i].DisplayType,
SectionFilled[i].Check,
SectionFilled[i].Pattern ) ) ) {
printf ( "Error at '0x%08X\n", SectionFilled[i].Offset + j );
}
}
if ( !ret2 ) {
printf ( "Succesfully checked '%s' From '0x%08X' size: '0x%08X' full of '0x%s'\n", SectionFilled[i].name, SectionFilled[i].Offset, SectionFilled[i].Size, SectionFilled[i].Pattern );
}
else {
printf ( "Some error occured when checking '%s'\n", SectionFilled[i].name );
}
i++;
ret |= ret2;
ret2 = EXIT_SUCCESS;
}
free( metldrOffset0 );
free( bootldrOffset0 );
return ( ret );
}
int main ( int argc, char *argv[] ) {
int ret;
int i;
int type = 0;
char DisplaySection[0x30] = { 0 };
uint32_t len;
uint32_t ExtractionSize;
FILE *fd = NULL;
char *buf = malloc ( DATA_BUFFER_SIZE );
struct Options Option[NB_OPTIONS];
printf ( "******************************\n" );
printf ( "* NOR Dump Tool *\n" );
printf ( "******************************\n" );
printf ( "\nVersion 0.9.5\n" );
printf ( "\nOpen source project aimed to help to validate PS3 NOR dumps\n" );
printf ( "At the moment ( January 2013 ) the code is probably able\n" );
printf ( "to give you a validation status of roughly 90%%!?\n" );
printf ( "It's anyway better to do additional checking by your own, \n" );
printf ( "unless the code of this tool is fully validated by experts!!!\n\n" );
if ( ( argc < 2 ) || ( strcmp ( argv[1], "--help" ) == 0 ) ) {
printf ( "Usage: %s NorFile.bin ( Options ) \n", argv[0] );
printf ( "Options:\n" );
printf ( "\t--help: Display this help.\n" );
printf ( "\t-P : Give percentage of bytes\n" );
printf ( "\t-G : Check PS3 Generic information\n" );
printf ( "\t-C : Check and display perconsole information\n" );
printf ( "\t-F : Check areas filled with '00' or 'FF'\n" );
printf ( "\t-S FolderName : Split some NOR section to folder 'FolderName'\n" );
printf ( "\t-M Start Size : Run MD5 sum on file from 'Start' for 'Size' long\n" );
printf ( "\t-E FileName Start Size : Extract specific NOR Section from 'Start' for 'Size' long\n" );
printf ( "\t-D Start Size H/A : Display a specific NOR Section from 'Start' for 'Size' long, \n\t\tuse H or A for Hex or ASCII\n" );
printf ( "\nBy default -P -G -C and -F will be applied if no option is given\n" );
printf ( "\nRepo: < https://github.com/anaria28/NOR-Dump-Tool > \n" );
return ( EXIT_FAILURE );
}
if ( argc == 2 )
{
type = OPTION_STATS + OPTION_CHECK_GENERIC + OPTION_CHECK_PERPS3 + OPTION_CHECK_FILLED;
}
for ( i = 1; i < argc; i++ )
{
if ( strcmp ( argv[i], "-S" ) == 0 ) {
type = type + OPTION_SPLIT;
Option[0].Name = argv[i + 1];
}
if ( strcmp ( argv[i], "-M" ) == 0 ) {
type = type + OPTION_MD5;
Option[1].Start = strtol ( argv[i + 1], NULL, 0 );
Option[1].Size = strtol ( argv[i + 2], NULL, 0 );
}
if ( strcmp ( argv[i], "-E" ) == 0 ) {
type = type + OPTION_EXTRACT;
Option[2].Name = argv[i + 1];
Option[2].Start = strtol ( argv[i + 2], NULL, 0 );
Option[2].Size = strtol ( argv[i + 3], NULL, 0 );
}
if ( strcmp ( argv[i], "-P" ) == 0 ) {
type = type + OPTION_STATS;
}
if ( strcmp ( argv[i], "-G" ) == 0 ) {
type = type + OPTION_CHECK_GENERIC;
}
if ( strcmp ( argv[i], "-C" ) == 0 ) {
type = type + OPTION_CHECK_PERPS3;
}
if ( strcmp ( argv[i], "-D" ) == 0 ) {
type = type + OPTION_DISPLAY_AREA;
Option[6].Start = strtol ( argv[i + 1], NULL, 0 );
Option[6].Size = strtol ( argv[i + 2], NULL, 0 );
if ( argc != i + 3 ) {
if ( strcmp ( argv[i + 3], "H" ) == 0 )
Option[6].Type = TYPE_HEX + DISPLAY_ALWAYS;
else if ( strcmp ( argv[i + 3], "A" ) == 0 )
Option[6].Type = TYPE_ASCII + DISPLAY_ALWAYS;
else
Option[6].Type = TYPE_HEX + DISPLAY_ALWAYS;
}
else
Option[6].Type = TYPE_HEX + DISPLAY_ALWAYS;
}
if ( strcmp ( argv[i], "-F" ) == 0 ) {
type = type + OPTION_CHECK_FILLED;
}
}
fd = fopen ( argv[1], "rb" );
if ( !fd ) {
printf ( "Failed to open %s\n", argv[1] );
return ( EXIT_FAILURE );
}
fseek ( fd, 0, SEEK_END );
if ( ( len = ftell ( fd ) ) != NOR_FILE_SIZE ) {
printf ( "File size not correct for NOR, %d Bytes instead of %d\n", len, NOR_FILE_SIZE );
return ( EXIT_FAILURE );
}
if ( ( ( type ) & ( 1 << 0 ) ) == OPTION_SPLIT ) {
printf ( "******************************\n" );
printf ( "* Splitting NOR Dump *\n" );
printf ( "******************************\n" );
ret = MKDIR( Option[0].Name, 777 );
if ( chdir ( Option[0].Name ) ) {
printf ( "Failed to use folder %s\n", Option[0].Name );
return ( EXIT_FAILURE );
}
GetSection ( fd, SectionTOC[asecure_loader].Offset + 0x18, 0x08, TYPE_HEX, buf );
ExtractionSize = strtol ( buf, NULL, 16 );
ret = ExtractSection ( "asecure_loader", fd, SectionTOC[asecure_loader].Offset + 0x40, ExtractionSize );
ret = ExtractSection ( "eEID", fd, SectionTOC[eEID].Offset, SectionTOC[eEID].Size );
ret = ExtractSection ( "cISD", fd, SectionTOC[cISD].Offset, SectionTOC[cISD].Size );
ret = ExtractSection ( "cCSD", fd, SectionTOC[cCSD].Offset, SectionTOC[cCSD].Size );
ret = ExtractSection ( "trvk_prg0", fd, SectionTOC[trvk_prg0].Offset, SectionTOC[trvk_prg0].Size );
ret = ExtractSection ( "trvk_prg1", fd, SectionTOC[trvk_prg1].Offset, SectionTOC[trvk_prg1].Size );
ret = ExtractSection ( "trvk_pkg0", fd, SectionTOC[trvk_pkg0].Offset, SectionTOC[trvk_pkg0].Size );
ret = ExtractSection ( "trvk_pkg1", fd, SectionTOC[trvk_pkg1].Offset, SectionTOC[trvk_pkg1].Size );
ret = ExtractSection ( "ros0", fd, SectionTOC[ros0].Offset, SectionTOC[ros0].Size );
ret = ExtractSection ( "ros1", fd, SectionTOC[ros1].Offset, SectionTOC[ros1].Size );
ret = ExtractSection ( "cvtrm", fd, SectionTOC[cvtrm].Offset, SectionTOC[cvtrm].Size );
ret = ExtractSection ( "CELL_EXTNOR_AREA", fd, SectionTOC[CELL_EXTNOR_AREA].Offset, SectionTOC[CELL_EXTNOR_AREA].Size );
ret = ExtractSection ( "bootldr", fd, SectionTOC[bootldr].Offset, SectionTOC[bootldr].Size );
}
if ( ( ( type ) & ( 1 << 1 ) ) == OPTION_MD5 ) {
printf ( "******************************\n" );
printf ( "* MD5 Sum on Section *\n" );
printf ( "******************************\n" );
MD5SumFileSection ( "Chosen section MD5 sum is: ", fd, Option[1].Start, Option[1].Size );
}
if ( ( ( type ) & ( 1 << 2 ) ) == OPTION_EXTRACT ) {
printf ( "******************************\n" );
printf ( "* Extracting Section *\n" );
printf ( "******************************\n" );
ret = ExtractSection ( Option[2].Name, fd, Option[2].Start, Option[2].Size );
}
if ( ( ( type ) & ( 1 << 3 ) ) == OPTION_STATS ) {
Statistics ( fd );
}
// Checking not done yet for a byte reserved dump it's then better to warn and exit for now.
if ( ( ReadSection ( "ByteReserved? ", fd, SectionTOC[FlashStart].Offset + 0x14, 0x04, TYPE_HEX, 1, "0FACE0FF" ) == EXIT_FAILURE ) &&
( ReadSection ( "ByteReserved? ", fd, SectionTOC[FlashStart].Offset + 0x14, 0x04, TYPE_HEX, 1, "AC0FFFE0" ) == EXIT_SUCCESS ) ) {
printf ( "Not treating byte reversed dump at the moment.\n" );
return ( EXIT_FAILURE );
}
if ( ( ( type ) & ( 1 << 4 ) ) == OPTION_CHECK_GENERIC ) {
if ( ( ret = CheckGenericData ( fd ) ) ) {
printf ( "Some checking were not successful.\n" );
printf ( "You may need to check further your dump.\n" );
printf ( "But fortunately for the Generic section of the NOR it may be fixed.\n" );
}
else {
printf ( "Seems good, but you'd eventually like to be carefull!\n" );
}
}
if ( ( ( type ) & ( 1 << 5 ) ) == OPTION_CHECK_PERPS3 ) {
if ( ( ret = CheckPerConsoleData ( fd ) ) ) {
printf ( "Some checking were not successful.\n" );
printf ( "You may need to check further your dump.\n" );
printf ( "Be cautious, flashing this one may lead to a brick of your PS3.\n" );
}
else {
printf ( "Seems good, but you'd eventually like to be carefull!\n" );
}
}
if ( ( ( type ) & ( 1 << 6 ) ) == OPTION_DISPLAY_AREA ) {
sprintf ( DisplaySection, "Start at '0x%08X' of size '0x%02X'", Option[6].Start, Option[6].Size );
ret = ReadSection ( DisplaySection, fd, Option[6].Start, Option[6].Size, Option[6].Type, 0, NULL );
}
if ( ( ( type ) & ( 1 << 7 ) ) == OPTION_CHECK_FILLED ) {
if ( ( ret = CheckFilledData ( fd ) ) ) {
printf ( "Some checking were not successful.\n" );
printf ( "You may need to check further your dump.\n" );
printf ( "Be cautious there is something fishy in your dump.\n" );
}
else {
printf ( "Seems good, but you'd eventually like to be carefull!\n" );
}
}
fclose ( fd );
free( buf );
return ( EXIT_SUCCESS );
}