Repository navigation
Expand file tree
/
Copy pathmatcher.cpp
More file actions
1601 lines (1429 loc) · 62.3 KB
/
Copy pathmatcher.cpp
File metadata and controls
1601 lines (1429 loc) · 62.3 KB
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
/*
This file is part of Snappy Driver Installer.
Snappy Driver Installer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License or (at your option) any later version.
Snappy Driver Installer is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
Snappy Driver Installer. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdio>
#include <unordered_map>
#include <windows.h>
#include <Shlwapi.h>
#include "SDI.h"
#include "version.h"
#include "logging.h"
#include "system.h"
#include "Settings.h"
#include "indexing.h"
#include "matcher.h"
#include "theme.h"
#include "gui.h"
// Depend on Win32API
#include "enum.h"
#include "device.h" // for CM_PROB_DISABLED
//{ Global variables
/*
For Windows XP to Windows 10, version 1511, the format of TargetOSVersion decoration is as follows:
INF
NT[Architecture][.[OSMajorVersion][.[OSMinorVersion][.[ProductType][.SuiteMask]]]]
Starting with Windows 10, version 1607 (Build 14310 and later), the format of the TargetOSVersion decoration is as follows:
INF
NT[Architecture][.[OSMajorVersion][.[OSMinorVersion][.[ProductType][.[SuiteMask][.[BuildNumber]]]]
Windows 11 21H2 10.0.22000
Windows 11 22H2 10.0.22261
Windows 11 23H2 10.0.22631
Windows 11 24H2 10.0.26100
Windows 11 25H2 10.0.26200
Windows 10 10.0.10240
Windows 10 (1511) 10.0.10586
Windows 10 (1607) 10.0.14310
Windows 10 (1607) 10.0.14393
Windows 10 (1703) 10.0.15063
Windows 10 (1709) 10.0.16299
Windows 10 (1803) 10.0.17134
Windows 10 (1809) 10.0.17763
Windows 10 (1903) 10.0.18362
Windows 10 (1909) 10.0.18363
Windows 10 (2004) 10.0.19041
Windows 10 (20H2) 10.0.19042
Windows 10 (21H1) 10.0.19043
Windows 10 (21H2) 10.0.19044
Windows 10 (22H2) 10.0.19045
*/
/*
Invalid:
me Windows ME
ntx64 ntAMD64
ntai64 ntIA64
ntarm ARM
ntx64.6.0 ntAMD64
nt.7 future
*/
// following matches the optional architecture field in the [Manufacturer]
// section of the inf file
const char *nts[num_decs]=
{
// https://betawiki.net/wiki/Windows_11 // CLIENT SERVER
"nt.5", "ntx86.5", "ntamd64.5", "ntia64.5", "ntarm.5", "ntarm64.5", // 2000
"nt.5.0", "ntx86.5.0", "ntamd64.5.0", "ntia64.5.0", "ntarm.5.0", "ntarm64.5.0", // 2000
"nt.5.1", "ntx86.5.1", "ntamd64.5.1", "ntia64.5.1", "ntarm.5.1", "ntarm64.5.1", // XP
"nt.5.2", "ntx86.5.2", "ntamd64.5.2", "ntia64.5.2", "ntarm.5.2", "ntarm64.5.2", // XP x64 Server 2003
"nt.6", "ntx86.6", "ntamd64.6", "ntia64.6", "ntarm.6", "ntarm64.6", // Vista Server 2008
"nt.6.0", "ntx86.6.0", "ntamd64.6.0", "ntia64.6.0", "ntarm.6.0", "ntarm64.6.0", // Vista Server 2008
"nt.6.1", "ntx86.6.1", "ntamd64.6.1", "ntia64.6.1", "ntarm.6.1", "ntarm64.6.1", // 7 Server 2008 R2
"nt.6.2", "ntx86.6.2", "ntamd64.6.2", "ntia64.6.2", "ntarm.6.2", "ntarm64.6.2", // 8 Server 2012
"nt.6.3", "ntx86.6.3", "ntamd64.6.3", "ntia64.6.3", "ntarm.6.3", "ntarm64.6.3", // 8.1 Server 2012 R2
"nt.6.4", "ntx86.6.4", "ntamd64.6.4", "ntia64.6.4", "ntarm.6.4", "ntarm64.6.4", // 10
"nt.10", "ntx86.10", "ntamd64.10", "ntia64.10", "ntarm.10", "ntarm64.10", // 10
"nt.10.0", "ntx86.10.0", "ntamd64.10.0", "ntia64.10.0", "ntarm.10.0", "ntarm64.10.0", // 10 Server 2016
"nt.10.0...10240", "ntx86.10.0...10240", "ntamd64.10.0...10240", "ntia64.10.0...10240", "ntarm.10.0...10240", "ntarm64.10.0...10240", //Win 10 v1507
"nt.10.0...10586", "ntx86.10.0...10586", "ntamd64.10.0...10586", "ntia64.10.0...10586", "ntarm.10.0...10586", "ntarm64.10.0...10586", //Win 10 v1511 Server 2016 TP4
"nt.10.0...14310", "ntx86.10.0...14310", "ntamd64.10.0...14310", "ntia64.10.0...14310", "ntarm.10.0...14310", "ntarm64.10.0...14310", //Win 10 v1607 Server 2016
"nt.10.0...14393", "ntx86.10.0...14393", "ntamd64.10.0...14393", "ntia64.10.0...14393", "ntarm.10.0...14393", "ntarm64.10.0...14393", //Win 10 v1607 Server 2016
"nt.10.0...15063", "ntx86.10.0...15063", "ntamd64.10.0...15063", "ntia64.10.0...15063", "ntarm.10.0...15063", "ntarm64.10.0...15063", //Win 10 v1703
"nt.10.0...16209", "ntx86.10.0...16209", "ntamd64.10.0...16209", "ntia64.10.0...16209", "ntarm.10.0...16209", "ntarm64.10.0...16209", //Win 10 v1709 EEAP
"nt.10.0...16273", "ntx86.10.0...16273", "ntamd64.10.0...16273", "ntia64.10.0...16273", "ntarm.10.0...16273", "ntarm64.10.0...16273", //Win 10 v1709 preview Server 1709
"nt.10.0...16288", "ntx86.10.0...16288", "ntamd64.10.0...16288", "ntia64.10.0...16288", "ntarm.10.0...16288", "ntarm64.10.0...16288", //Win 10 v1709 preview
"nt.10.0...16299", "ntx86.10.0...16299", "ntamd64.10.0...16299", "ntia64.10.0...16299", "ntarm.10.0...16299", "ntarm64.10.0...16299", //Win 10 v1709 Server 2016
"nt.10.0...17134", "ntx86.10.0...17134", "ntamd64.10.0...17134", "ntia64.10.0...17134", "ntarm.10.0...17134", "ntarm64.10.0...17134", //Win 10 v1803 Server 2016
"nt.10.0...17704", "ntx86.10.0...17704", "ntamd64.10.0...17704", "ntia64.10.0...17704", "ntarm.10.0...17704", "ntarm64.10.0...17704", //Win 10 v1809 preview Server 2019
"nt.10.0...17735", "ntx86.10.0...17735", "ntamd64.10.0...17735", "ntia64.10.0...17735", "ntarm.10.0...17735", "ntarm64.10.0...17735", //Win 10 v1809 preview Server 2019
"nt.10.0...17763", "ntx86.10.0...17763", "ntamd64.10.0...17763", "ntia64.10.0...17763", "ntarm.10.0...17763", "ntarm64.10.0...17763", //Win 10 v1809 Server 2019
"nt.10.0...18362", "ntx86.10.0...18362", "ntamd64.10.0...18362", "ntia64.10.0...18362", "ntarm.10.0...18362", "ntarm64.10.0...18362", //Win 10 v1903 Server 2019
"nt.10.0...18363", "ntx86.10.0...18363", "ntamd64.10.0...18363", "ntia64.10.0...18363", "ntarm.10.0...18363", "ntarm64.10.0...18363", //Win 10 v1909 Server 2019
"nt.10.0...18900", "ntx86.10.0...18900", "ntamd64.10.0...18900", "ntia64.10.0...18900", "ntarm.10.0...18900", "ntarm64.10.0...18900", //Win 10 v20H1 preview
"nt.10.0...19041", "ntx86.10.0...19041", "ntamd64.10.0...19041", "ntia64.10.0...19041", "ntarm.10.0...19041", "ntarm64.10.0...19041", //Win 10 v2004/20H1 Server 2019
"nt.10.0...19042", "ntx86.10.0...19042", "ntamd64.10.0...19042", "ntia64.10.0...19042", "ntarm.10.0...19042", "ntarm64.10.0...19042", //Win 10 v20H2 Server 2019
"nt.10.0...19043", "ntx86.10.0...19043", "ntamd64.10.0...19043", "ntia64.10.0...19043", "ntarm.10.0...19043", "ntarm64.10.0...19043", //Win 10 v21H1
"nt.10.0...19044", "ntx86.10.0...19044", "ntamd64.10.0...19044", "ntia64.10.0...19044", "ntarm.10.0...19044", "ntarm64.10.0...19044", //Win 10 v21H2
"nt.10.0...19045", "ntx86.10.0...19045", "ntamd64.10.0...19045", "ntia64.10.0...19045", "ntarm.10.0...19045", "ntarm64.10.0...19045", //Win 10 v22H2
"nt.10.0...19586", "ntx86.10.0...19586", "ntamd64.10.0...19586", "ntia64.10.0...19586", "ntarm.10.0...19586", "ntarm64.10.0...19586", //Win 11 preview
"nt.10.0...20190", "ntx86.10.0...20190", "ntamd64.10.0...20190", "ntia64.10.0...20190", "ntarm.10.0...20190", "ntarm64.10.0...20190", //Win 11 preview Server 2022
"nt.10.0...20348", "ntx86.10.0...20348", "ntamd64.10.0...20348", "ntia64.10.0...20348", "ntarm.10.0...20348", "ntarm64.10.0...20348", // Server 2022
"nt.10.0...21250", "ntx86.10.0...21250", "ntamd64.10.0...21250", "ntia64.10.0...21250", "ntarm.10.0...21250", "ntarm64.10.0...21250", //Win 11 preview
"nt.10.0...21262", "ntx86.10.0...21262", "ntamd64.10.0...21262", "ntia64.10.0...21262", "ntarm.10.0...21262", "ntarm64.10.0...21262", //Win 11 Cobalt
"nt.10.0...22000", "ntx86.10.0...22000", "ntamd64.10.0...22000", "ntia64.10.0...22000", "ntarm.10.0...22000", "ntarm64.10.0...22000", //Win 11 v21H2
"nt.10.0...22621", "ntx86.10.0...22621", "ntamd64.10.0...22621", "ntia64.10.0...22621", "ntarm.10.0...22621", "ntarm64.10.0...22621", //Win 11 v22H2
"nt.10.0...22631", "ntx86.10.0...22631", "ntamd64.10.0...22631", "ntia64.10.0...22631", "ntarm.10.0...22631", "ntarm64.10.0...22631", //Win 11 v23H2
"nt.10.0...22635", "ntx86.10.0...22635", "ntamd64.10.0...22635", "ntia64.10.0...22635", "ntarm.10.0...22635", "ntarm64.10.0...22635", //Win 11 v23H2
"nt.10.0...25216", "ntx86.10.0...25216", "ntamd64.10.0...25216", "ntia64.10.0...25216", "ntarm.10.0...25216", "ntarm64.10.0...25216", //Win 11 v24H2 Preview Server 2025
"nt.10.0...25398", "ntx86.10.0...25398", "ntamd64.10.0...25398", "ntia64.10.0...25398", "ntarm.10.0...25398", "ntarm64.10.0...25398", //Win 11 Server 23H2
"nt.10.0...25952", "ntx86.10.0...25952", "ntamd64.10.0...25952", "ntia64.10.0...25952", "ntarm.10.0...25952", "ntarm64.10.0...25952", //Win 11 v24H2 Preview
"nt.10.0...26052", "ntx86.10.0...26052", "ntamd64.10.0...26052", "ntia64.10.0...26052", "ntarm.10.0...26052", "ntarm64.10.0...26052", //Win 11 v24H2 Preview Server 2025
"nt.10.0...26063", "ntx86.10.0...26063", "ntamd64.10.0...26063", "ntia64.10.0...26063", "ntarm.10.0...26063", "ntarm64.10.0...26063", //Win 11 v24H2 PreSSE4.2 Server 2025
"nt.10.0...26080", "ntx86.10.0...26080", "ntamd64.10.0...26080", "ntia64.10.0...26080", "ntarm.10.0...26080", "ntarm64.10.0...26080", //Win 11 v24H2 Dev Server 2025
"nt.10.0...26100", "ntx86.10.0...26100", "ntamd64.10.0...26100", "ntia64.10.0...26100", "ntarm.10.0...26100", "ntarm64.10.0...26100", //Win 11 v24H2 Server 2025
"nt.10.0...26200", "ntx86.10.0...26200", "ntamd64.10.0...26200", "ntia64.10.0...26200", "ntarm.10.0...26200", "ntarm64.10.0...26200", //Win 11 v25H2
"nt", "ntx86", "ntamd64", "ntia64", "ntarm", "ntarm64", // NT specifies Win 2000 and later
"nt..", "ntx86..", "ntamd64..", "ntia64..", "ntarm..", "ntarm64.."
};
// this represents the inf file target version = major * 10 + minor
// where win11 = 10.0.22000 or later
const int nts_version[num_decs]=
{
50, 50, 50, 50, 50, 50, // 2000
50, 50, 50, 50, 50, 50, // 2000
51, 51, 51, 51, 51, 51, // XP
52, 52, 52, 52, 52, 52, // Server 2003
60, 60, 60, 60, 60, 60, // Vista
60, 60, 60, 60, 60, 60, // Vista
61, 61, 61, 61, 61, 61, // 7
62, 62, 62, 62, 62, 62, // 8
63, 63, 63, 63, 63, 63, // 8.1
64, 64, 64, 64, 64, 64, // 10
100, 100, 100, 100, 100, 100, // 10
100, 100, 100, 100, 100, 100, // 10
//
100, 100, 100, 100, 100, 100, // 10 (1507)
100, 100, 100, 100, 100, 100, // 10 (1511)
100, 100, 100, 100, 100, 100, // 10 (1607) (14310)
100, 100, 100, 100, 100, 100, // 10 (1607)
100, 100, 100, 100, 100, 100, // 10 (1703)
100, 100, 100, 100, 100, 100, // 10 (creators update)
100, 100, 100, 100, 100, 100, // 10 (insider preview)
100, 100, 100, 100, 100, 100, // 10 (insider preview)
100, 100, 100, 100, 100, 100, // 10 (1709)
100, 100, 100, 100, 100, 100, // 10 (1803)
100, 100, 100, 100, 100, 100, // 10 (1803)
100, 100, 100, 100, 100, 100, // 10 (insider preview)
100, 100, 100, 100, 100, 100, // 10 (1809)
100, 100, 100, 100, 100, 100, // 10 (1903)
100, 100, 100, 100, 100, 100, // 10 (1909)
100, 100, 100, 100, 100, 100, // 10 (1909)
100, 100, 100, 100, 100, 100, // 10 (20H1)
100, 100, 100, 100, 100, 100, // 10 (20H2)
100, 100, 100, 100, 100, 100, // 10 (21H1)
100, 100, 100, 100, 100, 100, // 10 (21H2)
100, 100, 100, 100, 100, 100, // 10 (22H2)
100, 100, 100, 100, 100, 100, // 10 (?)
100, 100, 100, 100, 100, 100, // 10 (insider preview)
100, 100, 100, 100, 100, 100, // 10 (Server 2022)
100, 100, 100, 100, 100, 100, // 10 (?)
100, 100, 100, 100, 100, 100, // 10 (insider preview)
//
100, 100, 100, 100, 100, 100, // 11 (21H2)
100, 100, 100, 100, 100, 100, // 11 (22H2)
100, 100, 100, 100, 100, 100, // 11 (23H2)
100, 100, 100, 100, 100, 100, // 11
100, 100, 100, 100, 100, 100, // 11
100, 100, 100, 100, 100, 100, // 11 (?)
100, 100, 100, 100, 100, 100, // 11 (?)
100, 100, 100, 100, 100, 100, // 11 (insider preview)
100, 100, 100, 100, 100, 100, // 11 (insider preview)
100, 100, 100, 100, 100, 100, // 11 (insider preview)
100, 100, 100, 100, 100, 100, // 11 (24H2 - Server 2025)
100, 100, 100, 100, 100, 100, // 11 (25H2)
//
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
//
// -1,
};
const int nts_build[num_decs]=
{
0, 0, 0, 0, 0, 0, // 2000
0, 0, 0, 0, 0, 0, // 2000
0, 0, 0, 0, 0, 0, // XP
0, 0, 0, 0, 0, 0, // Server 2003
0, 0, 0, 0, 0, 0, // Vista
0, 0, 0, 0, 0, 0, // Vista
0, 0, 0, 0, 0, 0, // 7
0, 0, 0, 0, 0, 0, // 8
0, 0, 0, 0, 0, 0, // 8.1
0, 0, 0, 0, 0, 0, // 10
0, 0, 0, 0, 0, 0, // 10
0, 0, 0, 0, 0, 0, // 10
//
0, 0, 0, 0, 0, 0, // 10 (1507)
0, 0, 0, 0, 0, 0, // 10 (1511)
14310, 14310, 14310, 14310, 14310, 14310, // 10 (1607) (14310)
14393, 14393, 14393, 14393, 14393, 14393, // 10 (1607)
15063, 15063, 15063, 15063, 15063, 15063, // 10 (1703)
16209, 16209, 16209, 16209, 16209, 16209, // 10 (creators update)
16273, 16273, 16273, 16273, 16273, 16273, // 10 (insider preview)
16288, 16288, 16288, 16288, 16288, 16288, // 10 (insider preview)
16299, 16299, 16299, 16299, 16299, 16299, // 10 (1709)
17134, 17134, 17134, 17134, 17134, 17134, // 10 (1803)
17704, 17704, 17704, 17704, 17704, 17704, // 10 (1803)
17735, 17735, 17735, 17735, 17735, 17735, // 10 (insider preview)
17763, 17763, 17763, 17763, 17763, 17763, // 10 (1809)
18362, 18362, 18362, 18362, 18362, 18362, // 10 (1903)
18363, 18363, 18363, 18363, 18363, 18363, // 10 (1909)
18900, 18900, 18900, 18900, 18900, 18900, // 10
19041, 19041, 19041, 19041, 19041, 19041, // 10 (20H1)
19042, 19042, 19042, 19042, 19042, 19042, // 10 (20H2)
19043, 19043, 19043, 19043, 19043, 19043, // 10 (21H1)
19044, 19044, 19044, 19044, 19044, 19044, // 10 (21H2)
19045, 19045, 19045, 19045, 19045, 19045, // 10 (22H2)
19586, 19586, 19586, 19586, 19586, 19586, // 10 (?)
20190, 20190, 20190, 20190, 20190, 20190, // 10 (insider preview)
20348, 20348, 20348, 20348, 20348, 20348, // 10 (Server 2022)
21250, 21250, 21250, 21250, 21250, 21250, // 10 (?)
21262, 21262, 21262, 21262, 21262, 21262, // 10 (insider preview)
//
22000, 22000, 22000, 22000, 22000, 22000, // 11 (21H2)
22621, 22621, 22621, 22621, 22621, 22621, // 11 (22H2)
22631, 22631, 22631, 22631, 22631, 22631, // 11 (23H2)
22635, 22635, 22635, 22635, 22635, 22635, // 11 (23H2)
25216, 25216, 25216, 25216, 25216, 25216, // 11 (?)
25398, 25398, 25398, 25398, 25398, 25398, // 11 (?)
25952, 25952, 25952, 25952, 25952, 25952, // 11 (?)
26052, 26052, 26052, 26052, 26052, 26052, // 11 (insider preview)
26063, 26063, 26063, 26063, 26063, 26063, // 11 (insider preview)
26080, 26080, 26080, 26080, 26080, 26080, // 11 (insider preview)
26100, 26100, 26100, 26100, 26100, 26100, // 11 (24H2 - Server 2025)
26200, 26200, 26200, 26200, 26200, 26200, // 11 (25H2)
//
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
//
// -1,
};
// 0=unknown/don't care/ignore, 1=x86, 2=amd64, 3=ia64, 4=arm, 5=arm64
const int nts_arch[num_decs]=
{
0, 1, 2, 3, 4, 5, // 2000
0, 1, 2, 3, 4, 5, // 2000
0, 1, 2, 3, 4, 5, // XP
0, 1, 2, 3, 4, 5, // Serve
0, 1, 2, 3, 4, 5, // Vista
0, 1, 2, 3, 4, 5, // Vista
0, 1, 2, 3, 4, 5, // 7
0, 1, 2, 3, 4, 5, // 8
0, 1, 2, 3, 4, 5, // 8.1
0, 1, 2, 3, 4, 5, // 10
0, 1, 2, 3, 4, 5, // 10
0, 1, 2, 3, 4, 5, // 10
//
0, 1, 2, 3, 4, 5, // 10 (1507)
0, 1, 2, 3, 4, 5, // 10 (1511)
0, 1, 2, 3, 4, 5, // 10 (1607)
0, 1, 2, 3, 4, 5, // 10 (1607)
0, 1, 2, 3, 4, 5, // 10 (1703)
0, 1, 2, 3, 4, 5, // 10 (creators update)
0, 1, 2, 3, 4, 5, // 10 (insider preview)
0, 1, 2, 3, 4, 5, // 10 (insider preview)
0, 1, 2, 3, 4, 5, // 10 (1709)
0, 1, 2, 3, 4, 5, // 10 (1803)
0, 1, 2, 3, 4, 5, // 10 (1803)
0, 1, 2, 3, 4, 5, // 10 (insider preview)
0, 1, 2, 3, 4, 5, // 10 (1809)
0, 1, 2, 3, 4, 5, // 10 (1903)
0, 1, 2, 3, 4, 5, // 10 (1909)
0, 1, 2, 3, 4, 5, // 10
0, 1, 2, 3, 4, 5, // 10 (20H1)
0, 1, 2, 3, 4, 5, // 10 (20H2)
0, 1, 2, 3, 4, 5, // 10 (21H1)
0, 1, 2, 3, 4, 5, // 10 (21H2)
0, 1, 2, 3, 4, 5, // 10 (22H2)
0, 1, 2, 3, 4, 5, // 10 (?)
0, 1, 2, 3, 4, 5, // 10 (insider preview)
0, 1, 2, 3, 4, 5, // 10 (Server 2022)
0, 1, 2, 3, 4, 5, // 10 (?)
0, 1, 2, 3, 4, 5, // 10 (insider preview)
//
0, 1, 2, 3, 4, 5, // 11 (21H2)
0, 1, 2, 3, 4, 5, // 11 (22H2)
0, 1, 2, 3, 4, 5, // 11 (23H2)
0, 1, 2, 3, 4, 5, // 11
0, 1, 2, 3, 4, 5, // 11
0, 1, 2, 3, 4, 5, // 11 (?)
0, 1, 2, 3, 4, 5, // 11 (?)
0, 1, 2, 3, 4, 5, // 11 (insider preview)
0, 1, 2, 3, 4, 5, // 11 (insider preview)
0, 1, 2, 3, 4, 5, // 11 (insider preview)
0, 1, 2, 3, 4, 5, // 11 (24H2 - Server 2025)
0, 1, 2, 3, 4, 5, // 11 (25H2)
//
0, 1, 2, 3, 4, 5,
0, 1, 2, 3, 4, 5,
//
// -1,
};
// d: 0=x86, 1=amd64, 2=ia64, 3=arm, 4=arm64, -1=ignore
const int nts_score[num_decs]=
{
50, 150, 150, 150, 150, 150, // 2000
50, 150, 150, 150, 150, 150, // 2000
51, 151, 151, 151, 151, 151, // XP
52, 152, 152, 152, 152, 152, // Server 2003
60, 160, 160, 160, 160, 160, // Vista
60, 160, 160, 160, 160, 160, // Vista
61, 161, 161, 161, 161, 161, // 7
62, 162, 162, 162, 162, 162, // 8
63, 163, 163, 163, 163, 163, // 8.1
64, 164, 164, 164, 164, 164, // 10
64, 164, 164, 164, 164, 164, // 10
64, 164, 164, 164, 164, 164, // 10
//
64, 164, 164, 164, 164, 164, // 10 (1507)
64, 164, 164, 164, 164, 164, // 10 (1511)
64, 164, 164, 164, 164, 164, // 10 (1607) (14310)
64, 164, 164, 164, 164, 164, // 10 (1607)
64, 164, 164, 164, 164, 164, // 10 (1703)
64, 164, 164, 164, 164, 164, // 10 (creators update)
64, 164, 164, 164, 164, 164, // 10 (insider preview)
64, 164, 164, 164, 164, 164, // 10 (insider preview)
64, 164, 164, 164, 164, 164, // 10 (1709)
64, 164, 164, 164, 164, 164, // 10 (1803)
64, 164, 164, 164, 164, 164, // 10 (1803)
64, 164, 164, 164, 164, 164, // 10 (insider preview)
64, 164, 164, 164, 164, 164, // 10 (1809)
64, 164, 164, 164, 164, 164, // 10 (1903)
64, 164, 164, 164, 164, 164, // 10 (1909)
64, 164, 164, 164, 164, 164, // 10
64, 164, 164, 164, 164, 164, // 10 (20H1)
64, 164, 164, 164, 164, 164, // 10 (20H2)
64, 164, 164, 164, 164, 164, // 10 (21H1)
64, 164, 164, 164, 164, 164, // 10 (21H2)
64, 164, 164, 164, 164, 164, // 10 (22H2)
64, 164, 164, 164, 164, 164, // 10 (?)
64, 164, 164, 164, 164, 164, // 10 (insider preview)
64, 164, 164, 164, 164, 164, // 10 (Server 2022)
64, 164, 164, 164, 164, 164, // 10 (?)
64, 164, 164, 164, 164, 164, // 10 (insider preview)
//
65, 165, 165, 165, 165, 165, // 11 (21H2)
65, 165, 165, 165, 165, 165, // 11 (22H2)
65, 165, 165, 165, 165, 165, // 11 (23H2)
65, 165, 165, 165, 165, 165, // 11
65, 165, 165, 165, 165, 165, // 11
65, 165, 165, 165, 165, 165, // 11 (?)
65, 165, 165, 165, 165, 165, // 11 (?)
65, 165, 165, 165, 165, 165, // 11 (insider preview)
65, 165, 165, 165, 165, 165, // 11 (insider preview)
65, 165, 165, 165, 165, 165, // 11 (insider preview)
65, 165, 165, 165, 165, 165, // 11 (24H2 - Server 2025)
65, 165, 165, 165, 165, 165, // 11 (25H2)
//
10, 100, 100, 100, 100, 100,
10, 100, 100, 100, 100, 100,
//
// -1,
};
const markers_t markers[num_markers]=
{
// Exact x86
{"5x86", 5, 1, 0},
{"5x86", 5, 2, 0},
{"6x86", 6, 0, 0},
{"7x86", 6, 1, 0},
{"8x86", 6, 2, 0},
{"81x86", 6, 3, 0},
{"10x86", 6, 4, 0}, // to be confirmed
{"10x86", 10, 0, 0}, // to be confirmed
{"U10x86", 10, 0, 0}, // to be confirmed
{"11x86", 11, 0, 0}, // to be confirmed
{"67x86", 6, 0, 0},
{"6xx86", 6, 0, 0},
{"78x86", 6, 1, 0},
{"781x86", 6, 1, 0},
{"710x86", 6, 1, 0}, // to be confirmed
{"88110x86",6, 3, 0}, // to be confirmed
{"8110x86", 6, 3, 0}, // to be confirmed
// Exact x64
{"5x64", 5, 1, 1}, // XP
{"5x64", 5, 2, 1},
{"6x64", 6, 0, 1},
{"7x64", 6, 1, 1},
{"8x64", 6, 2, 1},
{"81x64", 6, 3, 1},
{"10x64", 6, 4, 1}, // to be confirmed
{"10x64", 10, 0, 1}, // to be confirmed
{"U10x64", 10, 0, 1}, // to be confirmed
{"11x64", 11, 0, 1}, // to be confirmed
{"67x64", 6, 0, 1},
{"6xx64", 6, 0, 1},
{"78x64", 6, 1, 1},
{"781x64", 6, 1, 1},
{"710x64", 6, 1, 1}, // to be confirmed
{"88110x64",6, 3, 1}, // to be confirmed
{"8110x64", 6, 3, 1}, // to be confirmed
// exact ia64
{"5ia64", 5, 1, 2}, // XP
{"5ia64", 5, 2, 2},
{"6ia64", 6, 0, 2},
{"7ia64", 6, 1, 2},
{"8ia64", 6, 2, 2},
{"10ia64", 10, 0, 2},
{"11ia64", 11, 0, 2},
// exact arm
{"5arm", 5, 1, 3}, // XP
{"5arm", 5, 2, 3},
{"6arm", 6, 0, 3},
{"7arm", 6, 1, 3},
{"8arm", 6, 2, 3},
{"10arm", 10, 0, 3},
{"11arm", 11, 0, 3},
// exact arm64
{"5arm64", 5, 1, 4}, // XP
{"5arm64", 5, 2, 4},
{"6arm64", 6, 0, 4},
{"7arm64", 6, 1, 4},
{"8arm64", 6, 2, 4},
{"10arm64",10, 0, 4},
{"11arm64",11, 0, 4},
// Each OS, ignore arch
{"allnt", 4, 0,-1},
{"allxp", 5, 1,-1},
{"allxp", 5, 2,-1},
{"all6", 6, 0,-1},
{"all7", 6, 1,-1},
{"all8\\", 6, 2,-1},
{"all81", 6, 3,-1},
{"all10", 6, 4,-1}, // to be confirmed
{"all10", 10, 0,-1}, // to be confirmed
{"all11", 11, 0,-1}, // to be confirmed
{"allntx64x86",4, 0, -1}, // to be confirmed
{"all5x86x64",5, 1, -1}, // to be confirmed
{"all5x86x64",5, 2, -1}, // to be confirmed
{"all6x86x64",6, 0, -1}, // to be confirmed
{"all7x86x64",6, 1, -1}, // to be confirmed
{"all8x86x64",6, 2, -1}, // to be confirmed
{"all10x86x64",10, 0, -1}, // to be confirmed
{"all11x86x64",11, 0, -1}, // to be confirmed
// arch
{"allx86", -1, -1, 0},
{"allx64", -1, -1, 1},
{"all8x86", 6, 2, 0},
{"all8x64", 6, 2, 1},
{"allia64", -1, -1, 2},
{"allarm", -1, -1, 3},
{"allarm64",-1, -1, 4},
{"ntx86", -1, -1, 0},
{"ntx64", -1, -1, 1},
{"x86\\", -1, -1, 0},
{"x64\\", -1, -1, 1},
{"winall", -1,-1,-1},
// ("", -1,-1,-1),
};
char marker[MAX_INF_STRING_LENGTH];
int isLaptop;
//}
//{ Calc
void State::genmarker()
{
static const wchar_t *Filter_1[]={L"Acer",L"acer",L"emachines",L"packard",L"bell",L"gateway",L"aspire",nullptr};
static const wchar_t *Filter_2[]={L"Apple",L"apple",nullptr};
static const wchar_t *Filter_3[]={L"Asus",L"asus",nullptr};
static const wchar_t *Filter_4[]={L"OEM",L"clevo",L"eurocom",L"sager",L"iru",L"viewsonic",L"viewbook",nullptr};
static const wchar_t *Filter_5[]={L"Dell",L"dell",L"alienware",L"arima",L"jetway",L"gericom",nullptr};
static const wchar_t *Filter_6[]={L"Fujitsu",L"fujitsu",L"sieme",nullptr};
static const wchar_t *Filter_7[]={L"OEM",L"ecs",L"elitegroup",L"roverbook",L"rover",L"shuttle",nullptr};
static const wchar_t *Filter_8[]={L"HP",L"hp",L"hewle",L"compaq",nullptr};
static const wchar_t *Filter_9[]={L"OEM",L"intel",L"wistron",nullptr};
static const wchar_t *Filter_10[]={L"Lenovo",L"lenovo",L"compal",L"ibm",nullptr};
static const wchar_t *Filter_11[]={L"LG",L"lg",nullptr};
static const wchar_t *Filter_12[]={L"OEM",L"mitac",L"mtc",L"depo",L"getac",nullptr};
static const wchar_t *Filter_13[]={L"MSI",L"msi",L"micro-star",nullptr};
static const wchar_t *Filter_14[]={L"Panasonic",L"panasonic",L"matsushita",nullptr};
static const wchar_t *Filter_15[]={L"OEM",L"quanta",L"prolink",L"nec",L"k-systems",L"benq",L"vizio",nullptr};
static const wchar_t *Filter_16[]={L"OEM",L"pegatron",L"medion",nullptr};
static const wchar_t *Filter_17[]={L"Samsung",L"samsung",nullptr};
static const wchar_t *Filter_18[]={L"Gigabyte",L"gigabyte",nullptr};
static const wchar_t *Filter_19[]={L"Sony",L"sony",L"vaio",nullptr};
static const wchar_t *Filter_20[]={L"Toshiba",L"toshiba",nullptr};
static const wchar_t *Filter_21[]={L"OEM",L"twinhead",L"durabook",nullptr};
static const wchar_t *Filter_22[]={L"NEC",L"Nec_brand",L"nec",nullptr};
static const wchar_t **filter_list[num_filters]=
{
Filter_1, Filter_2, Filter_3, Filter_4, Filter_5, Filter_6, Filter_7,
Filter_8, Filter_9, Filter_10,Filter_11,Filter_12,Filter_13,Filter_14,
Filter_15,Filter_16,Filter_17,Filter_18,Filter_19,Filter_20,Filter_21,
Filter_22,
};
wsprintfA(marker,"OEM_nb");
const wchar_t *str=getManuf();
if(!str)return;
for(size_t i=0;i<num_filters;i++)
for(size_t j=1;filter_list[i][j];j++)
if(StrStrIW(str,filter_list[i][j]))
wsprintfA(marker,"%S_nb",filter_list[i][0]);
Log.print_con("Marker: '%s'\n",marker);
}
int calc_secttype(const char *s)
{
char buf[MAX_INF_SECTION_NAME_LENGTH];
// char *p=buf;
s=StrStrIA(s,".nt");
if(!s)return -1;
/*
strcpy(buf,s);
// looking for a match in nts[]
if((p=strchr(p+1,'.')))
if((p=strchr(p+1,'.')))
if((p=strchr(p+1,'.')))
if((p=strchr(p+1,'.')))
if((p=strchr(p+1,'.')))
if((p=strchr(p+1,'.')))*p=0;
*/
// in order to get a match in nts[]
// i need to ignore the ProductType and SuiteMask fields
// but include the BuildNumber field
// NT[Architecture][.[OSMajorVersion][.[OSMinorVersion][.[ProductType][.[SuiteMask][.[BuildNumber]]]]]
std::string ss=s;
std::string sections[7];
std::string del=".";
int ndx=0;
auto pos=ss.find(del);
while(pos!=std::string::npos && ndx<7)
{
sections[ndx]=ss.substr(0,pos);
ss.erase(0,pos+del.length());
pos=ss.find(del);
ndx++;
}
if(ndx<7)sections[ndx]=ss;
ss="";
if(sections[1].size()>0) // Architecture
ss+="."+sections[1];
if(sections[2].size()>0) // OSMajorVersion
ss+="."+sections[2];
if(sections[3].size()>0) // OSMinorVersion
ss+="."+sections[3];
if(sections[6].size()>0) // BuildNumber
ss+="..."+sections[6];
strcpy(buf,ss.c_str());
for(int i=0;i<num_decs;i++)if(!_strcmpi(buf+3,nts[i]+2))return i;
return -1;
}
// calculate the inf win version decoration score
int Hwidmatch::calc_decorscore(int id,const State *state)
{
int major,
minor,
build,
arch=state->getArchitecture()+1;
state->getWinVer(&major,&minor,&build);
// id is the index into the nts, nts_version, nts_build, nts_arch, nts_score arrays
if(id<0)return 1;
// for the purposes of matching with the inf file decorator then 11 = 10
if(major==11)major=10;
// if the inf win version is greater than current os then fail
if(nts_version[id]&&major*10+minor<nts_version[id])return 0;
// if the inf win architecture is not current os then fail
if(nts_arch[id]&&arch!=nts_arch[id])return 0;
// starting with 10.0.14310, if major and minor match exactly
// then nts_build is the minimum build number
// https://learn.microsoft.com/en-us/windows-hardware/drivers/install/inf-manufacturer-section
if(nts_version[id]&&nts_version[id]>=100&&nts_build[id]>=14310)
{
if(major*10+minor==nts_version[id]&&nts_build[id]>build)return 0;
}
// return the assigned score
return nts_score[id];
}
int Hwidmatch::calc_markerscore(const State *state,const char *path)
{
char buf[MAX_PATH];
int majver,
minver,
build,
arch=state->getArchitecture(),
curmaj=-1,curmin=-1,curarch=-1;
int i;
int score_l=0;
state->getWinVer(&majver,&minver,&build);
strcpy(buf,path);
strtolower(buf,strlen(buf));
for(i=0;i<num_markers;i++)
{
if(StrStrIA(buf,markers[i].name))
{
score_l=1;
if(markers[i].major==0){continue;}
if(markers[i].major>curmaj)curmaj=markers[i].major;
if(markers[i].minor>curmin)curmin=markers[i].minor;
if(markers[i].arch>curarch)curarch=markers[i].arch;
}
}
/*
+1 if at least one marker specified
+2 if OS version allows
+4 if arch allows
+8 if OS version matches
+16 if arch matches
*/
if(curmaj>=0&&curmin>=0&&majver==curmaj&&minver==curmin)score_l|=8;
if(curmaj>=0&&curmin>=0&&majver>=curmaj&&minver>=curmin)score_l|=2;
if(curmaj<0&&score_l)score_l|=2;
if(curarch>=0&&curarch==arch)score_l|=4+16;
if(curarch<0&&score_l)score_l|=4;
return score_l;
}
//}
//{ Misc
int cmpunsigned(unsigned a,unsigned b)
{
if(a>b)return 1;
if(a<b)return -1;
return 0;
}
//}
//{ Matcher
class MatcherImp:public Matcher
{
State *state=nullptr;
Collection *col=nullptr;
std::vector<Devicematch> devicematch_list;
std::vector<Hwidmatch> hwidmatch_list;
private:
void sort();
public:
~MatcherImp(){}
void findHWIDs(Devicematch *device_match,const wchar_t *hwid,int dev_pos,int ishw);
void init(State *state1,Collection *col1){state=state1;col=col1;devicematch_list.clear();hwidmatch_list.clear();}
void populate();
void print();
void sorta(size_t *v);
int write_device_list(wchar_t *filename);
const wchar_t *finddrp(const wchar_t *s) override{return col->finddrp(s);}
State *getState(){return state;}
Collection *getCol(){return col;}
size_t getDwidmatch_list() { return devicematch_list.size(); }
Devicematch *getDevicematch_i(size_t i){return &devicematch_list[i];}
size_t getHwidmatch_list(){return hwidmatch_list.size();}
void Insert(const Hwidmatch &a){hwidmatch_list.push_back(a);}
Hwidmatch *getHwidmatch_i(size_t i){return &hwidmatch_list[i];}
};
Matcher::~Matcher(){}
Matcher *CreateMatcher()
{
return new MatcherImp();
}
void MatcherImp::findHWIDs(Devicematch *devicematch,const wchar_t *hwidv,int dev_pos,int ishw)
{
// this searches the driver packs for the given hwid
// each index has it's own HashTable
// which will handle hash collisions within an index
// but there is no accounting for possible hash collisions across indices
// so: it's possible for the same hash to show up in different
// indices for different device HWIDs with no collision handling
char hwid[MAX_DEVICE_ID_LEN];
wsprintfA(hwid,"%ws",hwidv);
// calc hash from hwid
size_t sz = strlen(hwid);
strtoupper(hwid,sz);
int code = Hashtable::gethashcode(hwid, sz);
// iterate the driver packs
for(auto &drp:*col->getList())
{
int isfound;
// look for the hash
int val=drp.find((int)code,&isfound);
while(isfound)
{
// found a match - add it to a list
hwidmatch_list.push_back(Hwidmatch(&drp,val,dev_pos,ishw,state,devicematch));
devicematch->num_matches++;
val=drp.findnext(&isfound);
}
}
}
void MatcherImp::sort()
{
Hwidmatch *match1,*match2,*bestmatch;
Hwidmatch matchtmp(nullptr,0);
char sect1[MAX_INF_SECTION_NAME_LENGTH];
for(auto &devicematch:devicematch_list)
{
// Sort
match1=&hwidmatch_list[devicematch.start_matches];
for(unsigned i=0;i+1<devicematch.num_matches;i++,match1++)
{
match2=&hwidmatch_list[devicematch.start_matches+i+1];
bestmatch=match1;
for(unsigned j=i+1;j<devicematch.num_matches;j++,match2++)
if(bestmatch->cmp(match2)<0)bestmatch=match2;
if(bestmatch!=match1)
{
memcpy(&matchtmp,match1,sizeof(Hwidmatch));
memcpy(match1,bestmatch,sizeof(Hwidmatch));
memcpy(bestmatch,&matchtmp,sizeof(Hwidmatch));
}
}
// Mark dups
match1=&hwidmatch_list[devicematch.start_matches];
for(unsigned i=0;i+1<devicematch.num_matches;i++,match1++)
{
match1->getdrp_drvsection(sect1);
match2=&hwidmatch_list[devicematch.start_matches+i+1];
for(unsigned j=i+1;j<devicematch.num_matches;j++,match2++)
if(match1->isdup(match2,sect1))match2->markDup();
}
}
}
void MatcherImp::populate()
{
//Timers.start(time_matcher);
isLaptop=state->isLaptop;
//wcscpy(marker,state->marker);
for(auto &cur_device:*state->getDevices_list())
{
const Driver *cur_driver=state->getCurrentDriver(&cur_device);
devicematch_list.push_back(Devicematch(&cur_device,cur_driver,hwidmatch_list.size(),this));
}
sort();
devicematch_list.shrink_to_fit();
hwidmatch_list.shrink_to_fit();
//Timers.stop(time_matcher);
}
void MatcherImp::print()
{
// dump all the device/matcher info to the log file
int limits[7];
if(Log.isHidden(LOG_VERBOSE_MATCHER))return;
Log.print_file("\n{matcher_print[devices=%d,hwids=%d]\n",devicematch_list.size(),hwidmatch_list.size());
for(auto &devicematch:devicematch_list)
{
devicematch.device->print(state);
Log.print_file("DriverInfo\n");
if(devicematch.driver)
devicematch.driver->print(state);
else
Log.print_file(" NoDriver\n");
memset(limits,0,sizeof(limits));
Hwidmatch *hwidmatch;
hwidmatch=&hwidmatch_list[devicematch.start_matches];
for(unsigned j=0;j<devicematch.num_matches;j++,hwidmatch++)
hwidmatch->calclen(limits);
Log.print_file(" altsectscore | score | date | decorscore | markerscore | status | drvsection | packname | infcrc | inffile | manuf | version | HWID | drvdesc\n");
hwidmatch=&hwidmatch_list[devicematch.start_matches];
for(unsigned j=0;j<devicematch.num_matches;j++,hwidmatch++)
hwidmatch->print_tbl(limits);
Log.print_file("\n");
}
Log.print_file("}matcher_print\n\n");
}
int MatcherImp::write_device_list(wchar_t *filename)
{
if(!System.canWriteFile(filename,L"wt"))
{
Log.print_err("ERROR in write_device_list(): Unwriteable,'%S'\n",filename);
return 1;
}
FILE *f=_wfopen(filename,L"wt");
if(!f)
{
Log.print_err("ERROR in write_device_list(): Failed to open file,'%S'\n",filename);
return 1;
}
wchar_t buffer[1024];
int n;
const Txt *txt=&state->textas;
for(auto &devicematch:devicematch_list)
{
n=wsprintf(buffer,L"[Device]\nName: %s\nDescription: %s\nManufacturer: %s\nHardware ID: %s\nDriver: %s\n\n",
txt->get(devicematch.device->getFriendlyName()),
txt->get(devicematch.device->getDescr()),
txt->get(devicematch.device->getMfg()),
txt->get(devicematch.device->getHardwareID()),
txt->get(devicematch.device->getDriver()));
if(n)
{
fputws(buffer,f);
if(devicematch.driver)
{
n=wsprintf(buffer,L"[Driver]\nDescription: %s\nProvider: %s\nDate: %s\nVersion: %s\nMatching Device ID: %s\nInf Path: %s\nInf Section: %s\n\n",
txt->get(devicematch.driver->getDriverDesc()),
txt->get(devicematch.driver->getProviderName()),
txt->get(devicematch.driver->getDriverDate()),
txt->get(devicematch.driver->getDriverVersion()),
txt->get(devicematch.driver->getMatchingDeviceId()),
txt->get(devicematch.driver->getInfPath()),
txt->get(devicematch.driver->getInfSection()));
if(n)fputws(buffer,f);
}
}
}
fclose(f);
return 0;
}
void MatcherImp::sorta(size_t *v)
{
Devicematch *devicematch_i,*devicematch_j;
Hwidmatch *hwidmatch_i,*hwidmatch_j;
size_t i,j;
size_t num;
num=devicematch_list.size();
for(i=0;i<num;i++)v[i]=i;
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
devicematch_i=&devicematch_list[v[i]];
devicematch_j=&devicematch_list[v[j]];
hwidmatch_i=(devicematch_i->num_matches)?&hwidmatch_list[devicematch_i->start_matches]:nullptr;
hwidmatch_j=(devicematch_j->num_matches)?&hwidmatch_list[devicematch_j->start_matches]:nullptr;
int ismi=devicematch_i->isMissing(state);
int ismj=devicematch_j->isMissing(state);
if(ismi<ismj)
{
size_t t;
t=v[i];
v[i]=v[j];
v[j]=t;
}
else
if(ismi==ismj)
if((hwidmatch_i&&hwidmatch_j&&hwidmatch_i->cmpnames(hwidmatch_j)>0)
||
(!hwidmatch_i&&hwidmatch_j))
{
size_t t;
t=v[i];
v[i]=v[j];
v[j]=t;
}
}
}
}
//}
//{ Devicematch
Devicematch::Devicematch(Device *cur_device,const Driver *cur_driver,size_t items,Matcher *matcher):
start_matches(items),
num_matches(0),
device(cur_device),
driver(cur_driver)
{
// this looks for a matching hardware id in the driver packs
State *state=matcher->getState();
if(device->getHardwareID())
{
// p is the PBYTE pointing to a REG_MULTI_SZ
const wchar_t *p=state->textas.getw(device->getHardwareID());
int dev_pos=0;
// iterate the null terminated strings contained in the REG_MULTI_SZ
while(*p)
{
// look for this hwid string in the index
matcher->findHWIDs(this,p,dev_pos,1);
p+=wcslen(p)+1;
dev_pos++;
}
}
// do the same for CompatibleIDs
if(device->getCompatibleIDs())
{
const wchar_t *p=state->textas.getw(device->getCompatibleIDs());
int dev_pos=0;
while(*p)
{
matcher->findHWIDs(this,p,dev_pos,0);
p+=wcslen(p)+1;
dev_pos++;
}
}
if(num_matches==0)
{
matcher->Insert(Hwidmatch(nullptr,0));
if(isMissing(state))
status=STATUS_NF_MISSING;
else if(driver&&StrStrIW(state->textas.getw(driver->getInfPath()),L"oem"))
status=STATUS_NF_UNKNOWN;
else
status=STATUS_NF_STANDARD;
}
}
const GUID nonPnP={0x8ecc055d,0x047f,0x11d1,{0xa5,0x37,0x00,0x00,0xf8,0x75,0x3e,0xd1}};
int Devicematch::isMissing(const State *state)
{
if(device->getProblem()==CM_PROB_DISABLED)return 0;
if(device->getProblem()&&device->getHardwareID())return 1;
if(!driver)
{
if(StrStrIW(device->getHWIDby(0,state),L"USBPRINT"))return 1;
if(StrStrIW(device->getHWIDby(0,state),L"DOT4PRT"))return 1;
if(StrStrIW(device->getHWIDby(0,state),L"BTHENUM"))return 1;
//if(memcmp(device->getGUID(),&nonPnP,sizeof(GUID)))return 1;
}
if(driver&&!_wcsicmp(state->textas.getw(driver->getMatchingDeviceId()),L"PCI\\CC_0300"))return 1;