-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoggInspectorLib.cs
1439 lines (1393 loc) · 67.6 KB
/
MoggInspectorLib.cs
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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
/* using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Windows.Security.Cryptography.Certificates;
*/
using System.Security.Cryptography;
// MoggInspectorLib v0.1
// Use to calculate certain mogg security values, to check for PS3 errors
// Caller must provide the mogg header to the DeriveKeys method in a byte array, from byte 0 to the offset pointed to
// by the LITTLE-ENDIAN 32-bit integer at mogg offset 4, noninclusive
// DeriveKeys takes two arguments, the header byte array and a boolean, the boolean must be FALSE for almost all RB
// content. This will use the "green" HvKeys, and will be inert for v11 moggs
// If the boolean argument is set to TRUE, it will use the "red" HvKeys that have been found in every game but that
// no content we've ever seen actually uses
// Recommended practice is to use the green keys, check for the known C3 mismatches, if none of those are found and
// there is still a mismatch, save the contents of Ps3FixedMask and then run DeriveKeys again with the boolean set
// to TRUE. If that results in a matching XboxAesKey and Ps3AesKey, then we have a "special" mogg that used the red
// keys and thus was intended for purposes we're not sure of (potentially internal-only mogg encryption? all known
// xbox 360 debug builds of milo like Dance Central use the green keys even though they're intended for use on a dev
// kit). We don't really know much about the red keys, but we also don't want to inadvertently destroy them in the
// process of looking for PS3 encryption issues. My UI frontend will use this algorithm. Only if the second check
// (with the boolean set to TRUE) fails will you need to patch the mogg at offset Ps3KeyMaskOffset with Ps3FixedMask
// Caller must then use the public variables to determine what UI to provide, and must handle keymask patching using
// the returned value
// The library will *not* do the patching for you, I don't want the DLL able to patch files itself
// The library *will*, however, give you the offset you need to patch, in Ps3KeyMaskOffset
// V17Keyset and V17KeysetOffset will not be defined if version is not 17
// Values irrelevant to v11 moggs will not be defined when fed a v11 header
// Useful offsets for moggheads:
// 20+(_HeaderBlockSize*8) - Nonce offset, and base offset for many other values
namespace MoggInspectorLib
{
public class KeyChain
{
private readonly byte[] _Masher = new byte[] { 0x39, 0xa2, 0xbf, 0x53, 0x7d, 0x88, 0x1d, 0x03, 0x35, 0x38, 0xa3, 0x80, 0x45, 0x24, 0xee, 0xca, 0x25, 0x6d, 0xa5, 0xc2, 0x65, 0xa9, 0x94, 0x73, 0xe5, 0x74, 0xeb, 0x54, 0xe5, 0x95, 0x3f, 0x1c };
private readonly byte[] _CtrKey_11 = new byte[] { 0x37, 0xb2, 0xe2, 0xb9, 0x1c, 0x74, 0xfa, 0x9e, 0x38, 0x81, 0x08, 0xea, 0x36, 0x23, 0xdb, 0xe4 };
private readonly byte[] _HvKey_12 = new byte[] { 0x01, 0x22, 0x00, 0x38, 0xd2, 0x01, 0x78, 0x8b, 0xdd, 0xcd, 0xd0, 0xf0, 0xfe, 0x3e, 0x24, 0x7f };
private readonly byte[] _HvKey_14 = new byte[] { 0x51, 0x73, 0xad, 0xe5, 0xb3, 0x99, 0xb8, 0x61, 0x58, 0x1a, 0xf9, 0xb8, 0x1e, 0xa7, 0xbe, 0xbf };
private readonly byte[] _HvKey_15 = new byte[] { 0xc6, 0x22, 0x94, 0x30, 0xd8, 0x3c, 0x84, 0x14, 0x08, 0x73, 0x7c, 0xf2, 0x23, 0xf6, 0xeb, 0x5a };
private readonly byte[] _HvKey_16 = new byte[] { 0x02, 0x1a, 0x83, 0xf3, 0x97, 0xe9, 0xd4, 0xb8, 0x06, 0x74, 0x14, 0x6b, 0x30, 0x4c, 0x00, 0x91 };
private readonly byte[] _HvKey_17 = new byte[] { 0x42, 0x66, 0x37, 0xb3, 0x68, 0x05, 0x9f, 0x85, 0x6e, 0x96, 0xbd, 0x1e, 0xf9, 0x0e, 0x7f, 0xbd };
private readonly byte[] _HvKey_12_r = new byte[] { 0xf7, 0xb6, 0xc2, 0x22, 0xb6, 0x66, 0x5b, 0xd5, 0x6c, 0xe0, 0x7d, 0x6c, 0x8a, 0x46, 0xdb, 0x18 };
private readonly byte[] _HvKey_14_r = new byte[] { 0x60, 0xad, 0x83, 0x0b, 0xc2, 0x2f, 0x82, 0xc5, 0xcb, 0xbf, 0xf4, 0x3d, 0x60, 0x52, 0x7e, 0x33 };
private readonly byte[] _HvKey_15_r = new byte[] { 0x6c, 0x68, 0x55, 0x98, 0x5b, 0x12, 0x21, 0x41, 0xe7, 0x85, 0x35, 0xca, 0x19, 0xe1, 0x9a, 0xf3 };
private readonly byte[] _HvKey_16_r = new byte[] { 0xa4, 0x2f, 0xf3, 0xe4, 0xe8, 0xfb, 0xa5, 0x9e, 0xac, 0x79, 0x01, 0x9e, 0xd5, 0x89, 0x66, 0xec };
private readonly byte[] _HvKey_17_r = new byte[] { 0x0b, 0x9c, 0x96, 0xce, 0xb6, 0xf0, 0xbc, 0xde, 0x4e, 0x9c, 0xd1, 0xc4, 0x1d, 0xeb, 0x7f, 0xe6 };
private readonly byte[] _HiddenKeys = new byte[] // pre-v17
{
0x7f, 0x95, 0x5b, 0x9d, 0x94, 0xba, 0x12, 0xf1, 0xd7, 0x5a, 0x67, 0xd9, 0x16, 0x45, 0x28, 0xdd, 0x61, 0x55, 0x55, 0xaf, 0x23, 0x91, 0xd6, 0x0a, 0x3a, 0x42, 0x81, 0x18, 0xb4, 0xf7, 0xf3, 0x04,
0x78, 0x96, 0x5d, 0x92, 0x92, 0xb0, 0x47, 0xac, 0x8f, 0x5b, 0x6d, 0xdc, 0x1c, 0x41, 0x7e, 0xda, 0x6a, 0x55, 0x53, 0xaf, 0x20, 0xc8, 0xdc, 0x0a, 0x66, 0x43, 0xdd, 0x1c, 0xb2, 0xa5, 0xa4, 0x0c,
0x7e, 0x92, 0x5c, 0x93, 0x90, 0xed, 0x4a, 0xad, 0x8b, 0x07, 0x36, 0xd3, 0x10, 0x41, 0x78, 0x8f, 0x60, 0x08, 0x55, 0xa8, 0x26, 0xcf, 0xd0, 0x0f, 0x65, 0x11, 0x84, 0x45, 0xb1, 0xa0, 0xfa, 0x57,
0x79, 0x97, 0x0b, 0x90, 0x92, 0xb0, 0x44, 0xad, 0x8a, 0x0e, 0x60, 0xd9, 0x14, 0x11, 0x7e, 0x8d, 0x35, 0x5d, 0x5c, 0xfb, 0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0x43, 0x1d, 0x24, 0x8d, 0x61, 0x09, 0x54, 0xab, 0x27, 0x9a, 0xd3, 0x58, 0x60, 0x16, 0x84, 0x4f, 0xb3, 0xa4, 0xf3, 0x0d,
0x25, 0x93, 0x08, 0xc0, 0x9a, 0xbd, 0x10, 0xa2, 0xd6, 0x09, 0x60, 0x8f, 0x11, 0x1d, 0x7a, 0x8f, 0x63, 0x0b, 0x5d, 0xf2, 0x21, 0xec, 0xd7, 0x08, 0x62, 0x40, 0x84, 0x49, 0xb0, 0xad, 0xf2, 0x07,
0x29, 0xc3, 0x0c, 0x96, 0x96, 0xeb, 0x10, 0xa0, 0xda, 0x59, 0x32, 0xd3, 0x17, 0x41, 0x25, 0xdc, 0x63, 0x08, 0x04, 0xae, 0x77, 0xcb, 0x84, 0x5a, 0x60, 0x4d, 0xdd, 0x45, 0xb5, 0xf4, 0xa0, 0x05
};
private readonly byte[] _HiddenKeys17_1 = new byte[] // rb4
{
0x4c, 0x22, 0xd9, 0x28, 0xa6, 0x23, 0x01, 0x62, 0x0a, 0x84, 0x86, 0x27, 0xbb, 0xcc, 0x88, 0x9e, 0x33, 0x3a, 0x6b, 0x23, 0x92, 0x22, 0xa2, 0xb4, 0x81, 0x64, 0x4e, 0x8d, 0x25, 0x69, 0x9f, 0xdc,
0x64, 0xf1, 0x5f, 0x54, 0xca, 0x70, 0xb8, 0x8b, 0xf8, 0xaa, 0x2a, 0xd3, 0xd9, 0xec, 0x3b, 0x49, 0xe8, 0x0a, 0x3e, 0xe3, 0x46, 0xb1, 0xbf, 0x27, 0x1b, 0x6c, 0x76, 0x11, 0xc8, 0x35, 0x7a, 0xb4,
0x74, 0xf7, 0x42, 0xa5, 0xf1, 0xc7, 0x56, 0x2d, 0x31, 0xe1, 0x73, 0xf9, 0x96, 0x93, 0x89, 0x85, 0xa7, 0xac, 0x34, 0x46, 0x68, 0xd0, 0xbd, 0x6e, 0x08, 0xff, 0x5e, 0x8a, 0xae, 0x93, 0xa2, 0xdb,
0x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f,
0x35, 0x81, 0x86, 0xc9, 0x42, 0xcb, 0x1b, 0x2b, 0x87, 0x32, 0xae, 0x98, 0x73, 0x8e, 0xce, 0x02, 0xa7, 0x88, 0x2c, 0xbe, 0xfa, 0x54, 0x9d, 0x84, 0xbe, 0xc4, 0x0b, 0xff, 0xe6, 0xd9, 0x18, 0x2e,
0xca, 0x53, 0xb0, 0x5f, 0x14, 0x3a, 0x40, 0xb2, 0x5f, 0x8d, 0x5e, 0x10, 0x86, 0x0d, 0x63, 0xbd, 0xc7, 0x4b, 0x71, 0xd6, 0xff, 0xdd, 0x2d, 0x1f, 0xd9, 0x06, 0x20, 0xf6, 0xf8, 0x2f, 0x7d, 0x56,
0x40, 0x2f, 0x93, 0x66, 0x9b, 0xee, 0x29, 0x5c, 0x91, 0xcf, 0xa6, 0xad, 0x47, 0x63, 0x01, 0x87, 0x51, 0x6c, 0xe8, 0x29, 0x55, 0x68, 0x5e, 0x11, 0xc2, 0x48, 0x23, 0x96, 0x05, 0x78, 0xb3, 0xa1,
0x8f, 0xfb, 0x7e, 0xad, 0x69, 0x6a, 0x24, 0xcd, 0x03, 0x97, 0xca, 0xb8, 0x48, 0x39, 0xf6, 0xdd, 0x56, 0x80, 0x61, 0xe7, 0x66, 0xee, 0x5c, 0x55, 0xd1, 0x52, 0x57, 0xce, 0xd2, 0xc0, 0xbe, 0xc1
};
private readonly byte[] _HiddenKeys17_6 = new byte[] // dcvr
{
0x35, 0xb3, 0xda, 0x45, 0x95, 0xd2, 0x5c, 0x4e, 0x65, 0x01, 0x5f, 0x84, 0x61, 0x61, 0x6a, 0x08, 0xb0, 0x0d, 0x41, 0xd3, 0xa7, 0xf4, 0xb8, 0xa1, 0x78, 0x08, 0xe2, 0x75, 0x29, 0x1e, 0xfe, 0x8d,
0x18, 0x9a, 0x4c, 0x81, 0x2e, 0x8a, 0x6d, 0x40, 0x17, 0xec, 0x55, 0x1b, 0x4b, 0x39, 0x28, 0x84, 0x63, 0x69, 0xc3, 0x6b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2, 0x0d, 0x61, 0xbb, 0xa7, 0x54, 0x83, 0xac, 0x2e, 0xfa, 0xda, 0xee, 0xd4, 0xc4, 0x5a, 0x77, 0xce, 0xae, 0x03, 0x17, 0xb6,
0x44, 0x34, 0x3f, 0xa8, 0x66, 0x5d, 0x85, 0x17, 0xc1, 0xda, 0x8d, 0x26, 0xb3, 0x33, 0xba, 0x87, 0x57, 0x10, 0x6c, 0xb9, 0x7e, 0x43, 0xcb, 0x97, 0xfd, 0x2e, 0x48, 0xdc, 0x3d, 0xa4, 0xbf, 0x8a,
0xbb, 0x9a, 0x0e, 0x29, 0x7d, 0x8d, 0x17, 0x46, 0x08, 0x61, 0x8e, 0x72, 0xab, 0xef, 0x4b, 0x40, 0xc4, 0x93, 0x24, 0x03, 0x21, 0x54, 0x02, 0x97, 0xb5, 0x12, 0xab, 0x42, 0x4f, 0x23, 0x2a, 0x6f,
0x7b, 0xd5, 0x0c, 0x35, 0xe3, 0x62, 0xe4, 0x3b, 0xee, 0x23, 0x30, 0x9e, 0x61, 0x70, 0xbe, 0xbf, 0x8f, 0xa7, 0x4b, 0xed, 0x97, 0x3b, 0xd1, 0xcb, 0xdd, 0xd2, 0x0b, 0xe5, 0xe1, 0xb9, 0xe6, 0x52,
0x69, 0xa9, 0x4b, 0x0f, 0x1c, 0x58, 0xcb, 0x77, 0xe2, 0x12, 0xea, 0x94, 0xdf, 0x47, 0x3f, 0x53, 0x26, 0xba, 0x0e, 0x6e, 0x09, 0xc3, 0xb2, 0x22, 0x68, 0xdd, 0x4c, 0x5c, 0xfd, 0x66, 0x86, 0x73
};
private readonly byte[] _HiddenKeys17_8 = new byte[] // audica
{
0x9e, 0xdf, 0xa5, 0xbb, 0x02, 0xca, 0x0c, 0x2b, 0x51, 0x02, 0x1a, 0x35, 0x11, 0x62, 0x8a, 0x0f, 0x66, 0x31, 0x6e, 0x73, 0x0a, 0x68, 0x5f, 0x55, 0xe0, 0x51, 0x4f, 0x73, 0x50, 0x53, 0xb4, 0x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, 0xd0, 0x4d, 0x31, 0x68, 0x61, 0x56, 0x21,
0xdf, 0x60, 0xee, 0xdb, 0xc5, 0x55, 0x26, 0xc0, 0x0e, 0x3f, 0xa8, 0x4b, 0xd4, 0xb1, 0x54, 0x3f, 0x60, 0x93, 0xbf, 0xb3, 0x8a, 0x46, 0x79, 0x34, 0x36, 0xa9, 0x16, 0x9d, 0x20, 0xf7, 0xd3, 0x61,
0x92, 0x63, 0x1e, 0x54, 0xe4, 0xdf, 0x9b, 0x42, 0x32, 0xb4, 0xa8, 0x3d, 0x2e, 0x48, 0x3a, 0x96, 0x89, 0x0f, 0xcf, 0xaa, 0x22, 0x09, 0x1d, 0xd3, 0xf9, 0x28, 0x25, 0xce, 0x67, 0x57, 0xd6, 0xd0,
0xc1, 0x30, 0x1d, 0x91, 0xa1, 0xb7, 0x39, 0x1e, 0xe4, 0xd9, 0x08, 0x88, 0xcd, 0x19, 0x88, 0x09, 0xfc, 0xc1, 0x38, 0x59, 0x7c, 0x4b, 0xd7, 0xd9, 0xf5, 0x10, 0xa3, 0x9c, 0x1e, 0x5e, 0xf1, 0x30,
0x36, 0x00, 0x3f, 0x13, 0xa0, 0x7a, 0xb6, 0x02, 0x86, 0x4d, 0xc2, 0x70, 0x19, 0x1f, 0xd1, 0xd9, 0x8e, 0x0b, 0x64, 0x4a, 0xf2, 0xc6, 0xeb, 0xb5, 0x1c, 0x14, 0x6c, 0xc0, 0x54, 0xd3, 0x69, 0x5c,
0x00, 0xb1, 0xa8, 0x7f, 0xa2, 0x91, 0xad, 0x8e, 0x08, 0xf6, 0xc9, 0x03, 0x71, 0xa9, 0x74, 0x64, 0x66, 0xde, 0x4e, 0x02, 0x08, 0x35, 0x39, 0x40, 0x9c, 0x75, 0x10, 0x0d, 0x9d, 0x61, 0x7f, 0x63
};
private readonly byte[] _HiddenKeys17_10 = new byte[] // fuser
{
0xfe, 0x0e, 0x46, 0xa5, 0x59, 0x14, 0x7c, 0x30, 0xb4, 0x6a, 0x42, 0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x01, 0x36, 0xf4, 0x39
};
// These are here more for documentation than anything as the method will run the derivations regardless, but will enable detection of these moggs so the caller can display appropriate UI
private readonly byte[] _C3v12BadPs3Mask = new byte[16] { 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x2d, 0x74, 0x6f, 0x6f, 0x6c, 0x73, 0x2d, 0x62 };
private readonly byte[] _C3v13BadPs3Mask = new byte[16] { 0xc3, 0xc3, 0xc3, 0xc3, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b };
private readonly byte[] _C3v12FixedPs3Mask = new byte[16] { 0xf1, 0xb4, 0xb8, 0xb0, 0x48, 0xaf, 0xcb, 0x9b, 0x4b, 0x53, 0xe0, 0x56, 0x64, 0x57, 0x68, 0x39 };
private readonly byte[] _C3v13FixedPs3Mask = new byte[16] { 0xa5, 0xce, 0xfd, 0x06, 0x11, 0x93, 0x23, 0x21, 0xf8, 0x87, 0x85, 0xea, 0x95, 0xe4, 0x94, 0xd4 };
private readonly byte[] _C3v11Nonce = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x63, 0x33, 0x2d, 0x63, 0x75, 0x73, 0x74, 0x6F, 0x6D, 0x73, 0x31, 0x34 };
public uint Version; // read from bytes 0-3 of the header
public uint OggOffset; // read from bytes 4-7 of the header
public uint HeaderBlockSize; // read from bytes 16-19 of the header
public uint NonceOffset; // calculated from 20+(HeaderBlockSize*8)
public uint MagicAOffset; // calculated from NonceOffset+16
public uint MagicBOffset; // calculated from NonceOffset+24
public uint Ps3MaskOffset; // calculated from NonceOffset+32
public uint XboxMaskOffset; // calculated from NonceOffset+48
public byte[] HvKey = new byte[16]; // used to store the needed hvkey
public uint KeyIndexOffset; // calculated from NonceOffset+64 if v12-v16, NonceOffset+72 if v17
public uint V17KeysetOffset; // calculated from NonceOffset+64
public ulong V17Keyset; // read from the eight bytes at V17KeysetOffset, *only* if Version is 17
public byte[] MagicA = new byte[4]; // this is used to xor a specific offset in the decrypted audio as a form of obfuscation
public byte[] MagicB = new byte[4]; // this is used to xor a different specific offset in the decrypted audio
public uint Ps3Index; // this is the key index into the _HiddenKeys array as read from the header, modulo 6
public uint XboxIndex; // this is Ps3Index + 6
public byte[] XboxAesKey = new byte[16]; // this will hold the final derived xbox key
public byte[] Ps3AesKey = new byte[16]; // this will hold the final derived ps3 key
public byte[] Nonce = new byte[16]; // normally used as read, this is the IV for the AES CTR encryption so we just document it
public byte[] Ps3Mask = new byte[16]; // used directly, no encryption
public byte[] XboxMask = new byte[16]; // as read from the header, this is encrypted with the appropriate _HvKey
public byte[] XboxMaskDec = new byte[16]; // decrypted from XboxMask
public byte[] Ps3GrindArrayResult = new byte[16]; // this is kept so we can xor it with the xbox key to get the correct ps3 keymask
public byte[] Ps3FixedMask = new byte[16]; // used only when XboxAesKey and Ps3AesKey don't match, is XboxAesKey XOR Ps3GrindArrayResult
public bool KeymaskMismatch = false; // this will be set to true if the keys don't match, so the caller knows a patch is needed
public bool IsC3Mogg = false; // this will be set to true if the appropriate conditions are met for a mogg to be of C3 origin
private byte AsciiDigitToHex(byte h)
{
if ((h < 0x61) || (0x66 < h))
{
if ((h < 0x41) || (0x46 < h))
{
return (byte)(h - 0x30);
}
else
{
return (byte)(h - 0x37);
}
}
else
{
return (byte)(h + 0xa9);
}
}
private byte[] HexStringToBytes(byte[] s)
{
for (int i = 0; i < 16; i++)
{
byte lo = AsciiDigitToHex(s[i * 2 + 1]);
byte hi = AsciiDigitToHex(s[i * 2]);
s[i] = (byte)((lo + (hi * 16)) & 0xff);
}
return s;
}
private static uint Lcg(uint x)
{
return ((x * 0x19660d) + 0x3c6ef35f) & 0xffffffff;
}
private static byte RotL(byte x, byte n)
{
return (byte)((x << (n & 31) | x >> (8 - n & 31)) & 255);
}
private static byte RotR(byte x, byte n)
{
return (byte)((x >> (n & 31) | x << (8 - n & 31)) & 255);
}
private static byte Onot(byte x)
{
if (x == 0)
{ return 1; }
else
{ return 0; }
}
/* private static byte Op(byte a1, byte a2, int op)
{
byte num;
object obj;
int num1 = 0;
switch (op)
{
case 0:
{
num1 = a2 + RotR(a1, (byte)(a2 == 0 ? 1 : 0));
break;
}
case 1:
{
num1 = a2 + RotR(a1, 3);
break;
}
case 2:
{
num1 = a2 + RotL(a1, 1);
break;
}
case 3:
{
num1 = a2 ^ (a1 >> (a2 & 7 & 31) | (byte)(a1 << (-a2 & 7 & 31)));
break;
}
case 4:
{
num1 = a2 ^ RotL(a1, 4);
break;
}
case 5:
{
num = RotR(a1, 3);
num1 = a2 + (a2 ^ num);
break;
}
case 6:
{
num1 = a2 + RotL(a1, 2);
break;
}
case 7:
{
num1 = a2 + (a1 == 0 ? 1 : 0);
break;
}
case 8:
{
num1 = a2 ^ RotR(a1, (byte)(a2 == 0 ? 1 : 0));
break;
}
case 9:
{
num = RotL(a1, 3);
num1 = a2 ^ a2 + num;
break;
}
case 10:
{
num1 = a2 + RotL(a1, 3);
break;
}
case 11:
{
num1 = a2 + RotL(a1, 4);
break;
}
case 12:
{
num1 = a1 ^ a2;
break;
}
case 13:
{
num1 = a2 ^ (a1 == 0 ? 1 : 0);
break;
}
case 14:
{
num = RotR(a1, 3);
num1 = a2 ^ a2 + num;
break;
}
case 15:
{
num1 = a2 ^ RotL(a1, 3);
break;
}
case 16:
{
num1 = a2 ^ RotL(a1, 2);
break;
}
case 17:
{
num = RotL(a1, 3);
num1 = a2 + (a2 ^ num);
break;
}
case 18:
{
num1 = a2 + (a1 ^ a2);
break;
}
case 19:
{
num1 = a1 + a2;
break;
}
case 20:
{
num1 = a2 ^ RotR(a1, 3);
break;
}
case 21:
{
num1 = a2 ^ a1 + a2;
break;
}
case 22:
{
num1 = RotR(a1, (byte)(a2 == 0 ? 1 : 0));
break;
}
case 23:
{
num1 = a2 + RotR(a1, 1);
break;
}
case 24:
{
num1 = a1 >> (a2 & 7 & 31) | a1 << (-a2 & 7 & 31);
break;
}
case 25:
{
if (a1 == 0)
{
obj = (a2 == 0 ? 128 : 1);
}
else
{
obj = 0; // was null as we got it, but caused crashes, setting to 0 fixed
}
num1 = (byte)(int)obj; // num1 is int, but max cast the value of obj to a byte, so I am too
break;
}
case 26:
{
num1 = a2 + RotR(a1, 2);
break;
}
case 27:
{
num1 = a2 ^ RotR(a1, 1);
break;
}
case 28:
{
a1 = (byte)(~a1);
goto case 24;
}
case 29:
{
num1 = a2 ^ RotR(a1, 2);
break;
}
case 30:
{
num1 = a2 + (a1 >> (a2 & 7 & 31) | (byte)(a1 << (-a2 & 7 & 31)));
break;
}
case 31:
{
num1 = a2 ^ RotL(a1, 1);
break;
}
case 32:
{
num1 = (byte)((a1 << 8 | 170 | a1 ^ 255) >> 4) ^ a2;
break;
}
case 33:
{
num1 = (byte)((a1 ^ 255 | a1 << 8) >> 3 ^ a2);
break;
}
case 34:
{
num1 = (byte)((a1 << 8 ^ 65280 | a1) >> 2 ^ a2);
break;
}
case 35:
{
num1 = (byte)((a1 ^ 92 | a1 << 8) >> 5 ^ a2);
break;
}
case 36:
{
num1 = (byte)((a1 << 8 | 101 | a1 ^ 60) >> 2 ^ a2);
break;
}
case 37:
{
num1 = (byte)((a1 ^ 54 | a1 << 8) >> 2 ^ a2);
break;
}
case 38:
{
num1 = (byte)((a1 ^ 54 | a1 << 8) >> 4 ^ a2);
break;
}
case 39:
{
num1 = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 1 ^ a2);
break;
}
case 40:
{
num1 = (byte)((a1 ^ 255 | a1 << 8) >> 5 ^ a2);
break;
}
case 41:
{
num1 = (byte)((~a1 << 8 | a1) >> 6 ^ a2);
break;
}
case 42:
{
num1 = (byte)((a1 ^ 92 | a1 << 8) >> 3 ^ a2);
break;
}
case 43:
{
num1 = (byte)((a1 ^ 60 | 101 | a1 << 8) >> 5 ^ a2);
break;
}
case 44:
{
num1 = (byte)((a1 ^ 54 | a1 << 8) >> 1 ^ a2);
break;
}
case 45:
{
num1 = (byte)((a1 ^ 101 | a1 << 8 | 60) >> 6 ^ a2);
break;
}
case 46:
{
num1 = (byte)((a1 ^ 92 | a1 << 8) >> 2 ^ a2);
break;
}
case 47:
{
num1 = (byte)((a2 ^ 170 | a2 << 8 | 255) >> 3 ^ a1);
break;
}
case 48:
{
num1 = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 6 ^ a2);
break;
}
case 49:
{
num1 = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 7 ^ a2);
break;
}
case 50:
{
num1 = (byte)((a1 ^ 92 | a1 << 8) >> 6 ^ a2);
break;
}
case 51:
{
num1 = (byte)((a1 << 8 ^ 65280 | a1) >> 3 ^ a2);
break;
}
case 52:
{
num1 = (byte)((a1 ^ 255 | a1 << 8) >> 6 ^ a2);
break;
}
case 53:
{
num1 = (byte)((a1 << 8 ^ 65280 | a1) >> 5 ^ a2);
break;
}
case 54:
{
num1 = (byte)((a1 ^ 60 | 101 | a1 << 8) >> 4 ^ a2);
break;
}
case 55:
{
num1 = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 3 ^ a2);
break;
}
case 56:
{
num1 = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 5 ^ a2);
break;
}
case 57:
{
num1 = (byte)((a1 ^ 175 | a1 << 8 | 250) >> 5 ^ a2);
break;
}
case 58:
{
num1 = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 5 ^ a2);
break;
}
case 59:
{
num1 = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 3 ^ a2);
break;
}
case 60:
{
num1 = (byte)((a1 ^ 54 | a1 << 8) >> 3 ^ a2);
break;
}
case 61:
{
num1 = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 4 ^ a2);
break;
}
case 62:
{
num1 = (byte)((a1 ^ 255 | a1 << 8 | 175) >> 6 ^ a2);
break;
}
case 63:
{
num1 = (byte)((a1 ^ 255 | a1 << 8) >> 2 ^ a2);
break;
}
}
return (byte)(num1 & 255);
}*/
private static byte Op(byte a1, byte a2, int op)
{
byte ret = 0;
switch (op)
{
case 0:
{
ret = (byte)(a2 + RotR(a1, Onot(a2)));
break;
}
case 1:
{
ret = (byte)(a2 + RotR(a1, 3));
break;
}
case 2:
{
ret = (byte)(a2 + RotL(a1, 1));
break;
}
case 3:
{
ret = (byte)(a2 ^ (a1 >> (a2 & 7 & 31) | (a1 << (-a2 & 7 & 31))));
break;
}
case 4:
{
ret = (byte)(a2 ^ RotL(a1, 4));
break;
}
case 5:
{
ret = (byte)(a2 + (a2 ^ RotR(a1, 3)));
break;
}
case 6:
{
ret = (byte)(a2 + RotL(a1, 2));
break;
}
case 7:
{
ret = (byte)(a2 + Onot(a1));
break;
}
case 8:
{
ret = (byte)(a2 ^ RotR(a1, Onot(a2)));
break;
}
case 9:
{
ret = (byte)(a2 ^ (a2 + RotL(a1, 3)));
break;
}
case 10:
{
ret = (byte)(a2 + RotL(a1, 3));
break;
}
case 11:
{
ret = (byte)(a2 + RotL(a1, 4));
break;
}
case 12:
{
ret = (byte)(a1 ^ a2);
break;
}
case 13:
{
ret = (byte)(a2 ^ Onot(a1));
break;
}
case 14:
{
ret = (byte)(a2 ^ (a2 + RotR(a1, 3)));
break;
}
case 15:
{
ret = (byte)(a2 ^ RotL(a1, 3));
break;
}
case 16:
{
ret = (byte)(a2 ^ RotL(a1, 2));
break;
}
case 17:
{
ret = (byte)(a2 + (a2 ^ RotL(a1, 3)));
break;
}
case 18:
{
ret = (byte)(a2 + (a1 ^ a2));
break;
}
case 19:
{
ret = (byte)(a1 + a2);
break;
}
case 20:
{
ret = (byte)(a2 ^ RotR(a1, 3));
break;
}
case 21:
{
ret = (byte)(a2 ^ (a1 + a2));
break;
}
case 22:
{
ret = (byte)(RotR(a1, Onot(a2)));
break;
}
case 23:
{
ret = (byte)(a2 + RotR(a1, 1));
break;
}
case 24:
{
ret = (byte)(a1 >> (a2 & 7 & 31) | a1 << (-a2 & 7 & 31));
break;
}
case 25:
{
if (a1 == 0)
if (a2 == 0)
ret = 128;
else
ret = 1;
else
ret = 0;
break;
}
case 26:
{
ret = (byte)(a2 + RotR(a1, 2));
break;
}
case 27:
{
ret = (byte)(a2 ^ RotR(a1, 1));
break;
}
case 28:
{
ret = Op((byte)((~a1)&0xff), a2, 24);
break;
}
case 29:
{
ret = (byte)(a2 ^ RotR(a1, 2));
break;
}
case 30:
{
ret = (byte)(a2 + (a1 >> (a2 & 7 & 31) | (a1 << (-a2 & 7 & 31))));
break;
}
case 31:
{
ret = (byte)(a2 ^ RotL(a1, 1));
break;
}
case 32:
{
ret = (byte)(((a1 << 8 | 170 | a1 ^ 255) >> 4) ^ a2);
break;
}
case 33:
{
ret = (byte)((a1 ^ 255 | a1 << 8) >> 3 ^ a2);
break;
}
case 34:
{
ret = (byte)((a1 << 8 ^ 65280 | a1) >> 2 ^ a2);
break;
}
case 35:
{
ret = (byte)((a1 ^ 92 | a1 << 8) >> 5 ^ a2);
break;
}
case 36:
{
ret = (byte)((a1 << 8 | 101 | a1 ^ 60) >> 2 ^ a2);
break;
}
case 37:
{
ret = (byte)((a1 ^ 54 | a1 << 8) >> 2 ^ a2);
break;
}
case 38:
{
ret = (byte)((a1 ^ 54 | a1 << 8) >> 4 ^ a2);
break;
}
case 39:
{
ret = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 1 ^ a2);
break;
}
case 40:
{
ret = (byte)((a1 ^ 255 | a1 << 8) >> 5 ^ a2);
break;
}
case 41:
{
ret = (byte)((~a1 << 8 | a1) >> 6 ^ a2);
break;
}
case 42:
{
ret = (byte)((a1 ^ 92 | a1 << 8) >> 3 ^ a2);
break;
}
case 43:
{
ret = (byte)((a1 ^ 60 | 101 | a1 << 8) >> 5 ^ a2);
break;
}
case 44:
{
ret = (byte)((a1 ^ 54 | a1 << 8) >> 1 ^ a2);
break;
}
case 45:
{
ret = (byte)((a1 ^ 101 | a1 << 8 | 60) >> 6 ^ a2);
break;
}
case 46:
{
ret = (byte)((a1 ^ 92 | a1 << 8) >> 2 ^ a2);
break;
}
case 47:
{
ret = (byte)((a2 ^ 170 | a2 << 8 | 255) >> 3 ^ a1);
break;
}
case 48:
{
ret = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 6 ^ a2);
break;
}
case 49:
{
ret = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 7 ^ a2);
break;
}
case 50:
{
ret = (byte)((a1 ^ 92 | a1 << 8) >> 6 ^ a2);
break;
}
case 51:
{
ret = (byte)((a1 << 8 ^ 65280 | a1) >> 3 ^ a2);
break;
}
case 52:
{
ret = (byte)((a1 ^ 255 | a1 << 8) >> 6 ^ a2);
break;
}
case 53:
{
ret = (byte)((a1 << 8 ^ 65280 | a1) >> 5 ^ a2);
break;
}
case 54:
{
ret = (byte)((a1 ^ 60 | 101 | a1 << 8) >> 4 ^ a2);
break;
}
case 55:
{
ret = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 3 ^ a2);
break;
}
case 56:
{
ret = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 5 ^ a2);
break;
}
case 57:
{
ret = (byte)((a1 ^ 175 | a1 << 8 | 250) >> 5 ^ a2);
break;
}
case 58:
{
ret = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 5 ^ a2);
break;
}
case 59:
{
ret = (byte)((a1 ^ 92 | a1 << 8 | 54) >> 3 ^ a2);
break;
}
case 60:
{
ret = (byte)((a1 ^ 54 | a1 << 8) >> 3 ^ a2);
break;
}
case 61:
{
ret = (byte)((a1 ^ 99 | a1 << 8 | 92) >> 4 ^ a2);
break;
}
case 62:
{
ret = (byte)((a1 ^ 255 | a1 << 8 | 175) >> 6 ^ a2);
break;
}
case 63:
{
ret = (byte)((a1 ^ 255 | a1 << 8) >> 2 ^ a2);
break;
}
}
return (byte)(ret & 0xff);
}
private byte[] GrindArray(byte[] key)
{
int i;
uint num;
byte[] numArray = new byte[64];
byte[] numArray1 = new byte[64];
uint magicA = BitConverter.ToUInt32(MagicA, 0);
uint magicB = BitConverter.ToUInt32(MagicB, 0);
uint num1 = magicA;
uint num2 = magicB;
int[] numArray2 = new int[256];
for (i = 0; i < 0x100; i++) // hashTo5Bits? {ma %d 2}
{
numArray2[i] = (byte)((byte)magicA >> 3);
magicA = Lcg(magicA);
}
if (magicB == 0)
{
magicB = 0x303f;
}
for (i = 0; i < 0x20; i++)
{
do
{
magicB = Lcg(magicB);
num = magicB >> 2 & 0x1f;
}
while (numArray[num] != 0);
numArray1[i] = (byte)num;
numArray[num] = 1;
}
int[] numArray3 = numArray2;
int[] numArray4 = new int[256];
magicA = num2;
for (i = 0; i < 256; i++)
{
numArray4[i] = (byte)((byte)magicA >> 2 & 0x3f);
magicA = Lcg(magicA);
}
if (Version > 13)
{
for (i = 32; i < 64; i++)
{
do
{
num1 = Lcg(num1);
num = (num1 >> 2 & 0x1f) + 0x20;
}
while (numArray[num] != 0);
numArray1[i] = (byte)num;
numArray[num] = 1;
}
numArray3 = numArray4;
}
for (int j = 0; j < 16; j++)
{
byte num3 = key[j];
for (int k = 0; k < 16; k += 2)
{
num3 = Op(num3, key[k + 1], numArray1[numArray3[key[k]]]);
}
key[j] = num3;
}
return key;
}
/* private static byte[] GrindArray(uint magicA, uint magicB, byte[] key, int version)
{
int i;
uint num;
byte[] numArray = new byte[64];
byte[] numArray1 = new byte[64];
uint num1 = magicA;
uint num2 = magicB;
int[] numArray2 = new int[256];
for (i = 0; i < 0x100; i++) // hashTo5Bits? {ma %d 2}
{