-
Notifications
You must be signed in to change notification settings - Fork 0
/
XFlags.ps1
860 lines (723 loc) · 33.6 KB
/
XFlags.ps1
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
# Check administrator privileges
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell "-File `"$PSCommandPath`"" -Verb RunAs
exit
}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
function Console {
param ([Switch]$Show, [Switch]$Hide)
if (-not ("Console.Window" -as [type])) {
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
}
if ($Show) {
$consolePtr = [Console.Window]::GetConsoleWindow()
$null = [Console.Window]::ShowWindow($consolePtr, 5)
}
if ($Hide) {
$consolePtr = [Console.Window]::GetConsoleWindow()
$null = [Console.Window]::ShowWindow($consolePtr, 0)
}
}
# Flags
$flags = @(
@{Name = "FLG_STOP_ON_EXCEPTION"; Description = "Stop on exception"; Abbreviation = "soe"; Hex = 0x01},
@{Name = "FLG_SHOW_LDR_SNAPS"; Description = "Show loader snaps"; Abbreviation = "sls"; Hex = 0x02},
@{Name = "FLG_DEBUG_INITIAL_COMMAND"; Description = "Debug initial command"; Abbreviation = "dic"; Hex = 0x04},
@{Name = "FLG_HEAP_ENABLE_FREE_CHECK"; Description = "Enable heap free checking"; Abbreviation = "hfc"; Hex = 0x20},
@{Name = "FLG_HEAP_ENABLE_TAIL_CHECK"; Description = "Enable heap tail checking"; Abbreviation = "htc"; Hex = 0x10},
@{Name = "FLG_HEAP_VALIDATE_ALL"; Description = "Enable heap validation on call"; Abbreviation = "hvc"; Hex = 0x80},
@{Name = "FLG_HEAP_VALIDATE_PARAMETERS"; Description = "Enable heap parameter checking"; Abbreviation = "hpc"; Hex = 0x40},
@{Name = "FLG_HEAP_ENABLE_TAGGING"; Description = "Enable heap tagging"; Abbreviation = "htg"; Hex = 0x0800},
@{Name = "FLG_MAINTAIN_OBJECT_TYPELIST"; Description = "Maintain a list of objects for each type"; Abbreviation = "otl"; Hex = 0x4000},
@{Name = "FLG_MONITOR_SILENT_PROCESS_EXIT"; Description = "Enable silent process exit monitoring"; Abbreviation = "mspe"; Hex = 0x200},
@{Name = "FLG_DISABLE_STACK_EXTENSION"; Description = "Disable stack extension"; Abbreviation = "dse"; Hex = 0x010000},
@{Name = "FLG_ENABLE_CSRDEBUG"; Description = "Enable debugging of Win32 subsystem"; Abbreviation = "d32"; Hex = 0x020000},
@{Name = "FLG_ENABLE_EXCEPTION_LOGGING"; Description = "Enable exception logging"; Abbreviation = "eel"; Hex = 0x800000},
@{Name = "FLG_ENABLE_KDEBUG_SYMBOL_LOAD"; Description = "Enable loading of kernel debugger symbols"; Abbreviation = "ksl"; Hex = 0x040000},
@{Name = "FLG_HEAP_ENABLE_TAG_BY_DLL"; Description = "Enable heap tagging by DLL"; Abbreviation = "htd"; Hex = 0x8000},
@{Name = "FLG_HEAP_PAGE_ALLOCS"; Description = "Enable page heap"; Abbreviation = "hpa"; Hex = 0x02000000},
@{Name = "FLG_HEAP_DISABLE_COALESCING"; Description = "Disable heap coalesce on free"; Abbreviation = "dhc"; Hex = 0x00200000},
@{Name = "FLG_DISABLE_PAGE_KERNEL_STACKS"; Description = "Disable paging of kernel stacks"; Abbreviation = "dps"; Hex = 0x080000},
@{Name = "FLG_ENABLE_CLOSE_EXCEPTIONS"; Description = "Enable close exception"; Abbreviation = "ece"; Hex = 0x400000},
@{Name = "FLG_ENABLE_HANDLE_TYPE_TAGGING"; Description = "Enable object handle type tagging"; Abbreviation = "eot"; Hex = 0x01000000},
@{Name = "FLG_ENABLE_HANDLE_EXCEPTIONS"; Description = "Enable bad handles detection"; Abbreviation = "bhd"; Hex = 0x40000000},
@{Name = "FLG_DISABLE_PROTDLLS"; Description = "Disable protected DLL verification"; Abbreviation = "dpd"; Hex = 0x80000000},
@{Name = "FLG_DEBUG_INITIAL_COMMAND_EX"; Description = "Debug WinLogon"; Abbreviation = "dwl"; Hex = 0x04000000},
@{Name = "FLG_CRITSEC_EVENT_CREATION"; Description = "Early critical section event creation"; Abbreviation = "cse"; Hex = 0x10000000},
@{Name = "FLG_STOP_ON_UNHANDLED_EXCEPTION"; Description = "Stop on unhandled user-mode exception"; Abbreviation = "sue"; Hex = 0x20000000},
@{Name = "FLG_ENABLE_SYSTEM_CRIT_BREAKS"; Description = "Enable system critical breaks"; Abbreviation = "scb"; Hex = 0x100000}
)
# MitigationOptions
$mitigationOptions = @(
@{Name = "FLG_ASLR"; Description = "Address Space Layout Randomization"; Abbreviation = "aslr"; Flags = @{AlwaysOn = 0x100; AlwaysOff = 0x200}},
@{Name = "FLG_HeapTermination"; Description = "Heap Termination on Corruption"; Abbreviation = "heapt"; Flags = @{AlwaysOn = 0x1000; AlwaysOff = 0x2000}},
@{Name = "FLG_BottomUpASLR"; Description = "Bottom-Up ASLR"; Abbreviation = "buaslr"; Flags = @{AlwaysOn = 0x10000; AlwaysOff = 0x20000}},
@{Name = "FLG_HEASLR"; Description = "High Entropy ASLR"; Abbreviation = "heaslr"; Flags = @{AlwaysOn = 0x100000; AlwaysOff = 0x200000}},
@{Name = "FLG_SHC"; Description = "Strict Handle Checks"; Abbreviation = "shc"; Flags = @{AlwaysOn = 0x1000000; AlwaysOff = 0x2000000}},
@{Name = "FLG_DisableWin32KCalls"; Description = "Disable Win32K Calls"; Abbreviation = "dis-win32k"; Flags = @{AlwaysOn = 0x10000000; AlwaysOff = 0x20000000}},
@{Name = "FLG_DisableExtensionPoint"; Description = "Disable Extension Point"; Abbreviation = "dis-extpoint"; Flags = @{AlwaysOn = 0x100000000; AlwaysOff = 0x200000000}},
@{Name = "FLG_DisableDynamicCode"; Description = "Disable Dynamic Code"; Abbreviation = "dis-dyncode"; Flags = @{AlwaysOn = 0x1000000000; AlwaysOff = 0x2000000000}},
@{Name = "FLG_CFG"; Description = "Control Flow Guard"; Abbreviation = "cfg"; Flags = @{AlwaysOn = 0x10000000000; AlwaysOff = 0x20000000000}},
@{Name = "FLG_BlockNonMicrosoftBinaries"; Description = "Block Non-Microsoft Binaries"; Abbreviation = "block-non-ms"; Flags = @{AlwaysOn = 0x100000000000; AlwaysOff = 0x200000000000}},
@{Name = "FLG_BlockNonSystemFonts"; Description = "Block Non-System Fonts"; Abbreviation = "block-non-sysf"; Flags = @{AlwaysOn = 0x1000000000000; AlwaysOff = 0x2000000000000}},
@{Name = "FLG_DisableRemoteLoads"; Description = "Disable Remote Loads"; Abbreviation = "dis-remloads"; Flags = @{AlwaysOn = 0x10000000000000; AlwaysOff = 0x20000000000000}},
@{Name = "FLG_DisableLowIntegrityLoads"; Description = "Disable Low Integrity Loads"; Abbreviation = "dis-lowintl"; Flags = @{AlwaysOn = 0x100000000000000; AlwaysOff = 0x200000000000000}},
@{Name = "FLG_PreferSystemImages"; Description = "Prefer System Images"; Abbreviation = "pref-sysimg"; Flags = @{AlwaysOn = 0x1000000000000000; AlwaysOff = 0x2000000000000000}}
)
$otherMitigationOptions = @(
@{Name = "FLG_DEP"; Description = "Data Execution Prevention"; Abbreviation = "dep"; Hex = 0x1; Flags = @{AlwaysOn = 0x1}},
@{Name = "FLG_ATLThunk"; Description = "ATL Thunk Emulation"; Abbreviation = "atl"; Hex = 0x2; Flags = @{AlwaysOn = 0x2}},
@{Name = "FLG_SEHOP"; Description = "Structured Exception Handler Overwrite Protection"; Abbreviation = "sehop"; Hex = 0x4; Flags = @{AlwaysOn = 0x4}}
)
# Pequeña pero sirve
function Restart-Process {
param (
[string]$processName
)
$process = Get-Process -Name $processName -ErrorAction Stop
if ($process -ne $null) {
# Obtener la ruta
$processPath = (Get-Process -Id $process.Id).Path
# Detener, Esperar, Iniciar
Stop-Process -Id $process.Id -Force
Start-Sleep -Seconds 1
Start-Process -FilePath $processPath
} else {
Write-Output "Process '$processName' is not running"
}
}
$ifeoPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\"
# Establecer ifeo flags
function Set-Ifeo {
param (
[string]$process,
[int]$cpuPriority,
[int]$ioPriority,
[int]$pagePriority,
[int]$useLargePages,
[string]$debugger,
[int]$mitigationOp,
[int]$globalFlag
)
# Crear la clave si no existe
$default = Join-Path -Path $ifeoPath -ChildPath "$process"
$options = Join-Path -Path $default -ChildPath "PerfOptions"
if (-not (Test-Path $options)) {
New-Item -Path $options -Force | Out-Null
}
# Establecer las global flags
if ($cpuPriority -ne $null -and $cpuPriority -ne 0) {
Set-ItemProperty -Path $options -Name "CpuPriorityClass" -Value $cpuPriority
} else {
Remove-ItemProperty -Path $options -Name "CpuPriorityClass" -ErrorAction SilentlyContinue
}
if ($ioPriority -ne $null -and $ioPriority -ne 0) {
Set-ItemProperty -Path $options -Name "IoPriority" -Value $ioPriority
} else {
Remove-ItemProperty -Path $options -Name "IoPriority" -ErrorAction SilentlyContinue
}
if ($pagePriority -ne $null -and $PagePriority -ne 0) {
Set-ItemProperty -Path $options -Name "PagePriority" -Value $pagePriority
} else {
Remove-ItemProperty -Path $options -Name "PagePriority" -ErrorAction SilentlyContinue
}
if ($useLargePages -ne $null -and $useLargePages -ne 0) {
Set-ItemProperty -Path $default -Name "UseLargePages" -Value $useLargePages
} else {
Remove-ItemProperty -Path $default -Name "UseLargePages" -ErrorAction SilentlyContinue
}
if (![string]::IsNullOrEmpty($debugger)) {
Set-ItemProperty -Path $default -Name "Debugger" -Value $debugger
} else {
Remove-ItemProperty -Path $default -Name "Debugger" -ErrorAction SilentlyContinue
}
if ($mitigationOp -ne $null -and $mitigationOp -ne 0) {
Set-ItemProperty -Path $default -Name "MitigationOptions" -Value $mitigationOp
} else {
Remove-ItemProperty -Path $default -Name "MitigationOptions" -ErrorAction SilentlyContinue
}
if ($globalFlag -ne $null -and $globalFlag -ne 0) {
Set-ItemProperty -Path $default -Name "GlobalFlag" -Value $globalFlag
} else {
Remove-ItemProperty -Path $default -Name "GlobalFlag" -ErrorAction SilentlyContinue
}
$valueNames = @("CpuPriorityClass", "IoPriority", "PagePriority")
# Verificar si la clave esta vacía
$properties = Get-ItemProperty -Path $options -ErrorAction Stop
$hasValue = $false
foreach ($valueName in $valueNames) {
if ($properties.PSObject.Properties[$valueName]) {
$hasValue = $true
break
}
}
if (-not $hasValue) {
Remove-Item -Path $options -Recurse -Force
}
}
function Get-Ifeo {
param (
[string]$process
)
# Definir rutas de registro
$defaultPath = Join-Path -Path $ifeoPath -ChildPath "$process"
$optionsPath = Join-Path -Path $defaultPath -ChildPath "PerfOptions"
# Verificar si la clave existe
if (-not (Test-Path $defaultPath)) {
return
}
$result = @{
CpuPriority = $null
IoPriority = $null
PagePriority = $null
UseLargePages = $null
GlobalFlag = $null
MitigationOptions = $null
Debugger = $null
}
$default = Get-ItemProperty -Path $defaultPath -ErrorAction Stop
if ($default.PSObject.Properties["UseLargePages"]) {
$result.UseLargePages = $default.UseLargePages
}
if ($default.PSObject.Properties["GlobalFlag"]) {
$result.GlobalFlag = $default.GlobalFlag
}
if ($default.PSObject.Properties["MitigationOptions"]) {
$result.MitigationOptions = $default.MitigationOptions
}
if ($default.PSObject.Properties["Debugger"]) {
$result.Debugger = $default.Debugger
}
# Verificar si la clave existe
if (-not (Test-Path $optionsPath)) {
return $result
}
$options = Get-ItemProperty -Path $optionsPath -ErrorAction Stop
if ($options.PSObject.Properties["CpuPriorityClass"]) {
$result.CpuPriority = $options.CpuPriorityClass
}
if ($options.PSObject.Properties["IoPriority"]) {
$result.IoPriority = $options.IoPriority
}
if ($options.PSObject.Properties["PagePriority"]) {
$result.PagePriority = $options.PagePriority
}
return $result
}
function Load-Processes-Ifeo {
$listBoxProcesses.Items.Clear()
if ($rdbtnProcess.Checked) {
# Cargar procesos en ejecución
Get-Process | ForEach-Object {
$listBoxProcesses.Items.Add($_.Name + ".exe")
}
} elseif ($rdbtnConfig.Checked) {
# Cargar procesos desde el registro
$keys = Get-ChildItem -Path $ifeoPath
foreach ($key in $keys) {
$processName = $key.Name
if ($processName -match '^[^\\]+$') {
$processName = $processName + ".exe"
} else {
# Eliminar parte de la ruta del registro (en este caso, solo conservar el nombre del proceso)
$processName = [System.IO.Path]::GetFileName($processName)
}
$listBoxProcesses.Items.Add($processName)
}
}
}
function Reset-Checkboxes {
param (
[Parameter(Mandatory=$true)]
[System.Windows.Forms.Control]$parentControl
)
# Recorrer todos los controles del contenedor padre
foreach ($control in $parentControl.Controls) {
# Verificar si el control es un CheckBox
if ($control -is [System.Windows.Forms.CheckBox]) {
$checkBox = [System.Windows.Forms.CheckBox]$control
$checkBox.CheckState = [System.Windows.Forms.CheckState]::Unchecked
}
}
}
function Set-ValueFromNumber {
param (
[System.Windows.Forms.ComboBox]$comboBox,
[int]$number
)
if ($number -eq $null) {
# Seleccionar "default (delete)" si el número es $null
$defaultItem = $comboBox.Items | Where-Object { $_ -match "default \(delete\)" }
if ($defaultItem) {
$comboBox.SelectedItem = $defaultItem
} else {
$comboBox.SelectedIndex = -1
}
return
}
foreach ($item in $comboBox.Items) {
if ($item -match ".*\($number\).*") {
$comboBox.SelectedItem = $item
return
}
}
# Si no se encuentra, seleccionar "default (delete)"
$defaultItem = $comboBox.Items | Where-Object { $_ -match "default \(delete\)" }
if ($defaultItem) {
$comboBox.SelectedItem = $defaultItem
} else {
$comboBox.SelectedIndex = -1
}
}
function Get-ValueFromText {
param (
[string]$inputText
)
if ($inputText -match '\((\d+)\)') {
return [int]$matches[1]
} elseif ($inputText -match 'delete') {
return $null
} else {
return $null # si no coincide con ningún patrón del match
}
}
# MitigationOptionsMask
$global:bitmaskMit = 0
function Update-MitigationMask {
$global:bitmaskMit = 0
# ThreeState
foreach ($entry in $checkboxesMit) {
$checkbox = $entry.CheckBox
$option = $entry.Option
if ($checkbox.CheckState -eq [System.Windows.Forms.CheckState]::Checked) {
$global:bitmaskMit = $global:bitmaskMit -bor $option.Flags.AlwaysOn
} elseif ($checkbox.CheckState -eq [System.Windows.Forms.CheckState]::Indeterminate) {
$global:bitmaskMit = $global:bitmaskMit -bor $option.Flags.AlwaysOff
}
}
# TwoState
foreach ($option in $otherMitigationOptions) {
$checkbox = $tabMit.Controls.Find($option.Abbreviation, $true)[0]
if ($checkbox.CheckState -eq [System.Windows.Forms.CheckState]::Checked) {
$global:bitmaskMit = $global:bitmaskMit -bor $option.Hex
}
}
$labelMit.Text = "BitMask: 0x" + "{0:X}" -f $global:bitmaskMit
}
function Load-MitigationMask {
param (
[Parameter(Mandatory=$true)]
[UInt64]$bitmask
)
foreach ($entry in $checkboxesMit) {
$checkbox = $entry.CheckBox
$option = $entry.Option
if ($bitmask -band $option.Flags.AlwaysOn) {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Checked
} elseif ($bitmask -band $option.Flags.AlwaysOff) {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Indeterminate
} else {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Unchecked
}
}
}
function Load-OtherMitigationOptions {
param (
[Parameter(Mandatory=$true)]
[UInt64]$bitmask
)
foreach ($option in $otherMitigationOptions) {
$controls = $tabMit.Controls.Find($option.Abbreviation, $true)
if ($controls.Count -gt 0) {
$checkbox = $controls[0]
# Verificar que el control es un CheckBox
if ($bitmask -band $option.Hex) {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Checked
} else {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Unchecked
}
}
}
}
#GFLagsMask
$global:bitmaskFlags = 0
function Update-FlagsMask {
$global:bitmaskFlags = 0
foreach ($entry in $checkboxesFlags) {
$checkbox = $entry.CheckBox
$option = $entry.Option
if ($checkbox.CheckState -eq [System.Windows.Forms.CheckState]::Checked) {
$global:bitmaskFlags = $global:bitmaskFlags -bor $option.Hex
}
}
$labelGFlags.Text = "BitMask: 0x" + "{0:X}" -f $global:bitmaskFlags
}
function Load-FlagsMask {
param (
[Parameter(Mandatory=$true)]
[UInt32]$bitmask
)
foreach ($entry in $checkboxesFlags) {
$checkbox = $entry.CheckBox
$option = $entry.Option
if ($bitmask -band $option.Hex) {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Checked
} else {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Unchecked
}
}
}
# Ocultar consola, crear form
Console -Hide
[System.Windows.Forms.Application]::EnableVisualStyles();
$form = New-Object System.Windows.Forms.Form
$form.ClientSize = New-Object System.Drawing.Size(360, 310)
$form.Text = "XFlags"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$form.Add_KeyDown({
param($sender, $e)
if ($e.KeyCode -eq [System.Windows.Forms.Keys]::F5) {
Load-Processes-Ifeo
}
})
$listBoxProcesses = New-Object System.Windows.Forms.ListBox
$listBoxProcesses.Location = New-Object System.Drawing.Point(10, 28)
$listBoxProcesses.Size = New-Object System.Drawing.Size(150, 250)
$listBoxProcesses.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$form.Controls.Add($listBoxProcesses)
$listBoxProcesses.add_SelectedIndexChanged({
# Obtener el proceso seleccionado
$selectedProcess = $listBoxProcesses.SelectedItem
# Obtener la configuración
$config = Get-Ifeo -process $selectedProcess
if ($config) {
# PerfOptions
$cpuPriority = if ($null -ne $config.CpuPriority) { $config.CpuPriority } else { 0 }
$ioPriority = if ($null -ne $config.IoPriority) { $config.IoPriority } else { 0 }
$pagePriority = if ($null -ne $config.PagePriority) { $config.PagePriority } else { 0 }
Set-ValueFromNumber -comboBox $comboBoxCpuPriority -number $cpuPriority
Set-ValueFromNumber -comboBox $comboBoxIoPriority -number $ioPriority
Set-ValueFromNumber -comboBox $comboBoxPagePriority -number $pagePriority
# Large Pages
if ($null -ne $config.UseLargePages -and $config.UseLargePages -ge 1) {
$chkbLargePages.CheckState = [System.Windows.Forms.CheckState]::Checked
} else {
$chkbLargePages.CheckState = [System.Windows.Forms.CheckState]::Unchecked
}
# Debugger
$txtDbgr.Text = if ($null -ne $config.Debugger) { $config.Debugger } else { "" }
# Mitigation
$mitigationOptions = if ($null -ne $config.MitigationOptions) { $config.MitigationOptions } else { 0 }
$labelMit.Text = "BitMask: 0x{0:X}" -f $mitigationOptions + " (Registry)"
Load-MitigationMask -bitmask $mitigationOptions
Load-OtherMitigationOptions -bitmask $mitigationOptions
# Global Flags
$globalFlags = if ($null -ne $config.GlobalFlag) { $config.GlobalFlag } else { 0 }
$labelGFlags.Text = "BitMask: 0x{0:X}" -f $globalFlags + " (Registry)"
Load-FlagsMask -bitmask $globalFlags
}
})
# Process
$rdbtnProcess = New-Object System.Windows.Forms.RadioButton
$rdbtnProcess.Text = "Process"
$rdbtnProcess.Size = New-Object System.Drawing.Size(70, 20)
$rdbtnProcess.Location = New-Object System.Drawing.Point(10, 280)
$rdbtnProcess.Checked = $true
$form.Controls.Add($rdbtnProcess)
$rdbtnProcess.add_CheckedChanged({
Load-Processes-Ifeo
})
# Config
$rdbtnConfig = New-Object System.Windows.Forms.RadioButton
$rdbtnConfig.Text = "Config"
$rdbtnConfig.Size = New-Object System.Drawing.Size(60, 20)
$rdbtnConfig.Location = New-Object System.Drawing.Point(80, 280)
$form.Controls.Add($rdbtnConfig)
$rdbtnConfig.add_CheckedChanged({
Load-Processes-Ifeo
})
Load-Processes-Ifeo | Out-Null
# TabControl
$tab = New-Object System.Windows.Forms.TabControl
$tab.Dock = [System.Windows.Forms.DockStyle]::Fill
$tab.Add_SelectedIndexChanged({
if ($tab.SelectedIndex -eq 0) {
$form.ClientSize = New-Object System.Drawing.Size(360, 310)
} elseif ($tab.SelectedIndex -ge 1) {
$form.ClientSize = New-Object System.Drawing.Size(430, 310)
}
})
# Ifeo
$tabIfeo = New-Object System.Windows.Forms.TabPage
$tabIfeo.Text = "General"
# PriorityClass
$labelCpuPriority = New-Object System.Windows.Forms.Label
$labelCpuPriority.Location = New-Object System.Drawing.Point(210, 20)
$labelCpuPriority.Size = New-Object System.Drawing.Size(80, 13)
$labelCpuPriority.Text = "PriorityClass:"
$tabIfeo.Controls.Add($labelCpuPriority)
$comboBoxCpuPriority = New-Object System.Windows.Forms.ComboBox
$comboBoxCpuPriority.Location = New-Object System.Drawing.Point(210, 38)
$comboBoxCpuPriority.Size = New-Object System.Drawing.Size(95, 23)
$comboBoxCpuPriority.Items.AddRange(@("Realtime (4)", "High (3)", "Above Normal (6)", "Normal (2)", "Below Normal (5)", "Low (1)", "default (delete)"))
$comboBoxCpuPriority.Text = "default (delete)"
$comboBoxCpuPriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$tabIfeo.Controls.Add($comboBoxCpuPriority)
# IoPriority
$labelIoPriority = New-Object System.Windows.Forms.Label
$labelIoPriority.Location = New-Object System.Drawing.Point(210, 70)
$labelIoPriority.Size = New-Object System.Drawing.Size(60, 13)
$labelIoPriority.Text = "IoPriority:"
$tabIfeo.Controls.Add($labelIoPriority)
$comboBoxIoPriority = New-Object System.Windows.Forms.ComboBox
$comboBoxIoPriority.Location = New-Object System.Drawing.Point(210, 88)
$comboBoxIoPriority.Size = New-Object System.Drawing.Size(95, 23)
$comboBoxIoPriority.Items.AddRange(@("Critical (4)", "High (3)", "Normal (2)", "Low (1)", "default (delete)"))
$comboBoxIoPriority.Text = "default (delete)"
$comboBoxIoPriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$comboBoxIoPriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$tabIfeo.Controls.Add($comboBoxIoPriority)
# MemPriority
$labelMemPriority = New-Object System.Windows.Forms.Label
$labelMemPriority.Location = New-Object System.Drawing.Point(210, 120)
$labelMemPriority.Size = New-Object System.Drawing.Size(85, 13)
$labelMemPriority.Text = "PagePriority:"
$tabIfeo.Controls.Add($labelMemPriority)
$comboBoxPagePriority = New-Object System.Windows.Forms.ComboBox
$comboBoxPagePriority.Location = New-Object System.Drawing.Point(210, 138)
$comboBoxPagePriority.Size = New-Object System.Drawing.Size(95, 23)
$comboBoxPagePriority.Items.AddRange(@("Normal (5)", "Below Normal (4)", "Medium (3)", "Low (2)", "VeryLow (1)", "default (delete)"))
$comboBoxPagePriority.Text = "default (delete)"
$comboBoxPagePriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$comboBoxPagePriority.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$tabIfeo.Controls.Add($comboBoxPagePriority)
# LargePages
$chkbLargePages = New-Object System.Windows.Forms.CheckBox
$chkbLargePages.Location = New-Object System.Drawing.Point(210, 172)
$chkbLargePages.Size = New-Object System.Drawing.Size(105, 20)
$chkbLargePages.Text = "UseLargePages"
$tabIfeo.Controls.Add($chkbLargePages)
$tooltip = New-Object System.Windows.Forms.ToolTip
$tooltip.SetToolTip($chkbLargePages, "Enable Large Pages if possible")
# Dbg
$labelDbgr = New-Object System.Windows.Forms.Label
$labelDbgr.Location = New-Object System.Drawing.Point(170, 210)
$labelDbgr.Size = New-Object System.Drawing.Size(70, 13)
$labelDbgr.Text = "Debugger:"
$tabIfeo.Controls.Add($labelDbgr)
$txtDbgr = New-Object System.Windows.Forms.TextBox
$txtDbgr.Location = New-Object System.Drawing.Point(170, 228)
$txtDbgr.Size = New-Object System.Drawing.Size(150, 20)
$txtDbgr.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$tabIfeo.Controls.Add($txtDbgr)
$btnSearchDbg = New-Object System.Windows.Forms.Button
$btnSearchDbg.Location = New-Object System.Drawing.Point(325, 228)
$btnSearchDbg.Size = New-Object System.Drawing.Size(25, 20)
$btnSearchDbg.Text = "..."
$tabIfeo.Controls.Add($btnSearchDbg)
$btnSearchDbg.Add_Click({
# Crear el OpenFileDialog
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Filter = "Executables (*.exe)|*.exe|All files (*.*)|*.*"
$openFileDialog.Title = "Select Debugger"
# Mostrar el diálogo de selección de archivos
$result = $openFileDialog.ShowDialog()
# Verificar si el usuario seleccionó un archivo y presionó OK
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
# Obtener la ruta del archivo seleccionado
$selectedFile = $openFileDialog.FileName
# Establecer la ruta del archivo en el TextBox
$txtDbgr.Text = $selectedFile
}
})
# SaveConfig
$buttonSave = New-Object System.Windows.Forms.Button
$buttonSave.Location = New-Object System.Drawing.Point(230, 260)
$buttonSave.Size = New-Object System.Drawing.Size(50, 20)
$buttonSave.Text = "Save"
$tabIfeo.Controls.Add($buttonSave)
# aplicar todos los cambios
$buttonSave.Add_Click({
$process = $listBoxProcesses.SelectedItem
if ($process.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show("Select a process", "Info", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
return
}
$cpuPriority = $comboBoxCpuPriority.SelectedItem
$ioPriority = $comboBoxIoPriority.SelectedItem
$pagePriority = $comboBoxPagePriority.SelectedItem
$useLargePages = if ($chkbLargePages.Checked) {"Enabled (1)"} else {"default (delete)"}
$debugger = $txtDbgr.Text
if (-not $cpuPriority -or -not $ioPriority -or -not $pagePriority) {
[System.Windows.Forms.MessageBox]::Show("You must select one option for all priorities", "Info", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
return
}
# Convertir a valores númericos
$cpuPriorityValue = Get-ValueFromText -inputText $cpuPriority
$ioPriorityValue = Get-ValueFromText -inputText $ioPriority
$pagePriorityValue = Get-ValueFromText -inputText $pagePriority
# aplicar configuracion de ifeo
Set-Ifeo -process $process -cpuPriority $cpuPriorityValue -ioPriority $ioPriorityValue -pagePriority $pagePriorityValue -useLargePages $useLargePagesValue -debugger $debugger -mitigationOp $bitmaskMit -globalFlag $bitmaskFlags
$processName = $process.Replace(".exe", "")
$existProcess = Get-Process -Name $processName -ErrorAction Stop
if ($existProcess) {
$result = [System.Windows.Forms.MessageBox]::Show("Restart Process?", "Applied settings", [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Information)
# reiniciar el proceso, opcionalmente
if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
Restart-Process -processName $processName
}
}
})
### MitigationOptions
$tabMit = New-Object System.Windows.Forms.TabPage
$tabMit.Text = "MitigationOptions"
# MitigationBitmask
$labelMit = New-Object System.Windows.Forms.Label
$labelMit.Location = New-Object System.Drawing.Point(180, 10)
$labelMit.Size = New-Object System.Drawing.Size(250, 13)
$labelMit.Text = "BitMask: 0x0"
$tabMit.Controls.Add($labelMit)
# Configuración de posición inicial y dimensiones del área visible
$startX = 180
$startY = 40
$currentX = $startX
$currentY = $startY
$columnWidth = 120 # Ancho de la columna
$rowHeight = 25 # Espacio entre filas
$maxCheckboxesPerColumn = 7 # Número máximo de CheckBoxes por columna
$checkboxCount = 0 # Contador de CheckBoxes en la columna actual
$checkboxesMit = @()
foreach ($option in $mitigationOptions) {
# Crear CheckBox
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $option.Abbreviation
$checkbox.ThreeState = $true
$checkbox.Location = New-Object System.Drawing.Point($currentX, $currentY)
$checkbox.Size = New-Object System.Drawing.Size(100, 20) # Ajustar el tamaño del CheckBox
$tabMit.Controls.Add($checkbox)
$checkbox.Add_Click({
switch ($checkbox.CheckState) {
[System.Windows.Forms.CheckState]::Unchecked {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Checked
break
}
[System.Windows.Forms.CheckState]::Checked {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Indeterminate
break
}
[System.Windows.Forms.CheckState]::Indeterminate {
$checkbox.CheckState = [System.Windows.Forms.CheckState]::Unchecked
break
}
}
Update-MitigationMask
})
$checkboxesMit += [PSCustomObject]@{ CheckBox = $checkbox; Option = $option }
# Añadir SymbolicName al ToolTip
$tooltip.SetToolTip($checkbox, $option.Description)
# Ajustar la posición para el próximo CheckBox
$checkboxCount++
$currentY += $rowHeight
# Si se ha alcanzado el número máximo de CheckBoxes en la columna, mover a la siguiente columna
if ($checkboxCount -ge $maxCheckboxesPerColumn) {
$checkboxCount = 0
$currentY = $startY
$currentX += $columnWidth
}
}
# DEP
$startX = 180
$currentX = $startX
foreach ($option in $otherMitigationOptions){
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $option.Abbreviation
$width = ($option.Name).Length + 60
$checkbox.Location = New-Object System.Drawing.Point($currentX, 225)
$checkbox.Size = New-Object System.Drawing.Size($width, 20) # Ajustar el tamaño del CheckBox
$tabMit.Controls.Add($checkbox)
$checkbox.Add_Click({
Update-MitigationMask
})
$checkboxesMit += [PSCustomObject]@{ CheckBox = $checkbox; Option = $option }
# ToolTip
$tooltip.SetToolTip($checkbox, $option.Description)
$currentX+=85
}
# ResetMask
$btnResetMit = New-Object System.Windows.Forms.Button
$btnResetMit.Location = New-Object System.Drawing.Point(255, 255)
$btnResetMit.Size = New-Object System.Drawing.Size(90, 20)
$btnResetMit.Text = "ResetMask"
$tabMit.Controls.Add($btnResetMit)
$btnResetMit.Add_Click({
Reset-Checkboxes -parentControl $tabMit
$global:bitmaskMit = 0
$labelMit.Text = "BitMask: 0x{0:X}" -f $global:bitmaskMit
})
### GFlags
$tabGFlags = New-Object System.Windows.Forms.TabPage
$tabGFlags.Text = "Gflags"
# GFlagBitmask
$labelGFlags = New-Object System.Windows.Forms.Label
$labelGFlags.Location = New-Object System.Drawing.Point(180, 10)
$labelGFlags.Size = New-Object System.Drawing.Size(200, 13)
$labelGFlags.Text = "BitMask: 0x0"
$tabGFlags.Controls.Add($labelGFlags)
# ResetMask
$btnResetFlags = New-Object System.Windows.Forms.Button
$btnResetFlags.Location = New-Object System.Drawing.Point(255, 255)
$btnResetFlags.Size = New-Object System.Drawing.Size(90, 20)
$btnResetFlags.Text = "ResetMask"
$tabGFlags.Controls.Add($btnResetFlags)
$btnResetFlags.Add_Click({
Reset-Checkboxes -parentControl $tabGFlags
$global:bitmaskGFlags = 0
$labelGFlags.Text = "BitMask: 0x{0:X}" -f $global:bitmaskGFlags
})
# Configuración de posición inicial y dimensiones del área visible
$startX = 180
$startY = 40
$currentX = $startX
$currentY = $startY
$columnWidth = 60 # Ancho de la columna
$rowHeight = 30 # Espacio entre filas
$maxCheckboxesPerColumn = 7 # Número máximo de CheckBoxes por columna
$checkboxCount = 0 # Contador de CheckBoxes en la columna actual
$checkboxesFlags = @()
foreach ($flag in $flags) {
# Crear CheckBox
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $flag.Abbreviation
$checkbox.Location = New-Object System.Drawing.Point($currentX, $currentY)
$checkbox.Size = New-Object System.Drawing.Size(55, 20) # Ajustar el tamaño del CheckBox
$tabGFlags.Controls.Add($checkbox)
$checkbox.Add_Click({
Update-FlagsMask
})
$checkboxesFlags += [PSCustomObject]@{ CheckBox = $checkbox; Option = $flag }
# Añadir SymbolicName al ToolTip
$tooltip.SetToolTip($checkbox, $flag.Description)
# Ajustar la posición para el próximo CheckBox
$checkboxCount++
$currentY += $rowHeight
# Si se ha alcanzado el número máximo de CheckBoxes en la columna, mover a la siguiente columna
if ($checkboxCount -ge $maxCheckboxesPerColumn) {
$checkboxCount = 0
$currentY = $startY
$currentX += $columnWidth
}
}
$tab.TabPages.Add($tabIfeo)
$tab.TabPages.Add($tabMit)
$tab.TabPages.Add($tabGFlags)
$form.Controls.Add($tab)
$form.ShowDialog()