-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMCE.py
1978 lines (1518 loc) · 86.2 KB
/
MCE.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
#!/usr/bin/env python3
#coding=utf-8
"""
MC Extractor
Intel, AMD, VIA & Freescale Microcode Extractor
Copyright (C) 2016-2023 Plato Mavropoulos
"""
title = 'MC Extractor v1.78.2'
import sys
# Detect Python version
sys_py = sys.version_info
if sys_py < (3,7) :
sys.stdout.write('%s\n\nError: Python >= 3.7 required, not %d.%d!\n' % (title, sys_py[0], sys_py[1]))
if '-exit' not in sys.argv : (raw_input if sys_py[0] <= 2 else input)('\nPress enter to exit') # pylint: disable=E0602
sys.exit(-1)
# Detect OS platform
sys_os = sys.platform
if sys_os == 'win32' :
cl_wipe = 'cls'
sys.stdout.reconfigure(encoding='utf-8') # Fix Windows Unicode console redirection
elif sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1 :
cl_wipe = 'clear'
else :
print('%s\n\nError: Unsupported platform "%s"!\n' % (title, sys_os))
if '-exit' not in sys.argv : input('Press enter to exit')
sys.exit(-1)
import os
import re
import zlib
import struct
import shutil
import ctypes
import inspect
import sqlite3
import threading
import traceback
import urllib.request
import importlib.util
# Check code dependency installation
for depend in ['colorama','pltable'] :
if not importlib.util.find_spec(depend) :
print('%s\n\nError: Dependency "%s" is missing!\n Install via "pip3 install %s"\n' % (title, depend, depend))
if '-exit' not in sys.argv : input('Press enter to exit')
sys.exit(1)
import pltable
import colorama
# Initialize and setup Colorama
colorama.init()
col_r = colorama.Fore.RED + colorama.Style.BRIGHT
col_c = colorama.Fore.CYAN + colorama.Style.BRIGHT
col_b = colorama.Fore.BLUE + colorama.Style.BRIGHT
col_g = colorama.Fore.GREEN + colorama.Style.BRIGHT
col_y = colorama.Fore.YELLOW + colorama.Style.BRIGHT
col_m = colorama.Fore.MAGENTA + colorama.Style.BRIGHT
col_e = colorama.Fore.RESET + colorama.Style.RESET_ALL
# Set ctypes Structure types
char = ctypes.c_char
uint8_t = ctypes.c_ubyte
uint16_t = ctypes.c_ushort
uint32_t = ctypes.c_uint
uint64_t = ctypes.c_uint64
def mce_help() :
print(
'\nUsage: MCE [FilePath] {Options}\n\n{Options}\n\n'
'-? : Displays help & usage screen\n'
'-skip : Skips welcome & options screen\n'
'-exit : Skips Press enter to exit prompt\n'
'-mass : Scans all files of a given directory\n'
'-info : Displays microcode structure info\n'
'-add : Adds input microcode to DB, if new\n'
'-dbn : Renames input file based on unique DB name\n'
'-duc : Disables automatic check for MCE & DB updates\n'
'-search : Searches for microcodes based on CPUID/Model\n'
'-last : Shows \"Last\" status based on user input\n'
'-repo : Builds microcode repositories from input\n'
'-blob : Builds a Microcode Blob (MCB) from input'
)
print(col_g + '\nCopyright (C) 2016-2023 Plato Mavropoulos' + col_e)
if getattr(sys, 'frozen', False) : print(col_c + '\nRunning in frozen state!' + col_e)
mce_exit(0)
class MCE_Param :
def __init__(self, sys_os, source) :
self.val = ['-?','-skip','-info','-add','-mass','-search','-dbn','-repo','-exit','-blob','-last','-duc']
if sys_os == 'win32' : self.val.extend(['-ubu']) # Windows only
self.help_scr = False
self.build_db = False
self.skip_intro = False
self.print_hdr = False
self.mass_scan = False
self.search = False
self.give_db_name = False
self.build_repo = False
self.mce_ubu = False
self.skip_pause = False
self.build_blob = False
self.get_last = False
self.upd_dis = False
if '-?' in source : self.help_scr = True
if '-skip' in source : self.skip_intro = True
if '-add' in source : self.build_db = True
if '-info' in source : self.print_hdr = True
if '-mass' in source : self.mass_scan = True
if '-search' in source : self.search = True
if '-dbn' in source : self.give_db_name = True
if '-repo' in source : self.build_repo = True
if '-exit' in source : self.skip_pause = True
if '-blob' in source : self.build_blob = True
if '-last' in source : self.get_last = True
if '-duc' in source : self.upd_dis = True
if '-ubu' in source : self.mce_ubu = True # Hidden
if self.mass_scan or self.search or self.build_repo or self.build_blob or self.get_last : self.skip_intro = True
# https://stackoverflow.com/a/65447493 by Shail-Shouryya
class Thread_With_Result(threading.Thread) :
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None) :
self.result = None
if kwargs is None : kwargs = {}
def function() :
self.result = target(*args, **kwargs)
super().__init__(group=group, target=function, name=name, daemon=daemon)
class Intel_MC_Header(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('HeaderVersion', uint32_t), # 0x00 00000001
('UpdateRevision', uint32_t), # 0x04 Signed to signify PRD/PRE
('Year', uint16_t), # 0x08
('Day', uint8_t), # 0x0A
('Month', uint8_t), # 0x0B
('ProcessorSignature', uint32_t), # 0x0C
('Checksum', uint32_t), # 0x10 OEM validation only
('LoaderRevision', uint32_t), # 0x14 00000001
('PlatformIDs', uint8_t), # 0x18 Supported Platforms
('Reserved0', uint8_t*3), # 0x19 00 * 3
('DataSize', uint32_t), # 0x1C Extra + Patch
('TotalSize', uint32_t), # 0x20 Header + Extra + Patch + Extended
('Reserved1', uint32_t*3), # 0x24 00 * 12
# 0x30
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_b + 'Intel Header Main' + col_e
pt.add_row(['Header Version', self.HeaderVersion])
pt.add_row(['Update Version', '%X' % self.UpdateRevision])
pt.add_row(['Date', '%0.4X-%0.2X-%0.2X' % (self.Year, self.Month, self.Day)])
pt.add_row(['CPUID', '%0.5X' % self.ProcessorSignature])
pt.add_row(['Checksum', '%0.8X' % self.Checksum])
pt.add_row(['Loader Version', self.LoaderRevision])
pt.add_row(['Platform', '%0.2X (%s)' % (self.PlatformIDs, ','.join(map(str, intel_plat(mc_hdr.PlatformIDs))))])
pt.add_row(['Reserved 0', '0x%X' % int.from_bytes(self.Reserved0, 'little')])
pt.add_row(['Data Size', '0x%X' % self.DataSize])
pt.add_row(['Total Size', '0x%X' % self.TotalSize])
pt.add_row(['Reserved 1', '0x%X' % int.from_bytes(self.Reserved1, 'little')])
print(pt)
class IntelMicrocodeHeaderExtraBase(ctypes.LittleEndianStructure):
_pack_ = 1
_fields_ = [
('ModuleType', uint16_t), # 0x00 0000 (always)
('ModuleSubType', uint16_t), # 0x02 0000 (always)
('ModuleSize', uint32_t), # 0x04 dwords
('Flags', uint16_t), # 0x08 0 RSA Signed, 1-31 Reserved
('RSAKeySize', uint16_t), # 0x0A 1K multiple (e.g. 3 * 1024 = 3072)
('UpdateRevision', uint32_t), # 0x0C Signed to signify PRD/PRE
('VCN', uint32_t), # 0x10 Version Control Number
('MultiPurpose1', uint32_t), # 0x14 dwords from Extra, UpdateSize, Empty etc
('Day', uint8_t), # 0x18
('Month', uint8_t), # 0x19
('Year', uint16_t), # 0x1A
('UpdateSize', uint32_t), # 0x1C dwords from Extra without encrypted padding
('ProcessorSignatureCount', uint32_t), # 0x20 max is 8 (8 * 0x4 = 0x20)
('ProcessorSignature0', uint32_t), # 0x24
('ProcessorSignature1', uint32_t), # 0x28
('ProcessorSignature2', uint32_t), # 0x2C
('ProcessorSignature3', uint32_t), # 0x30
('ProcessorSignature4', uint32_t), # 0x34
('ProcessorSignature5', uint32_t), # 0x38
('ProcessorSignature6', uint32_t), # 0x3C
('ProcessorSignature7', uint32_t), # 0x40
('MultiPurpose2', uint32_t), # 0x44 dwords from Extra + encrypted padding, UpdateSize, Platform, Empty
('SVN', uint32_t), # 0x48 Security Version Number
('Unknown0', uint32_t), # 0x4C
('Unknown1', uint32_t), # 0x50
('Unknown2', uint32_t), # 0x54
('Unknown3', uint32_t), # 0x58
('Unknown4', uint32_t), # 0x5C
('Unknown5', uint32_t*8), # 0x60
# 0x80 (parent class, base)
]
def _get_rsa(self, rsa_mod, rsa_sig, rsa_exp, rsa_len):
self.rsa_exp = rsa_exp
self.rsa_mod = '%0.*X' % (rsa_len * 2, int.from_bytes(rsa_mod, 'little'))
self.rsa_sig = '%0.*X' % (rsa_len * 2, int.from_bytes(rsa_sig, 'little'))
def get_flags(self):
flags = IntelMicrocodeHeaderExtraGetFlags()
flags.asbytes = self.Flags
return flags.b.RSASigned, flags.b.Reserved
def get_cpuids(self):
return (self.ProcessorSignature0,self.ProcessorSignature1,self.ProcessorSignature2,self.ProcessorSignature3,
self.ProcessorSignature4,self.ProcessorSignature5,self.ProcessorSignature6,self.ProcessorSignature7)
def mc_print(self):
self.f1,self.f2 = self.get_flags()
self.cpuids = self.get_cpuids()
self.unknown5 = '%0.*X' % (0x20 * 2, int.from_bytes(self.Unknown5, 'little'))
pt,_ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_b + 'Intel Header Extra' + col_e
pt.add_row(['Module Type', self.ModuleType])
pt.add_row(['Module Sub Type', self.ModuleSubType])
pt.add_row(['Module Size', '0x%X' % (self.ModuleSize * 4)])
pt.add_row(['RSA Signed', ['No','Yes'][self.f1]])
pt.add_row(['Flags Reserved', '{0:07b}b'.format(self.f2)])
pt.add_row(['RSA Key Size', self.RSAKeySize * 1024])
pt.add_row(['Update Version', '%X' % self.UpdateRevision])
pt.add_row(['Version Control Number', self.VCN])
if self.MultiPurpose1 == mc_hdr.PlatformIDs:
pt.add_row(['Platform (MP1)', '%0.2X (%s)' % (self.MultiPurpose1, ','.join(map(str, intel_plat(mc_hdr.PlatformIDs))))])
elif self.MultiPurpose1 * 4 == self.UpdateSize * 4:
pt.add_row(['Update Size (MP1)', '0x%X' % (self.MultiPurpose1 * 4)])
elif self.MultiPurpose1 * 4 == mc_len - 0x30:
pt.add_row(['Padded Size (MP1)', '0x%X' % (self.MultiPurpose1 * 4)])
else:
pt.add_row(['Multi Purpose 1', '0x%X' % self.MultiPurpose1])
pt.add_row(['Date', '%0.4X-%0.2X-%0.2X' % (self.Year, self.Month, self.Day)])
pt.add_row(['Update Size', '0x%X' % (self.UpdateSize * 4)])
pt.add_row(['CPU Signatures', self.ProcessorSignatureCount])
any(pt.add_row(['CPUID %d' % i, '%0.5X' % self.cpuids[i]]) for i in range(len(self.cpuids)) if self.cpuids[i] != 0)
if self.MultiPurpose2 == mc_hdr.PlatformIDs:
pt.add_row(['Platform (MP2)', '%0.2X (%s)' % (self.MultiPurpose2, ','.join(map(str, intel_plat(mc_hdr.PlatformIDs))))])
elif self.MultiPurpose2 * 4 == self.UpdateSize * 4:
pt.add_row(['Update Size (MP2)', '0x%X' % (self.MultiPurpose2 * 4)])
elif self.MultiPurpose2 * 4 == mc_len - 0x30:
pt.add_row(['Padded Size (MP2)', '0x%X' % (self.MultiPurpose2 * 4)])
else:
pt.add_row(['Multi Purpose 2', '0x%X' % self.MultiPurpose2])
pt.add_row(['Security Version Number', self.SVN])
pt.add_row(['Unknown 0', '0x%X' % self.Unknown0])
pt.add_row(['Unknown 1', '0x%X' % self.Unknown1])
pt.add_row(['Unknown 2', '0x%X' % self.Unknown2])
pt.add_row(['Unknown 3', '0x%X' % self.Unknown3])
pt.add_row(['Unknown 4', '0x%X' % self.Unknown4])
pt.add_row(['Unknown 5', '%s [...]' % self.unknown5[:8]])
pt.add_row(['RSA Public Key', '%s [...]' % self.rsa_mod[:8]])
pt.add_row(['RSA Exponent', '0x%X' % self.rsa_exp])
pt.add_row(['RSA Signature', '%s [...]' % self.rsa_sig[:8]])
print()
print(pt)
class IntelMicrocodeHeaderExtraR1(IntelMicrocodeHeaderExtraBase):
_pack_ = 1
_fields_ = [
('RSAPublicKey', uint32_t*64), # 0x80
('RSAExponent', uint32_t), # 0x180 0x11 (17)
('RSASignature', uint32_t*64), # 0x184 0x14 --> SHA-1 or 0x20 --> SHA-256
# 0x204 (child class, R1)
]
def mc_print(self):
self._get_rsa(self.RSAPublicKey, self.RSASignature, self.RSAExponent, 0x100)
super().mc_print()
class IntelMicrocodeHeaderExtraR2(IntelMicrocodeHeaderExtraBase):
_pack_ = 1
_fields_ = [
('RSAPublicKey', uint32_t*96), # 0x80 Exponent is 0x10001 (65537)
('RSASignature', uint32_t*96), # 0x200 0x33 --> 0x13 = Unknown + 0x20 = SHA-256
# 0x300 (child class, R2)
]
def mc_print(self):
self._get_rsa(self.RSAPublicKey, self.RSASignature, 0x10001, 0x180)
super().mc_print()
class IntelMicrocodeHeaderExtraFlags(ctypes.LittleEndianStructure):
_fields_ = [
('RSASigned', uint16_t, 1), # RSA Signature usage
('Reserved', uint16_t, 7)
]
class IntelMicrocodeHeaderExtraGetFlags(ctypes.Union):
_fields_ = [
('b', IntelMicrocodeHeaderExtraFlags),
('asbytes', uint16_t)
]
class Intel_MC_Header_Extended(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('ExtendedSignatureCount', uint32_t), # 0x00
('ExtendedChecksum', uint32_t), # 0x04
('Reserved', uint32_t*3), # 0x08
# 0x14
]
def mc_print(self) :
print()
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_b + 'Intel Header Extended' + col_e
pt.add_row(['Extended Signatures', self.ExtendedSignatureCount])
pt.add_row(['Extended Checksum', '%0.8X' % self.ExtendedChecksum])
pt.add_row(['Reserved', '0x%X' % int.from_bytes(self.Reserved, 'little')])
print(pt)
class Intel_MC_Header_Extended_Field(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('ProcessorSignature', uint32_t), # 0x00
('PlatformIDs', uint32_t), # 0x04
('Checksum', uint32_t), # 0x08 replace CPUID, Platform, Checksum at Main Header w/o Extended
# 0x0C
]
def mc_print(self) :
print()
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_b + 'Intel Header Extended Field' + col_e
pt.add_row(['CPUID', '%0.5X' % self.ProcessorSignature])
pt.add_row(['Platform', '%0.2X %s' % (self.PlatformIDs, intel_plat(self.PlatformIDs))])
pt.add_row(['Checksum', '%0.8X' % self.Checksum])
print(pt)
class AMD_MC_Header(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('Year', uint16_t), # 0x00
('Day', uint8_t), # 0x02
('Month', uint8_t), # 0x03
('UpdateRevision', uint32_t), # 0x04
('LoaderID', uint16_t), # 0x08 00-05 80
('DataSize', uint8_t), # 0x0A 00 or 10 or 20 or 2nd byte of AM5 DataSize (?)
('InitializationFlag', uint8_t), # 0x0B 00 or 01 or 1st byte of AM5 DataSize (?)
('DataChecksum', uint32_t), # 0x0C OEM validation only
('NorthBridgeVEN_ID', uint16_t), # 0x10 0000 or 1022
('NorthBridgeDEV_ID', uint16_t), # 0x12
('SouthBridgeVEN_ID', uint16_t), # 0x14 0000 or 1022
('SouthBridgeDEV_ID', uint16_t), # 0x16
('ProcessorSignature', uint16_t), # 0x18
('NorthBridgeREV_ID', uint8_t), # 0x1A
('SouthBridgeREV_ID', uint8_t), # 0x1B
('BiosApiREV_ID', uint8_t), # 0x1C 00 or 01
('Reserved', uint8_t*3), # 0x1D 000000 or AAAAAA
# 0x20
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_r + 'AMD Header' + col_e
pt.add_row(['Date', '%0.4X-%0.2X-%0.2X' % (self.Year, self.Month, self.Day)])
pt.add_row(['Update Version', '%X' % self.UpdateRevision])
pt.add_row(['Loader ID', '0x%X' % self.LoaderID])
pt.add_row(['Data Size', '0x%X' % self.DataSize])
pt.add_row(['Initialization Flag', '0x%X' % self.InitializationFlag])
pt.add_row(['Checksum', '%0.8X' % self.DataChecksum])
pt.add_row(['NorthBridge Vendor ID', '0x%X' % self.NorthBridgeVEN_ID])
pt.add_row(['NorthBridge Device ID', '0x%X' % self.NorthBridgeDEV_ID])
pt.add_row(['SouthBridge Vendor ID', '0x%X' % self.SouthBridgeVEN_ID])
pt.add_row(['SouthBridge Device ID', '0x%X' % self.SouthBridgeDEV_ID])
pt.add_row(['CPUID', '%0.2X0F%0.2X' % (self.ProcessorSignature >> 8, self.ProcessorSignature & 0xFF)])
pt.add_row(['NorthBridge Revision', '0x%X' % self.NorthBridgeREV_ID])
pt.add_row(['SouthBridge Revision', '0x%X' % self.SouthBridgeREV_ID])
pt.add_row(['BIOS API Revision', '0x%X' % self.BiosApiREV_ID])
pt.add_row(['Reserved', '0x%X' % int.from_bytes(self.Reserved, 'little')])
print(pt)
class VIA_MC_Header(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('Signature', char*4), # 0x00 RRAS
('UpdateRevision', uint32_t), # 0x04
('Year', uint16_t), # 0x08
('Day', uint8_t), # 0x0A
('Month', uint8_t), # 0x0B
('ProcessorSignature', uint32_t), # 0x0C
('Checksum', uint32_t), # 0x10 OEM validation only
('LoaderRevision', uint32_t), # 0x14 00000001
('CNRRevision', uint8_t), # 0x18 0 CNR001 A0, 1 CNR001 A1
('Reserved', uint8_t*3), # 0x19 FF * 3
('DataSize', uint32_t), # 0x1C
('TotalSize', uint32_t), # 0x20
('Name', char*12), # 0x24
# 0x30
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_c + 'VIA Header' + col_e
pt.add_row(['Signature', self.Signature.decode('utf-8')])
pt.add_row(['Update Version', '%X' % self.UpdateRevision])
pt.add_row(['Date', '%0.4d-%0.2d-%0.2d' % (self.Year, self.Month, self.Day)])
pt.add_row(['CPUID', '%0.5X' % self.ProcessorSignature])
pt.add_row(['Checksum', '%0.8X' % self.Checksum])
pt.add_row(['Loader Version', self.LoaderRevision])
if self.CNRRevision != 0xFF :
pt.add_row(['CNR Revision', '001 A%d' % self.CNRRevision])
pt.add_row(['Reserved', '0x%X' % int.from_bytes(self.Reserved, 'little')])
else :
pt.add_row(['Reserved', '0xFFFFFFFF'])
pt.add_row(['Data Size', '0x%X' % self.DataSize])
pt.add_row(['Total Size', '0x%X' % self.TotalSize])
pt.add_row(['Name', self.Name.replace(b'\x7F',b'\x2E').decode('utf-8').strip()])
print(pt)
class FSL_MC_Header(ctypes.BigEndianStructure) :
_pack_ = 1
_fields_ = [
('TotalSize', uint32_t), # 0x00 Entire file
('Signature', char*3), # 0x04 QEF
('HeaderVersion', uint8_t), # 0x07 01
('Name', char*62), # 0x08 Null-terminated ID String
('IRAM', uint8_t), # 0x46 I-RAM (0 shared, 1 split)
('CountMC', uint8_t), # 0x47 Number of MC structures
('Model', uint16_t), # 0x48 SoC Model
('Major', uint8_t), # 0x4A SoC Revision Major
('Minor', uint8_t), # 0x4B SoC Revision Minor
('Reserved0', uint32_t), # 0x4C Alignment
('ExtendedModes', uint64_t), # 0x50 Extended Modes
('VTraps', uint32_t*8), # 0x58 Virtual Trap Addresses
('Reserved1', uint32_t), # 0x78 Alignment
# 0x7C
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_y + 'Freescale Header Main' + col_e
pt.add_row(['Signature', self.Signature.decode('utf-8')])
pt.add_row(['Name', self.Name.decode('utf-8')])
pt.add_row(['Header Version', self.HeaderVersion])
pt.add_row(['I-RAM', ['Shared','Split'][self.IRAM]])
pt.add_row(['Microcode Count', self.CountMC])
pt.add_row(['Total Size', '0x%X' % self.TotalSize])
pt.add_row(['SoC Model', '%0.4d' % self.Model])
pt.add_row(['SoC Major', self.Major])
pt.add_row(['SoC Minor', self.Minor])
pt.add_row(['Reserved 0', '0x%X' % self.Reserved0])
pt.add_row(['Extended Modes', '0x%X' % self.ExtendedModes])
pt.add_row(['Virtual Traps', '0x%X' % int.from_bytes(self.VTraps, 'little')])
pt.add_row(['Reserved 1', '0x%X' % self.Reserved1])
print(pt)
class FSL_MC_Entry(ctypes.BigEndianStructure) :
_pack_ = 1
_fields_ = [
('Name', char*32), # 0x00 Null-terminated ID String
('Traps', uint32_t*16), # 0x20 Trap Addresses (0 ignore)
('ECCR', uint32_t), # 0x60 ECCR Register value
('IRAMOffset', uint32_t), # 0x64 Code Offset into I-RAM
('CodeLength', uint32_t), # 0x68 dwords (*4, 1st Entry only)
('CodeOffset', uint32_t), # 0x6C MC Offset (from 0x0, 1st Entry only)
('Major', uint8_t), # 0x70 Major
('Minor', uint8_t), # 0x71 Minor
('Revision', uint8_t), # 0x72 Revision
('Reserved0', uint8_t), # 0x73 Alignment
('Reserved1', uint32_t), # 0x74 Future Expansion
# 0x78
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_y + 'Freescale Header Entry' + col_e
pt.add_row(['Name', self.Name.decode('utf-8')])
pt.add_row(['Traps', '0x%X' % int.from_bytes(self.Traps, 'little')])
pt.add_row(['ECCR', '0x%X' % self.ECCR])
pt.add_row(['I-RAM Offset', '0x%X' % self.IRAMOffset])
pt.add_row(['Code Length', '0x%X' % self.CodeLength])
pt.add_row(['Code Offset', '0x%X' % self.CodeOffset])
pt.add_row(['Major', self.Major])
pt.add_row(['Minor', self.Minor])
pt.add_row(['Revision', '0x%X' % self.Revision])
pt.add_row(['Reserved 0', '0x%X' % self.Reserved0])
pt.add_row(['Reserved 1', '0x%X' % self.Reserved1])
print(pt)
class MCB_Header(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('Tag', char*4), # 0x00 Microcode Blob Tag ($MCB)
('MCCount', uint16_t), # 0x04 Microcode Entry Count
('MCEDBRev', uint16_t), # 0x06 MCE DB Revision
('HeaderRev', uint8_t), # 0x08 MCB Header Revision (2)
('MCVendor', uint8_t), # 0x09 Microcode Vendor (0 Intel, 1 AMD)
('Reserved', char*2), # 0x0A Reserved ($$)
('Checksum', uint32_t), # 0x0C CRC-32 of Header + Entries + Data
# 0x10
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_y + 'Microcode Blob Header' + col_e
pt.add_row(['Tag', self.Tag.decode('utf-8')])
pt.add_row(['Microcode Count', self.MCCount])
pt.add_row(['MCE DB Revision', self.MCEDBRev])
pt.add_row(['Header Revision', self.HeaderRev])
pt.add_row(['Microcode Vendor', ['Intel','AMD'][self.MCVendor]])
pt.add_row(['Reserved', self.Reserved.decode('utf-8')])
pt.add_row(['Checksum', '%0.8X' % self.Checksum])
print(pt)
class MCB_Entry(ctypes.LittleEndianStructure) :
_pack_ = 1
_fields_ = [
('CPUID', uint32_t), # 0x00 CPUID
('Platform', uint32_t), # 0x04 Platform (Intel only)
('Revision', uint32_t), # 0x08 Revision
('Year', uint16_t), # 0x0C Year
('Month', uint8_t), # 0x0E Month
('Day', uint8_t), # 0x0F Day
('Offset', uint32_t), # 0x10 Offset
('Size', uint32_t), # 0x14 Size
('Checksum', uint32_t), # 0x18 Checksum (Vendor/MCE)
('Reserved', uint32_t), # 0x1C Reserved (0)
# 0x20
]
def mc_print(self) :
pt, _ = mc_table(['Field', 'Value'], False, 1)
pt.title = col_y + 'Microcode Blob Entry' + col_e
pt.add_row(['CPUID', '%0.8X' % self.CPUID])
pt.add_row(['Platform', intel_plat(self.Platform)])
pt.add_row(['Date', '%0.4X-%0.2X-%0.2X' % (self.Year, self.Month, self.Day)])
pt.add_row(['Offset', '0x%X' % self.Offset])
pt.add_row(['Size', '0x%X' % self.Size])
pt.add_row(['Checksum', '%0.8X' % self.Checksum])
pt.add_row(['Reserved', self.Reserved])
print(pt)
def mce_exit(code) :
try :
# Before exiting, print output of MCE & DB update check Thread, if completed/dead
if not thread_update.is_alive() and thread_update.result : print(thread_update.result)
# Before exiting, close DB
cursor.close() # Close DB Cursor
connection.close() # Close DB Connection
except :
pass
colorama.deinit() # Stop Colorama
if not param.skip_pause : input('\nPress enter to exit')
sys.exit(code)
# https://stackoverflow.com/a/22881871 by jfs
def get_script_dir(follow_symlinks=True) :
if getattr(sys, 'frozen', False) :
path = os.path.abspath(sys.executable)
else :
path = inspect.getabsfile(get_script_dir)
if follow_symlinks :
path = os.path.realpath(path)
return os.path.dirname(path)
# https://stackoverflow.com/a/781074 by Torsten Marek
def show_exception_and_exit(exc_type, exc_value, tb) :
if exc_type is KeyboardInterrupt :
print('\n')
else :
print(col_r + '\nError: %s crashed, please report the following:\n' % title)
traceback.print_exception(exc_type, exc_value, tb)
print(col_e)
if not param.skip_pause : input('Press enter to exit')
colorama.deinit() # Stop Colorama
sys.exit(-1)
def report_msg(msg_len) :
return f' You can help this project\n{" " * msg_len}by sharing it at https://win-raid.com forum. Thank you!'
def adler32(data, iv=1) :
return zlib.adler32(data, iv) & 0xFFFFFFFF
def crc32(data, iv=0) :
return zlib.crc32(data, iv) & 0xFFFFFFFF
def checksum32(data) :
chk32 = 0
for idx in range(0, len(data), 4) :
chk32 += int.from_bytes(data[idx:idx + 4], 'little')
return -chk32 & 0xFFFFFFFF
# https://github.com/skochinsky/me-tools/blob/master/me_unpack.py by Igor Skochinsky
def get_struct(input_stream, start_offset, class_name, param_list = None) :
if param_list is None : param_list = []
structure = class_name(*param_list) # Unpack parameter list
struct_len = ctypes.sizeof(structure)
struct_data = input_stream[start_offset:start_offset + struct_len]
fit_len = min(len(struct_data), struct_len)
if (start_offset >= file_end) or (fit_len < struct_len) :
print(col_r + 'Error: Offset 0x%X out of bounds at %s, possibly incomplete image!' % (start_offset, class_name.__name__) + col_e)
mce_exit(-1)
ctypes.memmove(ctypes.addressof(structure), struct_data, fit_len)
return structure
def intel_plat(cpuflags) :
platforms = []
if cpuflags == 0 : # 1995-1998
platforms.append(0)
else:
for bit in range(8) : # 0-7
cpu_flag = cpuflags >> bit & 1
if cpu_flag == 1 : platforms.append(bit)
return platforms
def mc_db_name(in_file, mc_name, mc_nr) :
new_file_name = os.path.join(os.path.dirname(in_file), mc_name + '.bin')
if mc_nr == 2 : print(col_m + 'Warning: This file includes multiple microcodes!' + col_e)
elif not os.path.isfile(new_file_name) : os.replace(in_file, new_file_name)
elif os.path.basename(in_file) == mc_name + '.bin' : pass
else : print(col_r + 'Error: A file with the same name already exists!' + col_e)
def date_check(year, month, day) :
year,month,day = int(year), int(month), int(day)
if not (year >= 0 and 1 <= month <= 12 and 1 <= day <= 31) : return False
if year % 4 == 0 : # Check for Leap Years (February)
if month == 2 and day > 29 : return False
else :
if month == 2 and day > 28 : return False
return True
def mce_upd_check(db_path) :
result = None
try :
with urllib.request.urlopen('https://raw.githubusercontent.com/platomav/MCExtractor/master/MCE.py') as gpy : git_py = gpy.read(0x100)
git_py_utf = git_py.decode('utf-8','ignore')
git_py_idx = git_py_utf.find('title = \'MC Extractor v')
if git_py_idx == -1 : raise Exception('BAD_PY_FORMAT')
git_py_ver = git_py_utf[git_py_idx:][23:].split('\'')[0].split('_')[0]
cur_py_ver = title[14:].split('_')[0]
py_print = '(v%s --> v%s)' % (cur_py_ver, git_py_ver)
py_is_upd = mce_is_latest(cur_py_ver.split('.')[:3], git_py_ver.split('.')[:3])
with urllib.request.urlopen('https://raw.githubusercontent.com/platomav/MCExtractor/master/MCE.db') as gdb : git_db = gdb.read()
tmp_db = db_path + '.temp'
with open(tmp_db, 'wb') as db : db.write(git_db)
git_conn = sqlite3.connect(tmp_db)
git_curs = git_conn.cursor()
git_curs.execute('PRAGMA quick_check')
git_db_ver = (git_curs.execute('SELECT revision FROM MCE')).fetchone()[0]
git_curs.close()
git_conn.close()
if os.path.isfile(tmp_db) : os.remove(tmp_db)
cur_conn = sqlite3.connect(db_path)
cur_curs = cur_conn.cursor()
cur_curs.execute('PRAGMA quick_check')
cur_db_ver = (cur_curs.execute('SELECT revision FROM MCE')).fetchone()[0]
cur_curs.close()
cur_conn.close()
db_print = '(r%s --> r%s)' % (cur_db_ver, git_db_ver)
db_is_upd = cur_db_ver >= git_db_ver
git_link = '\n Download the latest from https://github.com/platomav/MCExtractor/'
if not py_is_upd and not db_is_upd : result = col_m + '\nWarning: Outdated MC Extractor %s & Database %s!' % (py_print,db_print) + git_link + col_e
elif not py_is_upd : result = col_m + '\nWarning: Outdated MC Extractor %s!' % py_print + git_link + col_e
elif not db_is_upd : result = col_m + '\nWarning: Outdated Database %s!' % db_print + git_link + col_e
except :
result = None
return result
def mce_is_latest(ver_before, ver_after) :
# ver_before/ver_after = [X.X.X]
if int(ver_before[0]) > int(ver_after[0]) or (int(ver_before[0]) == int(ver_after[0]) and (int(ver_before[1]) > int(ver_after[1])
or (int(ver_before[1]) == int(ver_after[1]) and int(ver_before[2]) >= int(ver_after[2])))) :
return True
return False
def chk_mc_mod(mc_nr, msg_vendor, mc_db_note) :
mod_info = ' (%s)' % mc_db_note if mc_db_note != '' else ''
msg_vendor.append(col_y + "\nNote: Microcode #%d has an OEM/User modified header%s!" % (mc_nr, mod_info) + col_e)
return msg_vendor
def chk_mc_cross(match_ucode_idx, match_list_vendor, msg_vendor, mc_nr, mc_bgn, mc_len) :
if match_ucode_idx + 1 in range(len(match_list_vendor)) and match_list_vendor[match_ucode_idx + 1].start() < mc_bgn + mc_len :
msg_vendor.append(col_m + '\nWarning: Microcode #%d is crossing over to the next microcode(s)!' % mc_nr + col_e)
copy_file_with_warn()
return msg_vendor
def db_new_MCE() :
db_is_dev = (cursor.execute('SELECT developer FROM MCE')).fetchone()[0]
db_rev_now = (cursor.execute('SELECT revision FROM MCE')).fetchone()[0]
if db_is_dev == 0 :
cursor.execute('UPDATE MCE SET revision=? WHERE ROWID=1', (db_rev_now + 1,))
cursor.execute('UPDATE MCE SET developer=1 WHERE ROWID=1')
connection.commit()
def copy_file_with_warn() :
file_name = os.path.basename(in_file)
warn_dir = os.path.join(mce_dir, 'Warnings', '')
warn_name = os.path.join(warn_dir, file_name)
if not os.path.isdir(warn_dir) : os.mkdir(warn_dir)
# Check if same file already exists
if os.path.isfile(warn_name) :
with open(warn_name, 'br') as file :
if adler32(file.read()) == adler32(reading) : return
warn_name += '_%d' % cur_count
shutil.copyfile(in_file, warn_name)
def save_mc_file(mc_path, mc_data, mc_chk) :
if param.mce_ubu : return
if os.path.isfile(mc_path) :
with open(mc_path, 'rb') as mc_dup : dup_data = mc_dup.read()
if mc_data == dup_data : return
mc_path = '%s_%0.8X.bin' % (mc_path[:-4], mc_chk)
with open(mc_path, 'wb') as mc_file : mc_file.write(mc_data)
def mc_upd_chk_intel(mc_upd_chk_rsl, in_pl_bit, in_rel, in_ver, in_mod) :
is_latest = True
mc_latest = None
for entry in mc_upd_chk_rsl :
db_day = entry[0][6:8]
db_month = entry[0][4:6]
db_year = entry[0][:4]
db_pl_val = int(entry[1], 16)
db_pl_bit = intel_plat(int(entry[1], 16))
db_ver = int(entry[2], 16)
db_rel = 'PRE' if ctypes.c_int(db_ver).value < 0 else 'PRD'
# Same Release, Same or more Platform IDs, Newer Date, Same Date but more Platform IDs or Newer Version (not for -last)
if in_rel == db_rel and set(in_pl_bit).issubset(db_pl_bit) and \
((year < db_year or (year == db_year and (month < db_month or (month == db_month and day < db_day)))) or
((year,month,day) == (db_year,db_month,db_day) and (len(in_pl_bit) < len(db_pl_bit) or in_ver < db_ver) and not param.get_last)) :
is_latest = False
mc_latest = [cpu_id, db_pl_val, db_ver, db_year, db_month, db_day, db_rel]
if in_mod == 1 : is_latest = False # Modded input microcodes should not be shown as Latest
return is_latest, mc_latest
def mc_upd_chk_amd(mc_upd_chk_rsl, in_ver, in_mod) :
is_latest = True
mc_latest = None
for entry in mc_upd_chk_rsl :
db_day = entry[0][6:8]
db_month = entry[0][4:6]
db_year = entry[0][:4]
db_ver = int(entry[1], 16)
# Newer Date, Same Date but Newer Version (not for -last)
if (year < db_year or (year == db_year and (month < db_month or (month == db_month and day < db_day)))) \
or ((year,month,day) == (db_year,db_month,db_day) and in_ver < db_ver and not param.get_last) :
is_latest = False
mc_latest = [cpu_id, db_ver, db_year, db_month, db_day]
if in_mod == 1 : is_latest = False # Modded input microcodes should not be shown as Latest
return is_latest, mc_latest
def build_mc_repo(vendor, mc_name) :
repo_dir = os.path.join(mce_dir, 'Repo_%s' % vendor, '')
if not os.path.isdir(repo_dir) : os.mkdir(repo_dir)
shutil.copyfile(in_file, repo_dir + mc_name + '.bin')
def mc_table(row_col_names,header,padd) :
pt = pltable.PrettyTable(row_col_names)
pt.set_style(pltable.UNICODE_LINES)
pt.xhtml = True
pt.header = header # Boolean
pt.left_padding_width = padd if not param.mce_ubu else 0
pt.right_padding_width = padd if not param.mce_ubu else 0
pt.hrules = pltable.ALL
pt.vrules = pltable.ALL
pt_empty = str(pt)
return pt,pt_empty
def display_sql(cursor,title,header,padd):
rows = cursor.fetchall()
if not rows : return
if param.mce_ubu : padd = 0
sqlr = pltable.PrettyTable()
sqlr.set_style(pltable.UNICODE_LINES)
sqlr.xhtml = True
sqlr.header = header # Boolean
sqlr.left_padding_width = padd
sqlr.right_padding_width = padd
sqlr.hrules = pltable.ALL
sqlr.vrules = pltable.ALL
sqlr.title = title
row_id = -1
for name in [cn[0].upper() for cn in cursor.description]:
row_id += 1
sqlr.add_column(name, [row[row_id] for row in rows])
print('\n%s' % sqlr)
def mce_hdr(hdr_title) :
hdr_pt, _ = mc_table([], False, 1)
hdr_pt.add_row([col_y + ' %s ' % hdr_title + col_e])
print(hdr_pt)
def mass_scan(f_path) :
mass_files = []
for root, _, files in os.walk(f_path):
for name in files :
mass_files.append(os.path.join(root, name))
input('\nFound %s file(s)\n\nPress enter to start' % len(mass_files))
return mass_files
# Get MCE Parameters from input
param = MCE_Param(sys_os, sys.argv)
# Pause after any unexpected python exception
if not param.mce_ubu : sys.excepthook = show_exception_and_exit
# Get script location
mce_dir = get_script_dir()
# Set DB location
db_path = os.path.join(mce_dir, 'MCE.db')
# Initialize & Start background Thread for MCE & DB update check
thread_update = Thread_With_Result(target=mce_upd_check, args=(db_path,), daemon=True)
if not param.upd_dis : thread_update.start() # Start as soon as possible (mce_dir, db_path)
# Set MCB location
mcb_path = os.path.join(mce_dir, 'MCB.bin')
# Enumerate parameter input
arg_num = len(sys.argv)
# Connect to MCE Database
if os.path.isfile(db_path) :
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
# Validate DB health
try :
cursor.execute('PRAGMA quick_check')
except :
mce_hdr(title)
print(col_r + '\nError: MCE.db file is corrupted!' + col_e)
mce_exit(-1)
# Initialize DB, if found empty
cursor.execute('CREATE TABLE IF NOT EXISTS MCE(revision INTEGER DEFAULT 0, developer INTEGER DEFAULT 1, minimum BLOB DEFAULT "0.0.0")')
cursor.execute('CREATE TABLE IF NOT EXISTS Intel(cpuid BLOB, platform BLOB, version BLOB, yyyymmdd TEXT, size BLOB, checksum BLOB DEFAULT "00000000", \
adler32 BLOB DEFAULT "00000000", adler32e BLOB DEFAULT "00000000", modded INTEGER DEFAULT 0, notes TEXT DEFAULT "")')
cursor.execute('CREATE TABLE IF NOT EXISTS AMD(cpuid BLOB, nbdevid BLOB, sbdevid BLOB, nbsbrev BLOB, version BLOB, yyyymmdd TEXT, size BLOB, \
checksum BLOB DEFAULT "00000000", adler32 BLOB DEFAULT "00000000", modded INTEGER DEFAULT 0, notes TEXT DEFAULT "")')
cursor.execute('CREATE TABLE IF NOT EXISTS VIA(cpuid BLOB, signature TEXT, version BLOB, yyyymmdd TEXT, size BLOB, checksum BLOB DEFAULT "00000000", \
adler32 BLOB DEFAULT "00000000", modded INTEGER DEFAULT 0, notes TEXT DEFAULT "")')
cursor.execute('CREATE TABLE IF NOT EXISTS FSL(name TEXT, model BLOB, major BLOB, minor BLOB, size BLOB, checksum BLOB DEFAULT "00000000", \
adler32 BLOB DEFAULT "00000000", modded INTEGER DEFAULT 0, notes TEXT DEFAULT "")')
if not cursor.execute('SELECT EXISTS(SELECT 1 FROM MCE)').fetchone()[0] : cursor.execute('INSERT INTO MCE DEFAULT VALUES')
connection.commit()
# Check for MCE & DB incompatibility
db_rev = (cursor.execute('SELECT revision FROM MCE')).fetchone()[0]
db_dev = ['',' Dev'][(cursor.execute('SELECT developer FROM MCE')).fetchone()[0]]
db_min = (cursor.execute('SELECT minimum FROM MCE')).fetchone()[0]
if not mce_is_latest(title[14:].split('_')[0].split('.')[:3], db_min.split('_')[0].split('.')[:3]) :
mce_hdr(title)
print(col_r + '\nError: DB r%d%s requires MCE >= v%s!' % (db_rev, db_dev, db_min) + col_e)
mce_exit(-1)
else :
cursor = None
connection = None
mce_hdr(title)
print(col_r + '\nError: MCE.db file is missing!' + col_e)
mce_exit(-1)
rev_dev = (cursor.execute('SELECT revision, developer FROM MCE')).fetchone()
mce_title = '%s r%d%s' % (title, rev_dev[0], ' Dev' if rev_dev[1] else '')
# Set console/shell window title
if not param.mce_ubu :
if sys_os == 'win32' : ctypes.windll.kernel32.SetConsoleTitleW(mce_title)
elif sys_os.startswith('linux') or sys_os == 'darwin' or sys_os.find('bsd') != -1 : sys.stdout.write('\x1b]2;' + mce_title + '\x07')
if not param.skip_intro :
mce_hdr(mce_title)
print("\nWelcome to Intel, AMD, VIA & Freescale Microcode Extractor\n")
arg_num = len(sys.argv)
if arg_num == 2 :
print("Press Enter to skip or input -? to list options\n")
print("\nFile: " + col_g + "%s" % os.path.basename(sys.argv[1]) + col_e)
elif arg_num > 2 :
print("Press Enter to skip or input -? to list options\n")
print("\nFiles: " + col_y + "Multiple" + col_e)
else :
print('Input a file name/path or press Enter to list options\n')
print("\nFile: " + col_m + "None" + col_e)
input_var = input('\nOption(s): ')
# Anything quoted ("") is taken as one (file paths etc)
input_var = re.split(''' (?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', input_var.strip())
# Get MCE Parameters based on given Options
param = MCE_Param(sys_os, input_var)
# Non valid parameters are treated as files
if input_var[0] != "" :
for i in input_var:
if i not in param.val :
sys.argv.append(i.strip('"'))
# Re-enumerate parameter input
arg_num = len(sys.argv)
os.system(cl_wipe)
mce_hdr(mce_title)
elif not param.get_last :
mce_hdr(mce_title)
if (arg_num < 2 and not param.help_scr and not param.mass_scan