-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsq_tools.py
1784 lines (1675 loc) · 54.7 KB
/
sq_tools.py
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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import random
import os, codecs
import Hex
from binascii import hexlify as hx, unhexlify as uhx
import Keys
import re
from hashlib import sha256
from struct import pack as pk, unpack as upk
import Fs
import aes128
import sq_tools
import io
import Print
indent = 1
tabs = '\t' * indent
'''
versions =
0: "1.0.0", -> keygeneration = 0
450: "1.0.0", -> keygeneration = 0
65536: "2.0.0", -> keygeneration = 1
131072: "2.1.0", -> keygeneration = 1
196608: "2.2.0", -> keygeneration = 1
262144: "2.3.0", -> keygeneration = 1
201326592: "3.0.0", -> keygeneration = 2
201392128: "3.0.1", -> keygeneration = 3
201457664: "3.0.2", -> keygeneration = 3
268435456: "4.0.0", -> keygeneration = 4
268500992: "4.0.1", -> keygeneration = 4
269484032: "4.1.0", -> keygeneration = 4
335544320: "5.0.0", -> keygeneration = 5
335609856: "5.0.1", -> keygeneration = 5
335675392: "5.0.2", -> keygeneration = 5
336592896: "5.1.0", -> keygeneration = 5
402653184: "6.0.0", -> keygeneration = 6
402718720: "6.0.1", -> keygeneration = 6
403701760: "6.1.0", -> keygeneration = 6
404750336: "6.2.0" -> keygeneration = 7
469762048: "7.0.0" -> keygeneration = 8
469827584: "7.0.1" -> keygeneration = 8
536870912: "8.0.0" -> keygeneration = 8
536936448: "8.0.1" -> keygeneration = 8
537919488: "8.1.0" -> keygeneration = 9
603979776: "9.0.0" -> keygeneration = 10
604045312: "9.0.1" -> keygeneration = 10
605028352: "9.1.0" -> keygeneration = 11
606076928: "9.2.0" -> keygeneration = 11
671088640: "10.0.0" -> keygeneration = 11
671154176: "10.0.1" -> keygeneration = 11
671219712: "10.0.2" -> keygeneration = 11
671285248: "10.0.3" -> keygeneration = 11
671350784: "10.0.4" -> keygeneration = 11
672137216: "10.1.0" -> keygeneration = 11
672202752: "10.1.1" -> keygeneration = 11
673185792: "10.2.0" -> keygeneration = 11
738197504: "11.0.0" -> keygeneration = 11
738263040: "11.0.1" -> keygeneration = 11
805306368: "12.0.0" -> keygeneration = 11
805371904: "12.0.1" -> keygeneration = 11
805437440: "12.0.2" -> keygeneration = 11
805502976: "12.0.3" -> keygeneration = 11
806354944: "12.1.0" -> keygeneration = 12
872415232: "13.0.0" -> keygeneration = 13
873463808: "13.1.0" -> keygeneration = 13
874512404: "13.2.0" -> keygeneration = 13
874578000: "13.2.1" -> keygeneration = 13
939524096: "14.0.0" -> keygeneration = 14
940572672: "14.1.0" -> keygeneration = 14
940638208: "14.1.1" -> keygeneration = 14
940703744: "14.1.2" -> keygeneration = 14
1006632960: "15.0.0" -> keygeneration = 15
1006698496: "15.0.1" -> keygeneration = 15
1073741824: "16.0.0" -> keygeneration = 16
1073807360: "16.0.1" -> keygeneration = 16
1073872896: "16.0.2" -> keygeneration = 16
1073938432: "16.0.3" -> keygeneration = 16
1074790400: "16.1.0" -> keygeneration = 16
'''
def kgstring():
kg=list()
kg16=[1073741824,1073807360,1073872896,1073938432,1074790400];kg.append(kg16)
kg15=[1006632960,1006698496];kg.append(kg15)
kg14=[939524096,940572672,940638208,940703744];kg.append(kg14)
kg13=[872415232,873463808,874512404,874578000];kg.append(kg13)
kg12=[806354944];kg.append(kg12)
kg11=[605028352,606076928,671088640,671154176,671219712,671285248,671350784,672137216,672202752,673185792,738197504,738263040,805306368,805371904,805437440,805502976];kg.append(kg11)
kg10=[603979776,604045312];kg.append(kg10)
kg9=[537919488];kg.append(kg9)
kg8=[536936448,536870912,469827584,469762048];kg.append(kg8)
kg7=[404750336];kg.append(kg7)
kg6=[403701760,402718720,402653184];kg.append(kg6)
kg5=[336592896,335675392,335609856,335544320];kg.append(kg5)
kg4=[269484032,268500992,268435456];kg.append(kg4)
kg3=[201457664,201392128];kg.append(kg3)
kg2=[201326592];kg.append(kg2)
kg1=[262144,196608,131072,65536];kg.append(kg1)
kg0=[450,0];kg.append(kg0)
return kg
def kg_by_RSV(RSV):
kgs=kgstring();keygen=len(kgs)-1;topkg=len(kgs)
for k in range(len(kgs)):
if not RSV in kgs[k]:
keygen-=1
if RSV in kgs[k]:
break
if keygen<0:
return 'unknown'
return keygen
def transform_fw_string(FW):
FW=FW.split('-');rem=0;RRSV=0
if len(FW)>1:
rem=FW[1]
else:
rem=0
FW=FW[0]
FW=FW.split('.')
RSV=0
for i in range(len(FW)):
n=int(FW[i])
if i==0:
if n>=3:
RSV+=67108864*n
elif n==2:
RSV+=65536
elif i==1 and int(FW[0])>3:
RSV+=1048576*n
elif i==1 and int(FW[0])==2:
RSV+=1*n
elif i==2 and int(FW[0])>3:
RSV+=65536*n
RRSV=RSV+rem
return RSV,RRSV
def kg2masterkey(kg):
if kg == 1:
return 1
else:
return kg-1
def getTopRSV(keygeneration, RSV):
if keygeneration == 0:
return 450
if keygeneration == 1:
return 262164
if keygeneration == 2:
return 201327002
if keygeneration == 3:
return 201457684
if keygeneration == 4:
return 269484082
if keygeneration == 5:
return 336592976
if keygeneration == 6:
return 403701850
if keygeneration == 7:
return 404750376
if keygeneration == 8:
return 536936448
if keygeneration == 9:
return 537919488
if keygeneration == 10:
return 603979776
if keygeneration == 11:
return 605028352
if keygeneration == 12:
return 806354944
if keygeneration == 13:
return 872415232
if keygeneration == 14:
return 939524096
if keygeneration == 15:
return 1006632960
if keygeneration == 16:
return 1073741824
else:
return RSV
def getMinRSV(keygeneration, RSV):
if keygeneration == 0:
return 0
if keygeneration == 1:
return 65796
if keygeneration == 2:
RSV=3*67108864
return RSV
if keygeneration == 3:
RSV=3*67108864+1*65536
return RSV
if keygeneration == 4:
RSV=4*67108864
return RSV
if keygeneration == 5:
RSV=5*67108864
return RSV
if keygeneration == 6:
RSV=6*67108864
return RSV
if keygeneration == 7:
RSV=6*67108864+2*1048576
return RSV
if keygeneration == 8:
RSV=7*67108864
return RSV
if keygeneration == 9:
RSV=8*67108864+1*1048576
return RSV
if keygeneration == 10:
RSV=9*67108864
return RSV
if keygeneration == 11:
RSV=9*67108864+1*1048576+0*65796+0*1
return RSV
if keygeneration == 12:
RSV=12*67108864+1*1048576+0*65796+0*1
return RSV
if keygeneration == 13:
RSV=13*67108864+0*1048576+0*65796+0*1
return RSV
if keygeneration == 14:
RSV=14*67108864+0*1048576+0*65796+0*1
return RSV
if keygeneration == 15:
RSV=15*67108864+0*1048576+0*65796+0*1
return RSV
if keygeneration == 16:
RSV=16*67108864+0*1048576+0*65796+0*1
return RSV
else:
return RSV
def getFWRangeKG(keygeneration):
if keygeneration == 0:
return "(1.0.0)"
if keygeneration == 1:
return "(2.0.0 - 2.3.0)"
if keygeneration == 2:
return "(3.0.0)"
if keygeneration == 3:
return "(3.0.1 - 3.0.2)"
if keygeneration == 4:
return "(4.0.0 - 4.1.0)"
if keygeneration == 5:
return "(5.0.0 - 5.1.0)"
if keygeneration == 6:
return "(6.0.0 - 6.1.0)"
if keygeneration == 7:
return "(6.2.0)"
if keygeneration == 8:
return "(7.0.0 - 8.0.1)"
if keygeneration == 9:
return "(8.1.0)"
if keygeneration == 10:
return "(9.0.0 - 9.0.1)"
if keygeneration == 11:
return "(9.1.0 - 12.0.3)"
if keygeneration == 12:
return "(12.1.0)"
if keygeneration == 13:
return "(13.0.0 - 13.2.1)"
if keygeneration == 14:
return "(14.0.0 - 14.1.2)"
if keygeneration == 15:
return "(15.0.0 - 15.0.1)"
if keygeneration == 16:
return "(>= 16.0.0)"
else:
return "UNKNOWN"
def getmetacontenttype(ncatypenumber):
ncatypenumber=int(ncatypenumber)
if ncatypenumber==0:
return "Meta"
elif ncatypenumber==1:
return "Program"
elif ncatypenumber==2:
return "Data"
elif ncatypenumber==3:
return "Control"
elif ncatypenumber==4:
return "HtmlDocument"
elif ncatypenumber==5:
return "LegalInformation"
elif ncatypenumber==6:
return "DeltaFragment"
def getFWRangeRSV(RSV):
if RSV >= (3*67108864):
RSV=int(RSV)
frst_num=str(int(RSV/67108864))
remainder=RSV%67108864
sec_num=str(int(remainder/1048576))
remainder=remainder%1048576
thd_num=str(int(remainder/65536))
remainder=remainder%65536
fth_num=remainder
version=str(frst_num)
version+='.'
version+=str(sec_num)
version+='.'
version+=str(thd_num)
if fth_num > 0:
version+='-'
version+=str(fth_num)
version="("+version+")"
return version
elif RSV >= 65536:
RSV=int(RSV)
frst_num=2
sec_num=str(int(RSV/65536))
remainder=RSV%65536
thd_num=0
fth_num=remainder
version=str(frst_num)
version+='.'
version+=str(sec_num)
version+='.'
version+=str(thd_num)
if fth_num > 0:
version+='-'
version+=str(fth_num)
version="("+version+")"
return version
elif RSV > 0:
RSV=int(RSV)
frst_num=1
sec_num=0
thd_num=0
remainder=RSV%65536
fth_num=remainder
version=str(frst_num)
version+='.'
version+=str(sec_num)
version+='.'
version+=str(thd_num)
if fth_num > 0:
version+='-'
version+=str(fth_num)
version="("+version+")"
return version
elif RSV == 0:
return "(1.0.0)"
else:
return "(-)"
def getSize(bytes):
if bytes>(1024*1024*1024):
Gbytes=bytes/(1024*1024*1024)
Gbytes=round(Gbytes,2)
Gbytes=str(Gbytes)+"GB"
return Gbytes
if bytes>(1024*1024):
Mbytes=bytes/(1024*1024)
Mbytes=round(Mbytes,2)
Mbytes=str(Mbytes)+"MB"
return Mbytes
if bytes>(1024):
Kbytes=bytes/(1024)
Kbytes=round(Kbytes,2)
Kbytes=str(Kbytes)+"KB"
return Kbytes
else:
bytes=str(bytes)+"B"
return bytes
def getGCsize(bytes):
Gbytes=bytes/(1024*1024*1024)
Gbytes=round(Gbytes,2)
if Gbytes>=32:
card=0xE3
firm_ver='1000a100'
return card,firm_ver
if Gbytes>=16:
card=0xE2
firm_ver='1000a100'
return card,firm_ver
if Gbytes>=8:
card=0xE1
firm_ver='1000a100'
return card,firm_ver
if Gbytes>=4:
card=0xE0
firm_ver='1000a100'
return card,firm_ver
if Gbytes>=2:
card=0xF0
firm_ver='1100a100'
return card,firm_ver
if Gbytes>=1:
card=0xF8
firm_ver='1100a100'
return card,firm_ver
if Gbytes<1:
card=0xFA
firm_ver='1100a100'
return card,firm_ver
def getGCsizeinbytes(GCflag):
bytes=''
if GCflag=='E3':
size=64
if GCflag=='E2':
size=32
if GCflag=='E1':
size=16
if GCflag=='E0':
size=8
if GCflag=='F0':
size=4
if GCflag=='F8':
size=2
if GCflag=='FA':
size=1
bytes=size*998244352
return bytes
def getTypeFromCNMT(number):
if number == 0:
return "Meta: "
if number == 1:
return "Program: "
if number == 2:
return "Data: "
if number == 3:
return "Control: "
if number == 4:
return "HtmlDoc: "
if number == 5:
return "LegalInf: "
if number == 6:
return "Delta: "
def randhex(size):
hexdigits = "0123456789ABCDEF"
random_digits = "".join([ hexdigits[random.randint(0,0xF)] for _ in range(size*2) ])
return random_digits
def get_enc_gameinfo(bytes):
Gbytes=bytes/(1024*1024*1024)
Gbytes=round(Gbytes,2)
if Gbytes>=32 or Gbytes>=16 or Gbytes>=8 or Gbytes>=4:
firm_ver= 0x9298F35088F09F7D
access_freq= 0xa89a60d4
Read_Wait_Time= 0xcba6f96f
Read_Wait_Time2= 0xa45bb6ac
Write_Wait_Time= 0xabc751f9
Write_Wait_Time2= 0x5d398742
Firmware_Mode = 0x6b38c3f2
CUP_Version = 0x10da0b70
Empty1 = 0x0e5ece29
Upd_Hash= 0xa13cbe1da6d052cb
CUP_Id = 0xf2087ce9af590538
Empty2= 0x570d78b9cdd27fbeb4a0ac2adff9ba77754dd6675ac76223506b3bdabcb2e212fa465111ab7d51afc8b5b2b21c4b3f40654598620282add6
else:
firm_ver= 0x9109FF82971EE993
access_freq=0x5011ca06
Read_Wait_Time=0x3f3c4d87
Read_Wait_Time2=0xa13d28a9
Write_Wait_Time=0x928d74f1
Write_Wait_Time2=0x49919eb7
Firmware_Mode =0x82e1f0cf
CUP_Version = 0xe4a5a3bd
Empty1 = 0xf978295c
Upd_Hash= 0xd52639a4991bdb1f
CUP_Id = 0xed841779a3f85d23
Empty2= 0xaa4242135616f5187c03cf0d97e5d218fdb245381fd1cf8dfb796fbeda4bf7f7d6b128ce89bc9eaa8552d42f597c5db866c67bb0dd8eea11
firm_ver=firm_ver.to_bytes(8, byteorder='big')
access_freq=access_freq.to_bytes(4, byteorder='big')
Read_Wait_Time=Read_Wait_Time.to_bytes(4, byteorder='big')
Read_Wait_Time2=Read_Wait_Time2.to_bytes(4, byteorder='big')
Write_Wait_Time=Write_Wait_Time.to_bytes(4, byteorder='big')
Write_Wait_Time2=Write_Wait_Time2.to_bytes(4, byteorder='big')
Firmware_Mode=Firmware_Mode.to_bytes(4, byteorder='big')
CUP_Version=CUP_Version.to_bytes(4, byteorder='big')
Empty1=Empty1.to_bytes(4, byteorder='big')
Upd_Hash=Upd_Hash.to_bytes(8, byteorder='big')
CUP_Id=CUP_Id.to_bytes(8, byteorder='big')
Empty2=Empty2.to_bytes(56, byteorder='big')
Game_info = b''
Game_info += firm_ver
Game_info += access_freq
Game_info += Read_Wait_Time
Game_info += Read_Wait_Time2
Game_info += Write_Wait_Time
Game_info += Write_Wait_Time2
Game_info += Firmware_Mode
Game_info += CUP_Version
Game_info += Empty1
Game_info += Upd_Hash
Game_info += CUP_Id
Game_info += Empty2
#print(Game_info)
return Game_info
def get_krypto_block(keygeneration):
if keygeneration == 0:
return 'f3cbc0052cac528adf9129210f0a02e4'
if keygeneration == 1:
return 'f3cbc0052cac528adf9129210f0a02e4'
if keygeneration == 2:
return '789800b9e78b860eec2f7862ef05545e'
if keygeneration == 3:
return '99776e03a21f56232d056b8683d9c681'
if keygeneration == 4:
return '48df2c73957fa1b73b8e33fb2d052512'
if keygeneration == 5:
return '91dea3589a56e4fa1ce60a444009e7d8'
if keygeneration == 6:
return 'cd5b0d1abcf6450f37b8a3b68a15d5e9'
if keygeneration == 7:
return 'e7ae8f7303809fd63cbd1f500b31d5b9'
else:
return "UNKNOWN"
def verify_nkeys(fileName):
indent = 1
tabs = ' ' * indent
checkkeys = {}
with open(fileName, encoding="utf8") as f:
for line in f.readlines():
r = re.match('\s*([a-z0-9_]+)\s*=\s*([A-F0-9]+)\s*', line, re.I)
if r:
checkkeys[r.group(1)] = r.group(2)
print("")
if 'aes_kek_generation_source' not in checkkeys:
print("aes_kek_generation_source is Missing")
if 'aes_key_generation_source' not in checkkeys:
print("aes_key_generation_source is Missing")
if 'titlekek_source' not in checkkeys:
print("titlekek_source is Missing")
if 'key_area_key_application_source' not in checkkeys:
print("key_area_key_application_source is Missing")
if 'key_area_key_ocean_source' not in checkkeys:
print("key_area_key_ocean_source is Missing")
if 'key_area_key_system_source' not in checkkeys:
print("key_area_key_system_source is Missing")
counter=0
if 'master_key_00' not in checkkeys:
print("master_key_00 is Missing")
else:
counter+=1
if 'master_key_01' not in checkkeys:
print("master_key_01 is Missing")
else:
counter+=1
if 'master_key_02' not in checkkeys:
print("master_key_02 is Missing")
else:
counter+=1
if 'master_key_03' not in checkkeys:
print("master_key_03 is Missing")
else:
counter+=1
if 'master_key_04' not in checkkeys:
print("master_key_04 is Missing")
else:
counter+=1
if 'master_key_05' not in checkkeys:
print("master_key_05 is Missing")
else:
counter+=1
if 'master_key_06' not in checkkeys:
print("master_key_06 is Missing")
else:
counter+=1
if 'master_key_07' not in checkkeys:
print("master_key_07 is Missing")
else:
counter+=1
if 'master_key_08' not in checkkeys:
print("master_key_08 is Missing")
else:
counter+=1
if 'master_key_09' not in checkkeys:
print("master_key_09 is Missing")
else:
counter+=1
if 'master_key_10' not in checkkeys and 'master_key_0a' not in checkkeys:
print("master_key_10|master_key_0a is Missing")
else:
counter+=1
if 'header_key' not in checkkeys:
print("header_key is Missing")
if 'xci_header_key' not in checkkeys:
print('OPTIONAL KEY "xci_header_key" is Missing')
while counter<len(checkkeys):
if len(str(counter))<2:
mkverifier='master_key_0'+str(counter)
else:
mkverifier='master_key'+str(counter)
if mkverifier in checkkeys:
print(mkverifier+" is present but program doesn't have the hash to verify the key")
for i in checkkeys:
if i==mkverifier:
mk =checkkeys[i][:]
sha=sha256(uhx(mk)).hexdigest()
print(' > HEX SHA256: '+sha)
print('')
counter+=1
for i in checkkeys:
if i == 'aes_kek_generation_source':
aes_kek_generation_source =checkkeys[i][:]
print('aes_kek_generation_source : '+aes_kek_generation_source )
sha=sha256(uhx(aes_kek_generation_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == 'fc02b9d37b42d7a1452e71444f1f700311d1132e301a83b16062e72a78175085':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'aes_key_generation_source':
aes_key_generation_source =checkkeys[i][:]
print('aes_key_generation_source : '+aes_key_generation_source )
sha=sha256(uhx(aes_key_generation_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == 'fbd10056999edc7acdb96098e47e2c3606230270d23281e671f0f389fc5bc585':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'titlekek_source':
titlekek_source=checkkeys[i][:]
print('titlekek_source: '+titlekek_source)
sha=sha256(uhx(titlekek_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == 'c48b619827986c7f4e3081d59db2b460c84312650e9a8e6b458e53e8cbca4e87':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'key_area_key_application_source':
key_area_key_application_source=checkkeys[i][:]
print('key_area_key_application_source: '+key_area_key_application_source)
sha=sha256(uhx(key_area_key_application_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '04ad66143c726b2a139fb6b21128b46f56c553b2b3887110304298d8d0092d9e':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'key_area_key_ocean_source':
key_area_key_ocean_source=checkkeys[i][:]
print('key_area_key_ocean_source: '+key_area_key_ocean_source)
sha=sha256(uhx(key_area_key_ocean_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == 'fd434000c8ff2b26f8e9a9d2d2c12f6be5773cbb9dc86300e1bd99f8ea33a417':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'key_area_key_system_source':
key_area_key_system_source=checkkeys[i][:]
print('key_area_key_system_source: '+key_area_key_system_source)
sha=sha256(uhx(key_area_key_system_source)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '1f17b1fd51ad1c2379b58f152ca4912ec2106441e51722f38700d5937a1162f7':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_00':
master_key_00=checkkeys[i][:]
print('master_key_00: '+master_key_00)
sha=sha256(uhx(master_key_00)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '0ee359be3c864bb0782e1d70a718a0342c551eed28c369754f9c4f691becf7ca':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_01':
master_key_01=checkkeys[i][:]
print('master_key_01: '+master_key_01)
sha=sha256(uhx(master_key_01)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '4fe707b7e4abdaf727c894aaf13b1351bfe2ac90d875f73b2e20fa94b9cc661e':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_02':
master_key_02=checkkeys[i][:]
print('master_key_02: '+master_key_02)
sha=sha256(uhx(master_key_02)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '79277c0237a2252ec3dfac1f7c359c2b3d121e9db15bb9ab4c2b4408d2f3ae09':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_03':
master_key_03=checkkeys[i][:]
print('master_key_03: '+master_key_03)
sha=sha256(uhx(master_key_03)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '4f36c565d13325f65ee134073c6a578ffcb0008e02d69400836844eab7432754':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_04':
master_key_04=checkkeys[i][:]
print('master_key_04: '+master_key_04)
sha=sha256(uhx(master_key_04)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '75ff1d95d26113550ee6fcc20acb58e97edeb3a2ff52543ed5aec63bdcc3da50':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_05':
master_key_05=checkkeys[i][:]
print('master_key_05: '+master_key_05)
sha=sha256(uhx(master_key_05)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == 'ebe2bcd6704673ec0f88a187bb2ad9f1cc82b718c389425941bdc194dc46b0dd':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_06':
master_key_06=checkkeys[i][:]
print('master_key_06: '+master_key_06)
sha=sha256(uhx(master_key_06)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '9497e6779f5d840f2bba1de4e95ba1d6f21efc94717d5ae5ca37d7ec5bd37a19':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_07':
master_key_07=checkkeys[i][:]
print('master_key_07: '+master_key_07)
sha=sha256(uhx(master_key_07)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '4ec96b8cb01b8dce382149443430b2b6ebcb2983348afa04a25e53609dabedf6':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_08':
master_key_08=checkkeys[i][:]
print('master_key_08: '+master_key_08)
sha=sha256(uhx(master_key_08)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '2998e2e23609bc2675ff062a2d64af5b1b78dff463b24119d64a1b64f01b2d51':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_09':
master_key_09=checkkeys[i][:]
print('master_key_09: '+master_key_09)
sha=sha256(uhx(master_key_09)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '9d486a98067c44b37cf173d3bf577891eb6081ff6b4a166347d9dbbf7025076b':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'master_key_10' or i == 'master_key_0a':
master_key_10=checkkeys[i][:]
print('master_key_10|master_key_0a: '+master_key_10)
sha=sha256(uhx(master_key_10)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '4ec5a237a75a083a9c5f6cf615601522a7f822d06bd4ba32612c9cebbb29bd45':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'header_key':
header_key=checkkeys[i][:]
print('header_key: '+header_key)
sha=sha256(uhx(header_key)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '8e03de24818d96ce4f2a09b43af979e679974f7570713a61eed8b314864a11d5':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
if i == 'xci_header_key':
xci_header_key=checkkeys[i][:]
print('xci_header_key: '+xci_header_key)
sha=sha256(uhx(xci_header_key)).hexdigest()
print(' > HEX SHA256: '+sha)
if sha == '2e36cc55157a351090a73e7ae77cf581f69b0b6e48fb066c984879a6ed7d2e96':
print(tabs+'> Key is valid!!!')
else:
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
print('')
def verify_nkeys_startup(fileName):
indent = 1
tabs = ' ' * indent
checkkeys = {}
startup=False
with open(fileName, encoding="utf8") as f:
for line in f.readlines():
r = re.match('\s*([a-z0-9_]+)\s*=\s*([A-F0-9]+)\s*', line, re.I)
if r:
checkkeys[r.group(1)] = r.group(2)
print("")
if 'aes_kek_generation_source' not in checkkeys:
print("aes_kek_generation_source is Missing")
print("This is a needed key!!!")
startup=True
if 'aes_key_generation_source' not in checkkeys:
print("aes_key_generation_source is Missing")
print("This is a needed key!!!")
startup=True
if 'titlekek_source' not in checkkeys:
print("titlekek_source is Missing")
print("This is a needed key!!!")
startup=True
if 'key_area_key_application_source' not in checkkeys:
print("key_area_key_application_source is Missing")
print("This is a needed key!!!")
startup=True
if 'key_area_key_ocean_source' not in checkkeys:
print("key_area_key_ocean_source is Missing")
print("This is a needed key!!!")
startup=True
if 'key_area_key_system_source' not in checkkeys:
print("key_area_key_system_source is Missing")
print("This is a needed key!!!")
startup=True
counter=0
if 'master_key_00' not in checkkeys:
print("master_key_00 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 1.0.0-2.3.0 requirement")
startup=True
else:
counter+=1
if 'master_key_01' not in checkkeys:
print("master_key_01 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 3.0.0 requirement")
startup=True
else:
counter+=1
if 'master_key_02' not in checkkeys:
print("master_key_02 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 3.0.1-3.0.2 requirement")
startup=True
else:
counter+=1
if 'master_key_03' not in checkkeys:
print("master_key_03 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 4.0.0-4.0.1 requirement")
startup=True
else:
counter+=1
if 'master_key_04' not in checkkeys:
print("master_key_04 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 5.0.0-5.1.0 requirement")
startup=True
else:
counter+=1
if 'master_key_05' not in checkkeys:
print("master_key_05 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 6.0.0-6.1.0 requirement")
startup=True
else:
counter+=1
if 'master_key_06' not in checkkeys:
print("master_key_06 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 6.2.0 requirement")
startup=True
else:
counter+=1
if 'master_key_07' not in checkkeys:
print("master_key_07 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 7.0.0-8.0.1 requirement")
startup=True
else:
counter+=1
if 'master_key_08' not in checkkeys:
print("master_key_08 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 8.1 requirement")
startup=True
else:
counter+=1
if 'master_key_09' not in checkkeys:
print("master_key_09 is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 9.0 requirement")
startup=True
else:
counter+=1
if 'master_key_10' not in checkkeys and 'master_key_0a' not in checkkeys:
print("master_key_10|master_key_0a is Missing!!!")
print("The program won't be able to decrypt games content that uses this key")
print("This key represents FW 9.1-10.04 requirement")
startup=True
else:
counter+=1
if 'header_key' not in checkkeys:
print("header_key is Missing")
if 'xci_header_key' not in checkkeys:
print('OPTIONAL KEY "xci_header_key" is Missing')
while counter<len(checkkeys):
if len(str(counter))<2:
mkverifier='master_key_0'+str(counter)
else:
mkverifier='master_key'+str(counter)
if mkverifier in checkkeys:
print(mkverifier+" is present but program doesn't have the hash to verify the key")
for i in checkkeys:
if i==mkverifier:
mk =checkkeys[i][:]
sha=sha256(uhx(mk)).hexdigest()
print(' > HEX SHA256: '+sha)
print('')
counter+=1
for i in checkkeys:
if i == 'aes_kek_generation_source':
aes_kek_generation_source =checkkeys[i][:]
sha=sha256(uhx(aes_kek_generation_source)).hexdigest()
if sha != 'fc02b9d37b42d7a1452e71444f1f700311d1132e301a83b16062e72a78175085':
print('aes_kek_generation_source : '+aes_kek_generation_source )
print(' > HEX SHA256: '+sha)
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
startup=True
print('')
if i == 'aes_key_generation_source':
aes_key_generation_source =checkkeys[i][:]
sha=sha256(uhx(aes_key_generation_source)).hexdigest()
if sha != 'fbd10056999edc7acdb96098e47e2c3606230270d23281e671f0f389fc5bc585':
print('aes_key_generation_source : '+aes_kek_generation_source )
print(' > HEX SHA256: '+sha)
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
startup=True
print('')
if i == 'titlekek_source':
titlekek_source=checkkeys[i][:]
sha=sha256(uhx(titlekek_source)).hexdigest()
if sha != 'c48b619827986c7f4e3081d59db2b460c84312650e9a8e6b458e53e8cbca4e87':
print('titlekek_source : '+aes_kek_generation_source )
print(' > HEX SHA256: '+sha)
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
startup=True
print('')
if i == 'key_area_key_application_source':
key_area_key_application_source=checkkeys[i][:]
sha=sha256(uhx(key_area_key_application_source)).hexdigest()
if sha != '04ad66143c726b2a139fb6b21128b46f56c553b2b3887110304298d8d0092d9e':
print('key_area_key_application_source: '+aes_kek_generation_source )
print(' > HEX SHA256: '+sha)
print(tabs+'> Key is invalid!!! -> PLEASE CHECK YOUR KEYS.TXT!!!')
startup=True
print('')
if i == 'key_area_key_ocean_source':
key_area_key_ocean_source=checkkeys[i][:]