-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppControlPolicy.au3
More file actions
1625 lines (1350 loc) · 66.7 KB
/
AppControlPolicy.au3
File metadata and controls
1625 lines (1350 loc) · 66.7 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
#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=AppControl-App.ico
#AutoIt3Wrapper_Outfile_x64=AppControlPolicy.exe
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=App Control Policy Manager
#AutoIt3Wrapper_Res_Fileversion=6.0.3
#AutoIt3Wrapper_Res_ProductVersion=6.0.3
#AutoIt3Wrapper_Res_ProductName=AppControlPolicyManager
#AutoIt3Wrapper_Res_LegalCopyright=@ 2025 WildByDesign
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Res_HiDpi=P
#AutoIt3Wrapper_Res_Icon_Add=AppControl-App.ico
#AutoIt3Wrapper_Res_Icon_Add=unchecked.ico
#AutoIt3Wrapper_Res_Icon_Add=checked.ico
#AutoIt3Wrapper_UseUpx=N
#AutoIt3Wrapper_Compression=0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added Standard Include files by AutoIt3Wrapper ***
#include <Array.au3>
#include <GDIPlus.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiToolTip.au3>
#include <File.au3>
#include <String.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WinAPISysInternals.au3>
#include <WinAPIRes.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIInternals.au3>
#include <WinAPIGdiInternals.au3>
#include <WinAPITheme.au3>
#include <APIResConstants.au3>
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <HeaderConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <StatusBarConstants.au3>
#include <StringConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
; *** End added Standard Include files by AutoIt3Wrapper ***
#include "includes\ExtMsgBox.au3"
#include "includes\GUIDarkMode_v0.02mod.au3"
#include "includes\GUIListViewEx.au3"
#include "includes\XML.au3"
#include "includes\ModernMenuRaw.au3"
#include "includes\_GUICtrlListView_SaveCSV.au3"
#include "includes\libnotif.au3"
Global $programversion = "6.0.1"
If @Compiled = 0 Then
; System aware DPI awareness
;DllCall("User32.dll", "bool", "SetProcessDPIAware")
; Per-monitor V2 DPI awareness
DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -4)
EndIf
isDarkMode()
Func isDarkMode()
Global $isDarkMode = _WinAPI_ShouldAppsUseDarkMode()
Endfunc
If $isDarkMode = True Then
_ExtMsgBoxSet(Default)
;_ExtMsgBoxSet(1, 5, -1, -1, -1, "Consolas", 800, 800)
_ExtMsgBoxSet(1, 4, 0x202020, 0xFFFFFF, 9, -1, 1200)
Else
_ExtMsgBoxSet(Default)
;_ExtMsgBoxSet(1, 5, -1, -1, -1, "Consolas", 800, 800)
_ExtMsgBoxSet(1, 4, -1, -1, 9, -1, 1200)
EndIf
Global $hGUI, $cListView, $hListView, $EFIarray, $hGUI2, $ExitButtonEFI, $EFIListView, $hEFIListView, $PolicyStatusInfo
Global $out, $arpol, $arraycount, $policycount, $policyoutput, $policycorrect, $CountTotal, $ExitButton, $TestButton, $Label2, $aContent, $iLV_Index
Global $CountEnforced = 0
Global $WDACWizardExists
Global Const $SBS_SIZEBOX = 0x08, $SBS_SIZEGRIP = 0x10
$idLightBk = _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_BTNFACE))
If $isDarkMode = True Then
Global $g_iBkColor = 0x2c2c2c, $g_iTextColor = 0xffffff
Else
Global $g_iBkColor = $idLightBk, $g_iTextColor = 0x000000
EndIf
Global $g_hSizebox, $g_hOldProc, $g_hStatus, $g_iHeight, $g_aText, $g_aRatioW, $g_hDots
Local Const $sSegUIVar = @WindowsDir & "\fonts\SegUIVar.ttf"
Local $SegUIVarExists = FileExists($sSegUIVar)
If $SegUIVarExists Then
Global $MainFont = "Segoe UI Variable Display"
;GUISetFont(8.5, $FW_NORMAL, -1, $MainFont)
Else
Global $MainFont = "Segoe UI"
;GUISetFont(8.5, $FW_NORMAL, -1, $MainFont)
EndIf
;---
; configure library
_LibNotif_Config($LIBNOTIF_CFG_TIMEOUT, 10000)
_LibNotif_Config($LIBNOTIF_CFG_MINTOASTWIDTH, 128)
;_LibNotif_Config($LIBNOTIF_CFG_POSITION, $LIBNOTIF_POS_UR)
_LibNotif_Config($LIBNOTIF_CFG_MAXTEXTWIDTH, @DesktopWidth - 100)
_LibNotif_Config($LIBNOTIF_CFG_CLOSEBUTTON, True)
$idLightBk = _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_BTNFACE))
If $isDarkMode = True Then
_LibNotif_Config($LIBNOTIF_CFG_BKCOLOR, 0x202020)
_LibNotif_Config($LIBNOTIF_CFG_TEXTCOLOR, 0xe0e0e0)
Else
_LibNotif_Config($LIBNOTIF_CFG_BKCOLOR, $idLightBk)
_LibNotif_Config($LIBNOTIF_CFG_TEXTCOLOR, 0x000000)
EndIf
_LibNotif_Config($LIBNOTIF_CFG_TEXTFONTNAME, $MainFont)
_LibNotif_Config($LIBNOTIF_CFG_TEXTSIZE, 10)
_LibNotif_Config($LIBNOTIF_CFG_TEXTWEIGHT, 400)
_LibNotif_Config($LIBNOTIF_CFG_TEXTATTRIBUTES, 0)
_LibNotif_Config($LIBNOTIF_CFG_TEXTMARGIN, 15)
_LibNotif_Config($LIBNOTIF_CFG_BUTTONSIZE, 30)
;_LibNotif_Config($LIBNOTIF_CFG_SHOW_ANIMSTYLE, $AW_VER_NEGATIVE)
;_LibNotif_Config($LIBNOTIF_CFG_HIDE_ANIMSTYLE, $AW_VER_POSITIVE + $AW_HIDE)
; init library
_LibNotif_Init()
;---
If $isDarkMode = True Then
Global $iDllGDI = DllOpen("gdi32.dll")
Global $iDllUSER32 = DllOpen("user32.dll")
;Three column colours
Global $aCol[11][2] = [[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff],[0xffffff, 0xffffff]]
;Convert RBG to BGR for SetText/BkColor()
For $i = 0 To UBound($aCol)-1
$aCol[$i][0] = _BGR2RGB($aCol[$i][0])
$aCol[$i][1] = _BGR2RGB($aCol[$i][1])
Next
EndIf
; Fake older build for testing
;Global $WinBuild = "22621"
Global $WinBuild = @OSBuild
If $WinBuild >= 26100 Then
Global $is24H2 = True
;MsgBox($MB_SYSTEMMODAL, "Title", "This is 24H2 or newer")
Else
Global $is24H2 = False
;MsgBox($MB_SYSTEMMODAL, "Title", "This is not 24H2")
EndIf
Global $ifPS7Exists = FileExists(@ProgramFilesDir & '\PowerShell\7\pwsh.exe')
If $ifPS7Exists Then
Global $o_powershell = @ProgramFilesDir & '\PowerShell\7\pwsh.exe -NoProfile -Command'
Else
Global $o_powershell = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command"
EndIf
GetPolicyInfo()
Func GetPolicyInfo()
If $is24H2 = True Then
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
Else
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
; Pre-24H2 Simulation using older CiTool
;Local $o_CmdString1 = " (.\CiTool\22621\CiTool.exe -lp -json | ConvertFrom-Json).Policies | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
EndIf
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
CreatePolicyTable($out)
EndFunc
Func GetPolicyEnforced()
If $is24H2 = True Then
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsEnforced -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
Else
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsEnforced -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
; Pre-24H2 Simulation using older CiTool
;Local $o_CmdString1 = " (.\CiTool\22621\CiTool.exe -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsEnforced -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
EndIf
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
;;;
; Testing in case of parsing issues
;Local Const $sFilePath = @DesktopDir & "\test-output.txt"
;Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
;FileWrite($hFileOpen, $out)
;FileClose($hFileOpen)
;Local Const $sFilePath2 = @DesktopDir & "\test-parsed.txt"
;Local $hFileOpen2 = FileOpen($sFilePath2, $FO_OVERWRITE)
;FileWrite($hFileOpen2, $finalparse)
;FileClose($hFileOpen2)
;;;
CreatePolicyTable($out)
EndFunc
Func GetPolicyBase()
If $is24H2 = True Then
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -eq $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
Else
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -eq $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
; Pre-24H2 Simulation using older CiTool
;Local $o_CmdString1 = " (.\CiTool\22621\CiTool.exe -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -eq $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
EndIf
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
CreatePolicyTable($out)
EndFunc
Func GetPolicySupp()
If $is24H2 = True Then
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -ne $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
Else
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -ne $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
; Pre-24H2 Simulation using older CiTool
;Local $o_CmdString1 = " (.\CiTool\22621\CiTool.exe -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.PolicyID -ne $_.BasePolicyID} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property FriendlyName | FL"
EndIf
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
CreatePolicyTable($out)
EndFunc
Func GetPolicySigned()
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsSignedPolicy -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
CreatePolicyTable($out)
EndFunc
Func GetPolicySystem()
If $is24H2 = True Then
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsSystemPolicy -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,VersionString,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
Else
Local $o_CmdString1 = " (CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsSystemPolicy -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
; Pre-24H2 Simulation using older CiTool
;Local $o_CmdString1 = " (.\CiTool\22621\CiTool.exe -lp -json | ConvertFrom-Json).Policies | Where-Object {$_.IsSystemPolicy -eq 'True'} | Select-Object -Property IsEnforced,FriendlyName,PolicyID,BasePolicyID,Version,IsOnDisk,IsSignedPolicy,IsSystemPolicy,IsAuthorized,PolicyOptions | Sort-Object -Descending -Property IsEnforced | Sort-Object -Property BasePolicyID,FriendlyName | FL"
EndIf
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
CreatePolicyTable($out)
EndFunc
Func CreatePolicyTable($out_passed)
If $is24H2 = True Then
Local $string0 = StringStripWS($out_passed, $STR_STRIPSPACES + $STR_STRIPLEADING + $STR_STRIPTRAILING)
Local $string1 = StringReplace($string0, "FriendlyName : ", "")
Local $string2 = StringReplace($string1, "BasePolicyID : ", "")
Local $string3 = StringReplace($string2, "PolicyID : ", "")
Local $string4 = StringReplace($string3, "VersionString : ", "")
Local $string5 = StringReplace($string4, "IsEnforced : ", "")
Local $string6 = StringReplace($string5, "IsOnDisk : ", "")
Local $string7 = StringReplace($string6, "IsSignedPolicy : ", "")
Local $string8 = StringReplace($string7, "IsSystemPolicy : ", "")
Local $string9 = StringReplace($string8, "IsAuthorized : ", "")
Local $string10 = StringReplace($string9, "PolicyOptions : ", "")
Local $string11 = StringReplace($string10, "[32;1m", "")
Local $string12 = StringReplace($string11, "[0m", "")
Local $string13 = StringReplace($string12, "{", "")
Local $string14 = StringReplace($string13, "}", "")
Local $string15 = StringReplace($string14, "Version : ", "")
Local $string16 = StringReplace($string15, "...", "")
Local $string17 = StringReplace($string16, "Default Policy.", "Default Policy")
Local $string18 = StringReplace($string17, "Integrity Policy.", "Integrity Policy")
Local $string19 = StringReplace($string18, "Supplemental Policies.", "Supplemental Policies")
Local $string20 = StringReplace($string19, "Code Trust.", "Code Trust")
Local $string21 = StringReplace($string20, "Rule Protection.", "Rule Protection")
Local $finalparse = $string21
Else
;Local $string0 = StringStripWS($out_passed, $STR_STRIPSPACES + $STR_STRIPLEADING + $STR_STRIPTRAILING)
Local $string0 = StringStripWS($out_passed, $STR_STRIPLEADING + $STR_STRIPTRAILING)
Local $string1 = StringReplace($string0, "FriendlyName : ", "")
Local $string2 = StringReplace($string1, "BasePolicyID : ", "")
Local $string3 = StringReplace($string2, "PolicyID : ", "")
Local $string4 = StringReplace($string3, "VersionString : ", "*")
Local $string5 = StringReplace($string4, "IsEnforced : ", "")
Local $string6 = StringReplace($string5, "IsOnDisk : ", "")
Local $string7 = StringReplace($string6, "IsSignedPolicy : ", "*")
Local $string8 = StringReplace($string7, "IsSystemPolicy : ", "")
Local $string9 = StringReplace($string8, "IsAuthorized : ", "")
Local $string10 = StringReplace($string9, "PolicyOptions : ", "*")
Local $string11 = StringReplace($string10, "[32;1m", "")
Local $string12 = StringReplace($string11, "[0m", "")
Local $string13 = StringReplace($string12, "{", "")
Local $string14 = StringReplace($string13, "}", "")
Local $string15 = StringReplace($string14, "Version : ", "")
Local $string16 = StringStripWS($string15, $STR_STRIPSPACES)
Local $string17 = StringReplace($string16, "PolicyOptions :", "*")
Local $string18 = StringReplace($string17, "...", "")
Local $string19 = StringReplace($string18, "Default Policy.", "Default Policy")
Local $string20 = StringReplace($string19, "Integrity Policy.", "Integrity Policy")
Local $string21 = StringReplace($string20, "Supplemental Policies.", "Supplemental Policies")
Local $string22 = StringReplace($string21, "Code Trust.", "Code Trust")
Local $string23 = StringReplace($string22, "Rule Protection.", "Rule Protection")
Local $finalparse = $string23
EndIf
;MsgBox($MB_SYSTEMMODAL, "Title", "Final parse = " & $finalparse)
;;;
; Testing in case of parsing issues
;Local Const $sFilePath = @DesktopDir & "\test-output.txt"
;Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
;FileWrite($hFileOpen, $out_passed)
;FileClose($hFileOpen)
;Local Const $sFilePath2 = @DesktopDir & "\test-parsed.txt"
;Local $hFileOpen2 = FileOpen($sFilePath2, $FO_OVERWRITE)
;FileWrite($hFileOpen2, $finalparse)
;FileClose($hFileOpen2)
;;;
If $finalparse = "" Then
Global $policycount = 0
Else
$arpol = stringsplit($finalparse, @CR , 0)
;_ArrayDisplay($arpol, "test")
Global $policyoutput = UBound ($arpol, $UBOUND_ROWS)
Global $policycorrect = $policyoutput - 1
Global $policycount = $policycorrect / 10
EndIf
; create policy array (pixelsearch)
; support more policies by increasing $policycount <= 64
Select
Case $policycount = 0
Global $aWords[1][11]
Case IsInt($policycount) And $policycount >= 1 And $policycount <= 64
Global $aWords[$policycount][11]
For $i = 0 To $policycount - 1
For $j = 1 To 10
$aWords[$i][$j] = $arpol[$i*10 + $j]
Next
Next
Case Else
Global $aWords[1][11] = [["", "Error:", "Error " & $policycorrect & " &" & " Error " & $policycount, "", "", "", "", "", "", "", ""]]
EndSelect
If $is24H2 = False Then
For $i = 0 To UBound($aWords) -1
$iVersion = $aWords[$i][5]
Local $tUInt64 = DllStructCreate("uint64 value;"), _
$tVersion = DllStructCreate("word revision; word build; word minor; word major", DllStructGetPtr($tUInt64))
$tUInt64.value = $iVersion
Local $iVersionString = StringFormat('%i.%i.%i.%i', $tVersion.major, $tVersion.minor, $tVersion.build, $tVersion.revision)
$aWords[$i][5] = $iVersionString
Next
EndIf
Endfunc
VulnerableDriver()
Func VulnerableDriver()
Local $sVulnDriver = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnable")
If $sVulnDriver = '1' Then
Global $sVulnDrivermsg = " Vulnerable Driver Blocklist : Enabled"
ElseIf $sVulnDriver = '0' Then
Global $sVulnDrivermsg = " Vulnerable Driver Blocklist : Disabled"
Else
Global $sVulnDrivermsg = " Vulnerable Driver Blocklist : Unknown"
EndIf
Endfunc
;GetPolicyStatus()
Func GetPolicyStatus()
Local $sSmartAppControl = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Policy", "VerifiedAndReputablePolicyState")
If $sSmartAppControl = 0 Then
$sSACStatus = " Smart App Control (Off)"
ElseIf $sSmartAppControl = 1 Then
$sSACStatus = " Smart App Control (Enforced)"
ElseIf $sSmartAppControl = 2 Then
$sSACStatus = " Smart App Control (Evaluation)"
Else
$sSACStatus = " Smart App Control (undetermined)"
EndIf
Local $sVulnerableDriver = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnable")
If $sVulnerableDriver = 0 Then
$sVDriverStatus = "Vulnerable Driver Blocklist (Disabled)"
ElseIf $sVulnerableDriver = 1 Then
$sVDriverStatus = "Vulnerable Driver Blocklist (Enabled)"
Else
$sVDriverStatus = "Vulnerable Driver Blocklist (undetermined)"
EndIf
Local $o_CmdString1 = " Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard | FL *codeintegrity*"
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
Local $topstatus1 = StringReplace($out, "[32;1m", "")
Local $topstatus2 = StringReplace($topstatus1, "[0m", "")
Local $topstatus3 = StringReplace($topstatus2, "UsermodeCodeIntegrityPolicyEnforcementStatus : 0", "User Mode Code Integrity " & "(Not Configured)")
Local $topstatus4 = StringReplace($topstatus3, "UsermodeCodeIntegrityPolicyEnforcementStatus : 1", "User Mode Code Integrity " & "(Audit)")
Local $topstatus5 = StringReplace($topstatus4, "UsermodeCodeIntegrityPolicyEnforcementStatus : 2", "User Mode Code Integrity " & "(Enforced)")
Local $topstatus6 = StringReplace($topstatus5, "CodeIntegrityPolicyEnforcementStatus : 0", "Kernel Mode Code Integrity " & "(Not Configured)")
Local $topstatus7 = StringReplace($topstatus6, "CodeIntegrityPolicyEnforcementStatus : 1", "Kernel Mode Code Integrity " & "(Audit)")
Local $topstatus8 = StringReplace($topstatus7, "CodeIntegrityPolicyEnforcementStatus : 2", "Kernel Mode Code Integrity " & "(Enforced)")
Global $topstatus9 = StringStripWS($topstatus8, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)
Local $aPolicyStatus = StringSplit($topstatus9, @CR)
Global $CurrentPolicyStatus = $sVDriverStatus & " | " & $sSACStatus & " | " & $aPolicyStatus[1] & " | " & $aPolicyStatus[2]
; update status bar parts with current info
;
; update smart app control status
$g_aText[0] = $sSACStatus
; update vulnerable driver blocklist status
$g_aText[1] = $sVDriverStatus
; update user mode code integrity status
$g_aText[2] = $aPolicyStatus[2]
; update kernel mode code integrity status
$g_aText[3] = $aPolicyStatus[1]
; redraw status bar to update values
_WinAPI_RedrawWindow($g_hStatus)
Endfunc
Func GetPolicyStatus_old()
Local $o_CmdString1 = " Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard | FL *codeintegrity*"
Local $o_Pid = Run($o_powershell & $o_CmdString1 , "", @SW_Hide, $STDOUT_CHILD)
ProcessWaitCloseEx($o_Pid)
$out = StdoutRead($o_Pid)
Local $topstatus1 = StringReplace($out, "[32;1m", "")
Local $topstatus2 = StringReplace($topstatus1, "[0m", "")
Local $topstatus3 = StringReplace($topstatus2, "UsermodeCodeIntegrityPolicyEnforcementStatus : 0", " App Control user mode policy : " & "Not Configured ")
Local $topstatus4 = StringReplace($topstatus3, "UsermodeCodeIntegrityPolicyEnforcementStatus : 1", " App Control user mode policy : " & "Audit Mode ")
Local $topstatus5 = StringReplace($topstatus4, "UsermodeCodeIntegrityPolicyEnforcementStatus : 2", " App Control user mode policy : " & "Enforced Mode ")
Local $topstatus6 = StringReplace($topstatus5, "CodeIntegrityPolicyEnforcementStatus : 0", "App Control policy : " & "Not Configured ")
Local $topstatus7 = StringReplace($topstatus6, "CodeIntegrityPolicyEnforcementStatus : 1", "App Control policy : " & "Audit Mode ")
Local $topstatus8 = StringReplace($topstatus7, "CodeIntegrityPolicyEnforcementStatus : 2", "App Control policy : " & "Enforced Mode ")
Global $topstatus9 = StringStripWS($topstatus8, $STR_STRIPLEADING + $STR_STRIPTRAILING)
;MsgBox($MB_SYSTEMMODAL, "Title", $topstatus9)
Endfunc
_GDIPlus_Startup()
;Global $iW = @DesktopWidth - 420, $iH = $hGUIHeight + 200
Global $iW = @DesktopWidth / 1.5, $iH = @DesktopHeight / 2
$hGUI = GUICreate("App Control Policy Manager", $iW, $iH, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)
$aWinSize = WinGetClientSize($hGUI)
GUISetIcon(@ScriptFullPath, 201)
$SBARPartSize = $iW / 4
;GUISetBkColor($g_iBkColor)
;-----------------
; Create a sizebox window (Scrollbar class) BEFORE creating the StatusBar control
$g_hSizebox = _WinAPI_CreateWindowEx(0, "Scrollbar", "", $WS_CHILD + $WS_VISIBLE + $SBS_SIZEBOX, _
0, 0, 0, 0, $hGUI) ; $SBS_SIZEBOX or $SBS_SIZEGRIP
; Subclass the sizebox (by changing the window procedure associated with the Scrollbar class)
Local $hProc = DllCallbackRegister('ScrollbarProc', 'lresult', 'hwnd;uint;wparam;lparam')
$g_hOldProc = _WinAPI_SetWindowLong($g_hSizebox, $GWL_WNDPROC, DllCallbackGetPtr($hProc))
Local $hCursor = _WinAPI_LoadCursor(0, $OCR_SIZENWSE)
_WinAPI_SetClassLongEx($g_hSizebox, -12, $hCursor) ; $GCL_HCURSOR = -12
;$g_hBrush = _WinAPI_CreateSolidBrush($g_iBkColor)
;-----------------
$g_hStatus = _GUICtrlStatusBar_Create($hGUI, -1, "", $WS_CLIPSIBLINGS) ; ClipSiblings style +++
Local $aParts[4] = [$SBARPartSize - 50, ($SBARPartSize * 2) - 50, ($SBARPartSize * 3) - 20, -1]
If $aParts[Ubound($aParts) - 1] = -1 Then $aParts[Ubound($aParts) - 1] = $iW ; client width size
_MyGUICtrlStatusBar_SetParts($g_hStatus, $aParts)
Dim $g_aText[Ubound($aParts)] = [" Smart App Control ()", "Vulnerable Driver Blocklist ()", "User Mode Code Integrity ()", "Kernel Mode Code Integrity ()"]
Dim $g_aRatioW[Ubound($aParts)]
For $i = 0 To UBound($g_aText) - 1
_GUICtrlStatusBar_SetText($g_hStatus, "", $i, $SBT_OWNERDRAW + $SBT_NOBORDERS)
; _GUICtrlStatusBar_SetText($g_hStatus, "", $i, $SBT_OWNERDRAW + $SBT_NOBORDERS) ; interesting ?
$g_aRatioW[$i] = $aParts[$i] / $iW
Next
; get status bar height for GUI and listview height
$StatusBarCtrlID = _WinAPI_GetDlgCtrlID($g_hStatus)
$aPos = ControlGetPos($hGUI, "", $StatusBarCtrlID)
$StatusBarCtrlIDV = $aPos[1]
$StatusBarCtrlIDHeight = $aPos[3]
$aGUI_Pos = WinGetPos($hGUI)
$aGUI_ClientSize = WinGetClientSize($hGUI)
$iCaptionHeight = $aGUI_Pos[3] - $aGUI_ClientSize[1]
If $isDarkMode = True Then
_SetMenuBkColor(0x2c2c2c)
_SetMenuTextColor(0xffffff)
_SetMenuSelectTextColor(0xffffff)
_SetMenuSelectBkColor(0x404040)
_SetMenuSelectRectColor(0x404040)
_SetMenuIconBkColor(0x2c2c2c)
_SetMenuIconBkGrdColor(0x2c2c2c)
Else
_SetMenuBkColor($idLightBk)
_SetMenuTextColor(0x000000)
_SetMenuSelectTextColor(0x000000)
_SetMenuSelectBkColor(0xf5cba7)
_SetMenuSelectRectColor(0xf5cba7)
_SetMenuIconBkColor($idLightBk)
_SetMenuIconBkGrdColor($idLightBk)
EndIf
Local $iFileMenu5 = _GUICtrlCreateODTopMenu( "&File", $hGui )
Local $iFileMenu4 = _GUICtrlCreateODTopMenu( "&Logs", $hGui )
Local $iFileMenu3 = _GUICtrlCreateODTopMenu( "&Tools", $hGui )
Local $iFileMenu = _GUICtrlCreateODTopMenu( "&Policy Actions", $hGui )
Local $iFileMenu2 = _GUICtrlCreateODTopMenu( "&Filtering Options", $hGui )
If $isDarkMode = True Then
$menuPolicyAddUpdate = GUICtrlCreateMenuItem( "Add or Update Policies", $iFileMenu)
$menuPolicyRemove = GUICtrlCreateMenuItem( "Remove Checked Policies", $iFileMenu)
$menuPolicyConvert = GUICtrlCreateMenuItem( "Convert XML to Binary", $iFileMenu)
$menuPolicyRefresh = GUICtrlCreateMenuItem( "Refresh Policy List", $iFileMenu)
$menuFilterEnforced = GUICtrlCreateMenuItem( "Enforced Policies", $iFileMenu2)
$menuFilterBase = GUICtrlCreateMenuItem( "Base Policies", $iFileMenu2)
$menuFilterSupp = GUICtrlCreateMenuItem( "Supplemental Policies", $iFileMenu2)
$menuFilterSigned = GUICtrlCreateMenuItem( "Signed Policies", $iFileMenu2)
; disable filtering by Signed policies on pre-24H2 systems
If $is24H2 = False Then GUICtrlSetState($menuFilterSigned, $GUI_DISABLE)
$menuFilterSystem = GUICtrlCreateMenuItem( "System Policies", $iFileMenu2)
$menuEFIPartition = GUICtrlCreateMenuItem( "EFI Partition", $iFileMenu2)
$menuFilterReset = GUICtrlCreateMenuItem( "Reset", $iFileMenu2)
$menuAppWizard = GUICtrlCreateMenuItem( "App Control Wizard", $iFileMenu3)
$menuMsInfo32 = GUICtrlCreateMenuItem( "System Information", $iFileMenu3)
$menuLogsCI = GUICtrlCreateMenuItem( "Code Integrity", $iFileMenu4)
$menuLogsScript = GUICtrlCreateMenuItem( "MSI and Script", $iFileMenu4)
$menuExportCSV = GUICtrlCreateMenuItem( "Export as CSV", $iFileMenu5)
$menuFileExit = GUICtrlCreateMenuItem( "Exit", $iFileMenu5)
Else
$menuPolicyAddUpdate = _GUICtrlCreateODMenuItem( "Add or Update Policies", $iFileMenu)
$menuPolicyRemove = _GUICtrlCreateODMenuItem( "Remove Checked Policies", $iFileMenu)
$menuPolicyConvert = _GUICtrlCreateODMenuItem( "Convert XML to Binary", $iFileMenu)
$menuPolicyRefresh = _GUICtrlCreateODMenuItem( "Refresh Policy List", $iFileMenu)
$menuFilterEnforced = _GUICtrlCreateODMenuItem( "Enforced Policies", $iFileMenu2)
$menuFilterBase = _GUICtrlCreateODMenuItem( "Base Policies", $iFileMenu2)
$menuFilterSupp = _GUICtrlCreateODMenuItem( "Supplemental Policies", $iFileMenu2)
$menuFilterSigned = _GUICtrlCreateODMenuItem( "Signed Policies", $iFileMenu2)
; disable filtering by Signed policies on pre-24H2 systems
If $is24H2 = False Then GUICtrlSetState($menuFilterSigned, $GUI_DISABLE)
$menuFilterSystem = _GUICtrlCreateODMenuItem( "System Policies", $iFileMenu2)
$menuEFIPartition = _GUICtrlCreateODMenuItem( "EFI Partition", $iFileMenu2)
$menuFilterReset = _GUICtrlCreateODMenuItem( "Reset", $iFileMenu2)
$menuAppWizard = _GUICtrlCreateODMenuItem( "App Control Wizard", $iFileMenu3)
$menuMsInfo32 = _GUICtrlCreateODMenuItem( "System Information", $iFileMenu3)
$menuLogsCI = _GUICtrlCreateODMenuItem( "Code Integrity", $iFileMenu4)
$menuLogsScript = _GUICtrlCreateODMenuItem( "MSI and Script", $iFileMenu4)
$menuExportCSV = _GUICtrlCreateODMenuItem( "Export as CSV", $iFileMenu5)
$menuFileExit = _GUICtrlCreateODMenuItem( "Exit", $iFileMenu5)
EndIf
$aGUI_ClientSizeLV = WinGetClientSize($hGUI)
Local Const $sCascadiaPath = @WindowsDir & "\fonts\CascadiaCode.ttf"
Local $iCascadiaExists = FileExists($sCascadiaPath)
If $iCascadiaExists Then
GUISetFont(10, $FW_NORMAL, -1, "Cascadia Mono")
Else
GUISetFont(10, $FW_NORMAL, -1, "Consolas")
EndIf
Local $hToolTip2 = _GUIToolTip_Create(0)
;_GUIToolTip_SetMaxTipWidth($hToolTip2, 400)
If $isDarkMode = True Then
_WinAPI_SetWindowTheme($hToolTip2, "", "")
_GUIToolTip_SetTipBkColor($hToolTip2, 0x202020)
_GUIToolTip_SetTipTextColor($hToolTip2, 0xe0e0e0)
Else
_WinAPI_SetWindowTheme($hToolTip2, "", "")
_GUIToolTip_SetTipBkColor($hToolTip2, 0xffffff)
_GUIToolTip_SetTipTextColor($hToolTip2, 0x000000)
EndIf
_GUIToolTip_SetMaxTipWidth($hToolTip2, 260)
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER), $cListView
$cListView = GUICtrlCreateListView("|Enforced|Policy Name|Policy ID|Base Policy ID|Version|On Disk|Signed Policy|System Policy|Authorized|Policy Options", 0, 0, $aWinSize[0], $aGUI_ClientSizeLV[1] - $StatusBarCtrlIDHeight)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
_GUICtrlListView_AddArray($hListView,$aWords)
; header text fix for dark mode
HeaderFix()
Func HeaderFix()
If $isDarkMode = True Then
;get handle to child SysHeader32 control of ListView
Global $hHeader = HWnd(GUICtrlSendMsg($cListView, $LVM_GETHEADER, 0, 0))
;Turn off theme for header
DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
;subclass ListView to get at NM_CUSTOMDRAW notification sent to ListView
Global $wProcNew = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
Global $wProcOld = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
;Optional: Flat Header - remove header 3D button effect
Global $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
_WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT))
EndIf
Endfunc
CountTotal()
Func CountTotal()
Global $CountTotal = 0
Global $CountTotal = _GUICtrlListView_GetItemCount($cListView)
;ConsoleWrite("Count = " & $CountEnforced & @CRLF)
;MsgBox($MB_SYSTEMMODAL, "Title", "Count = " & $CountEnforced)
Endfunc
CountEnforced()
Func CountEnforced()
Global $CountEnforced = 0
For $I = 0 To _GUICtrlListView_GetItemCount($cListView) - 1
$Array = _GUICtrlListView_GetItemTextArray($cListView, $I)
If $Array[2] = "True" Then $CountEnforced += 1
Next
;ConsoleWrite("Count = " & $CountEnforced & @CRLF)
;MsgBox($MB_SYSTEMMODAL, "Title", "Count = " & $CountEnforced)
Endfunc
;UpdatePolicyStatus()
Func UpdatePolicyStatus()
Global $PolicyStatusInfo = " " & $topstatus9 & @CRLF & @CRLF & $sVulnDrivermsg & @CRLF & @CRLF & " Policies (total) : " & $CountTotal & @CRLF & " Policies (enforced) : " & $CountEnforced
EndFunc
$PolicyStatus = GUICtrlCreateLabel($PolicyStatusInfo, 100, 100, -1, -1, $WS_BORDER + $SS_LEFTNOWORDWRAP)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT + $GUI_DOCKLEFT)
GUICtrlSetState($PolicyStatus, $GUI_HIDE)
; Read ListView content into an array
$aContent = _GUIListViewEx_ReadToArray($cListView)
If $isDarkMode = True Then
;$hImageList = _GUICtrlListView_GetImageList($hListView, 2)
EndIf
ApplyThemeColor()
Func ApplyThemeColor()
If $isDarkMode = True Then
GuiDarkmodeApply($hGUI)
Else
Local $bEnableDarkTheme = False
GuiLightmodeApply($hGUI)
EndIf
Endfunc
If $isDarkMode = True Then
$hImageList = _GUICtrlListView_GetImageList($hListView, 2)
_GUIImageList_Remove($hImageList)
If @Compiled = 0 Then
_GUIImageList_AddIcon($hImageList, "unchecked.ico")
_GUIImageList_AddIcon($hImageList, "checked.ico")
Else
_GUIImageList_AddIcon($hImageList, @ScriptFullPath, 3)
_GUIImageList_AddIcon($hImageList, @ScriptFullPath, 4)
EndIf
EndIf
; Initiate ListView
$iLV_Index = _GUIListViewEx_Init($cListView, $aContent, 0, Default, False, 1)
; Register required messages
_GUIListViewEx_MsgRegister()
hListViewRefreshColWidth()
Func hListViewRefreshColWidth()
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
If $policycount = 0 Then
_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE_USEHEADER)
Else
_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 4, $LVSCW_AUTOSIZE)
EndIf
;_GUICtrlListView_SetColumnWidth($hListView, 5, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 5, $LVSCW_AUTOSIZE)
Local $aTmp1 = _GUICtrlListView_GetColumn($hListView, 5)
_GUICtrlListView_SetColumnWidth($hListView, 5, $LVSCW_AUTOSIZE_USEHEADER)
Local $aTmp2 = _GUICtrlListView_GetColumn($hListView, 5)
If $aTmp1[4] < $aTmp2[4] Then _GUICtrlListView_SetColumnWidth($hListView, 5, $LVSCW_AUTOSIZE_USEHEADER)
If $aTmp1[4] > $aTmp2[4] Then _GUICtrlListView_SetColumnWidth($hListView, 5, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 6, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 7, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 8, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 9, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 10, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlSendMsg( $cListView, $WM_CHANGEUISTATE, 65537, 0 )
EndFunc
; to allow the setting of StatusBar BkColor at least under Windows 10
_WinAPI_SetWindowTheme($g_hStatus, "", "")
; Set status bar background color
_GUICtrlStatusBar_SetBkColor($g_hStatus, $g_iBkColor)
;$g_iHeight = _GUICtrlStatusBar_GetHeight($g_hStatus) + 3 ; change the constant (+3) if necessary
$g_iHeight = $StatusBarCtrlIDHeight
$g_hDots = CreateDots($g_iHeight, $g_iHeight, 0xFF000000 + $g_iBkColor, 0xFF000000 + $g_iTextColor)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_MOVE, "WM_MOVE")
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GetPolicyStatus()
GUISetState()
Example()
Func Example()
Local $aWindow_Size = WinGetPos($hGUI)
ConsoleWrite('X position = ' & $aWindow_Size[0] & @CRLF)
ConsoleWrite('Y position = ' & $aWindow_Size[1] & @CRLF)
ConsoleWrite('Window Width = ' & $aWindow_Size[2] & @CRLF)
ConsoleWrite('Window Height = ' & $aWindow_Size[3] & @CRLF)
Local $aWindowClientArea_Size = WinGetClientSize($hGUI)
ConsoleWrite('Window Client Area Width = ' & $aWindowClientArea_Size[0] & @CRLF)
ConsoleWrite('Window Client Area Height = ' & $aWindowClientArea_Size[1] & @CRLF)
EndFunc ;==>Example
#cs
WinMove($hGUI,'',(@Desktopwidth - WinGetPos($hGUI)[2]) / 2,(@Desktopheight - WinGetPos($hGUI)[3]) / 2, @DesktopWidth - 420 + 6, $GUIHeightMeasured + 6)
;Sleep(500)
;GUISetState()
GUISetStyle($GUI_SS_DEFAULT_GUI, -1)
WinMove($hGUI,'', (@Desktopwidth - WinGetPos($hGUI)[2]) / 2,(@Desktopheight - WinGetPos($hGUI)[3]) / 2)
GUISetState(@SW_SHOWMINIMIZED)
GUISetState(@SW_RESTORE)
WinSetOnTop($hGUI, "", $WINDOWS_ONTOP)
WinSetOnTop($hGUI, "", $WINDOWS_NOONTOP)
#ce
WDACWizardExists()
;GUISetState(@SW_SHOW)
Func _LVWndProc($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
If $iMsg = $WM_NOTIFY Then
Local $tNMHDR, $hWndFrom, $iCode, $iItem, $hDC
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
;Local $IDFrom = DllStructGetData($tNMHDR, "IDFrom")
Switch $hWndFrom
Case $hHeader
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Switch DllStructGetData($tCustDraw, "dwDrawStage")
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
$hDC = DllStructGetData($tCustDraw, "hDC")
$iItem = DllStructGetData($tCustDraw, "dwItemSpec")
DllCall($iDllGDI, "int", "SetTextColor", "handle", $hDC, "dword", $aCol[$iItem][0])
DllCall($iDllGDI, "int", "SetBkColor", "handle", $hDC, "dword", $aCol[$iItem][1])
Return $CDRF_NEWFONT
Return $CDRF_SKIPDEFAULT
EndSwitch
EndSwitch
EndSwitch
EndIf
;pass the unhandled messages to default WindowProc
Local $aResult = DllCall($iDllUSER32, "lresult", "CallWindowProcW", "ptr", $wProcOld, _
"hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
If @error Then Return -1
Return $aResult[0]
EndFunc ;==>_LVWndProc
Func _BGR2RGB($iColor)
;Author: Wraithdu
Return BitOR(BitShift(BitAND($iColor, 0x0000FF), -16), BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc ;==>_BGR2RGB
Func AddPolicies()
Local $spFile
$mFile = FileOpenDialog("Select Policy File(s) to Add or Update", @ScriptDir, "Policy Files (*.cip)", 1 + 4 )
If @error Then
ConsoleWrite("error")
Else
$spFile = StringSplit($mFile, "|")
If UBound($spFile) = 2 Then
$path = $spFile[1]
_ArrayDelete($spFile, 0)
Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
Local $aPathSplit = _PathSplit($spFile[0], $sDrive, $sDir, $sFileName, $sExtension)
Local $cmd1 = ' (citool.exe -up '
Local $cmd2 = '"'
Local $cmd3 = $aPathSplit[3]
Local $cmd4 = $aPathSplit[4]
Local $cmd5 = '"'
Local $cmd6 = ' -json)'
Run(@ComSpec & " /c " & $cmd1 & $cmd2 & $cmd3 & $cmd4 & $cmd5 & $cmd6, "", @SW_HIDE)
$sMsg = "Selected policy has been added." & @CRLF
$sMsg &= "" & @CRLF
$sMsg &= "The policy list and status information will automatically" & @CRLF
$sMsg &= "refresh in about 5 seconds."
;_ExtMsgBox (0 & ";" & @ScriptDir & "\AppControlManager.exe", 0, "App Control Policy Manager", $sMsg)
_LibNotif_Notif($sMsg)
Sleep(5000)
_GUICtrlListView_DeleteAllItems($cListView)
GetPolicyInfo()
GetPolicyStatus()
_GUICtrlListView_AddArray($hListView,$aWords)
CountTotal()
CountEnforced()
UpdatePolicyStatus()
hListViewRefreshColWidth()
GUICtrlSetData($PolicyStatus, $PolicyStatusInfo)
Else
$path = $spFile[1]
_ArrayDelete($spFile, 0)
_ArrayDelete($spFile, 0)
For $x = 0 to UBound($spFile)-1
Local $cmd1 = ' (citool.exe -up '
Local $cmd2 = '"'
Local $cmd3 = $spFile[$x]
Local $cmd4 = '"'
Local $cmd5 = ' -json)'
Run(@ComSpec & " /c " & $cmd1 & $cmd2 & $cmd3 & $cmd4 & $cmd5, "", @SW_HIDE)
Next
$sMsg = "Selected policies have been added." & @CRLF
$sMsg &= "" & @CRLF
$sMsg &= "The policy list and status information will automatically" & @CRLF
$sMsg &= "refresh in about 5 seconds."
;_ExtMsgBox (0 & ";" & @ScriptDir & "\AppControlManager.exe", 0, "App Control Policy Manager", $sMsg)
_LibNotif_Notif($sMsg)
Sleep(5000)
_GUICtrlListView_DeleteAllItems($cListView)
GetPolicyInfo()
GetPolicyStatus()
_GUICtrlListView_AddArray($hListView,$aWords)
CountTotal()
CountEnforced()
UpdatePolicyStatus()
hListViewRefreshColWidth()
GUICtrlSetData($PolicyStatus, $PolicyStatusInfo)
EndIf
EndIf
EndFunc
Func LogsCI()
$oXML=ObjCreate("Microsoft.XMLDOM")
$stest = FileRead(@AppDataDir & "\Microsoft\MMC\eventvwr")
$oXML.LoadXML($stest)
If Not _XML_NodeExists($oXML, "//DynamicPath") Then
Run(@ComSpec & " /c " & 'eventvwr /c:"Microsoft-Windows-CodeIntegrity/Operational"', "", @SW_HIDE)
Else
$oXMLChild1 = $oXML.selectSingleNode( "//DynamicPath" )
$parent = $oXMLChild1.ParentNode
$test = $parent.removeChild ( $oXMLChild1 )
$oXML.Save(@AppDataDir & "\Microsoft\MMC\eventvwr")
Sleep(500)
Run(@ComSpec & " /c " & 'eventvwr /c:"Microsoft-Windows-CodeIntegrity/Operational"', "", @SW_HIDE)
EndIf
Endfunc
Func LogsScript()
$oXML=ObjCreate("Microsoft.XMLDOM")
$stest = FileRead(@AppDataDir & "\Microsoft\MMC\eventvwr")
$oXML.LoadXML($stest)
If Not _XML_NodeExists($oXML, "//DynamicPath") Then
Run(@ComSpec & " /c " & 'eventvwr /c:"Microsoft-Windows-AppLocker/MSI and Script"', "", @SW_HIDE)
Else
$oXMLChild1 = $oXML.selectSingleNode( "//DynamicPath" )
$parent = $oXMLChild1.ParentNode
$test = $parent.removeChild ( $oXMLChild1 )
$oXML.Save(@AppDataDir & "\Microsoft\MMC\eventvwr")
Sleep(500)
Run(@ComSpec & " /c " & 'eventvwr /c:"Microsoft-Windows-AppLocker/MSI and Script"', "", @SW_HIDE)
EndIf
Endfunc
Func About()
_ExtMsgBox (0 & ";" & @ScriptDir & "\AppControlManager.exe", 0, "App Control Policy Manager", " Version: " & $programversion & @CRLF & _
" Created by: " & "WildByDesign" & @CRLF & @CRLF & _
" This program is free and open source. " & @CRLF)
Endfunc