-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefenderSwitcher.ps1
489 lines (443 loc) · 26.1 KB
/
DefenderSwitcher.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
param (
[switch]$enable_av,
[switch]$disable_av
)
$interactiveMode = (!$enable_av -and !$disable_av)
# Acquiring high privileges
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) {$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""; Start-Process PowerShell.exe -ArgumentList $arguments -Verb RunAs; exit}
if (![Type]::GetType('Privileges')) {
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Privileges {
[DllImport("advapi32.dll")] internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
[DllImport("advapi32.dll")] internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
[DllImport("advapi32.dll", SetLastError = true)] internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
[StructLayout(LayoutKind.Sequential, Pack = 1)] internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; }
internal const int SE_PRIVILEGE_ENABLED = 0x00000002, TOKEN_QUERY = 0x00000008, TOKEN_ADJUST_PRIVILEGES = 0x00000020;
public static bool AddPrivilege(string privilege) {
IntPtr hproc = GetCurrentProcess(), htok = IntPtr.Zero;
TokPriv1Luid tp = new TokPriv1Luid { Count = 1, Luid = 0, Attr = SE_PRIVILEGE_ENABLED };
if (OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok) && LookupPrivilegeValue(null, privilege, ref tp.Luid))
return AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return false;
}
public static bool RemovePrivilege(string privilege) {
IntPtr hproc = GetCurrentProcess(), htok = IntPtr.Zero;
TokPriv1Luid tp = new TokPriv1Luid { Count = 1, Luid = 0, Attr = 0 };
if (OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok) && LookupPrivilegeValue(null, privilege, ref tp.Luid))
return AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return false;
}
[DllImport("kernel32.dll")] public static extern IntPtr GetCurrentProcess();
}
"@ -Language CSharp
}
function Add-Privileges {'SeRestorePrivilege','SeTakeOwnershipPrivilege','SeDebugPrivilege','SeSystemEnvironmentPrivilege' | ForEach-Object {[Privileges]::AddPrivilege($_) | Out-Null }}
function Remove-Privileges {'SeRestorePrivilege','SeTakeOwnershipPrivilege','SeDebugPrivilege','SeSystemEnvironmentPrivilege' | ForEach-Object {[Privileges]::RemovePrivilege($_) | Out-Null }}
# Check system integrity
function CheckSystemIntegrity {
function HandleError {
param ([string]$Message)
Write-Host "Error: $Message" -ForegroundColor Red
pause
$response = Read-Host "Do you want to run 'sfc /scannow' for system recovery? (Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Write-Host "Starting system scan..." -ForegroundColor Yellow
[Diagnostics.Process]::Start("cmd.exe", "/c sfc /scannow & pause").WaitForExit()
exit
} else {
Write-Host "Skipping system integrity check. If problems continue, consider reinstalling Windows." -ForegroundColor Red
pause
exit
}
}
$ErrorActionPreference = 'SilentlyContinue'
try {
if (!(Get-Command -Name Add-WindowsPackage -ErrorAction SilentlyContinue)) {
$modulesPath = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
if (!(Test-Path $modulesPath)) {
HandleError "PowerShell modules directory missing at '$modulesPath'."
} else {
HandleError "'Add-WindowsPackage' command not available. Windows may be corrupted."
}
}
$registryPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing',
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide'
)
foreach ($path in $registryPaths) {
if (!(Test-Path $path)) {
HandleError "Registry key missing at '$path'."
}
}
$services = @('TrustedInstaller', 'wuauserv', 'bits', 'cryptsvc')
foreach ($serviceName in $services) {
if (!(Get-Service -Name $serviceName -ErrorAction SilentlyContinue)) {
HandleError "'$serviceName' service missing."
}
}
} catch {
HandleError $_.Exception.Message
}
$ErrorActionPreference = 'Continue'
}
# Prerequisite
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class ConsoleManager {
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
public static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool bMaximumWindow, ref CONSOLE_FONT_INFO_EX lpConsoleCurrentFontEx);
[DllImport("kernel32.dll")]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll")]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct CONSOLE_FONT_INFO_EX {
public uint cbSize;
public uint nFont;
public COORD dwFontSize;
public int FontFamily;
public int FontWeight;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string FaceName;
}
[StructLayout(LayoutKind.Sequential)]
public struct COORD { public short X; public short Y; }
[StructLayout(LayoutKind.Sequential)]
public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
public const int STD_OUTPUT_HANDLE = -11;
public static void ResizeWindow(int w, int h) {
MoveWindow(GetConsoleWindow(), 0, 0, w, h, true);
}
public static void SetConsoleFont(string name, short size) {
CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX();
info.cbSize = (uint)Marshal.SizeOf(typeof(CONSOLE_FONT_INFO_EX));
info.FaceName = name;
info.dwFontSize = new COORD { X = size, Y = size };
info.FontFamily = 54;
info.FontWeight = 400;
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), false, ref info);
}
public static void QuickEditOFF() {
IntPtr hConIn = GetStdHandle(-10);
uint m;
if (GetConsoleMode(hConIn, out m))
SetConsoleMode(hConIn, (m | 0x80U) & ~0x40U);
}
}
"@
function AdjustDesign {
param ([switch]$QuickEditOFF)
Add-Type -AssemblyName System.Windows.Forms
$host.PrivateData.WarningBackgroundColor = 'Black'
$host.PrivateData.ErrorBackgroundColor = 'Black'
$host.PrivateData.VerboseBackgroundColor = 'Black'
$host.PrivateData.DebugBackgroundColor = 'Black'
$host.UI.RawUI.BackgroundColor = [ConsoleColor]::Black
$host.UI.RawUI.ForegroundColor = [ConsoleColor]::White
if ($QuickEditOFF) {[ConsoleManager]::QuickEditOFF()}
[ConsoleManager]::ResizeWindow(850,550)
[ConsoleManager]::SetConsoleFont("Consolas",16)
$hwnd = [ConsoleManager]::GetConsoleWindow()
$rect = New-Object ConsoleManager+RECT
[ConsoleManager]::GetWindowRect($hwnd, [ref]$rect) | Out-Null
$sw = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
$sh = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
$ww = $rect.Right - $rect.Left
$wh = $rect.Bottom - $rect.Top
$newX = [Math]::Max(0, [Math]::Round(($sw - $ww) / 2))
$newY = [Math]::Max(0, [Math]::Round(($sh - $wh) / 2))
[ConsoleManager]::MoveWindow($hwnd, $newX, $newY, $ww, $wh, $true) | Out-Null
}
function CheckDefenderStatus {
$packageResult = (Get-WindowsPackage -online | Where-Object { $_.PackageName -like '*AntiBlocker*' })
$serviceResult = (Get-Service -Name WinDefend -ErrorAction SilentlyContinue | Select-Object -ExpandProperty StartType)
$serviceResult = $serviceResult -replace "`r`n", ""
if ($packageResult -or $serviceResult -eq 'Disabled') {
$global:status = "disabled"
} else {
$global:status = "enabled"
}
}
$pingResult = & ping -n 2 google.com | Select-String "TTL="
$existingFile = if (Test-Path "$env:WinDir\DefenderSwitcher") {gci -Path "$env:WinDir\DefenderSwitcher" -Filter "*AntiBlocker*" -File | Select-Object -First 1} else {$null}
$programUsable = $false
switch ($true) {
($null -eq $existingFile) {
if (!$pingResult) {
$programUsable = $false
} else {
$destinationDir = "$env:WinDir\DefenderSwitcher"
$fileName = "Z-RapidOS-AntiBlocker-Package31bf3856ad364e35amd641.0.0.0.cab"
$destinationPath = Join-Path -Path $destinationDir -ChildPath $fileName
$fileUrl = "https://rapid-community.ru/downloads/$fileName"
if (!(Test-Path -Path $destinationDir)) {
New-Item -Path $destinationDir -ItemType Directory | Out-Null
}
curl.exe -s -o $destinationPath $fileUrl > $null 2>&1
if (Test-Path -Path $destinationPath) {
$programUsable = $true
} else {
$programUsable = $false
}
}
break
}
default {
$programUsable = $true
$destinationDir = "$env:WinDir\DefenderSwitcher"
$fileName = "Z-RapidOS-AntiBlocker-Package31bf3856ad364e35amd641.0.0.0.cab"
$destinationPath = Join-Path -Path $destinationDir -ChildPath $fileName
$fileUrl = "https://rapid-community.ru/downloads/$fileName"
$tempFile = Join-Path -Path $env:TEMP -ChildPath $fileName
curl.exe -s -o $tempFile $fileUrl > $null 2>&1
if ((Test-Path -Path $tempFile) -and (Test-Path -Path $destinationPath)) {
if ((Get-FileHash -Path $tempFile).Hash -ne (Get-FileHash -Path $destinationPath).Hash) {
Move-Item -Path $tempFile -Destination $destinationPath -Force
} else {
Remove-Item -Path $tempFile
}
}
break
}
}
function MainMenu {
cls
CheckDefenderStatus;
Write-Host "`n`n`n`n"
Write-Host " ______________________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Defender Switcher"
Write-Host ""
Write-Host " Current Status:" -ForegroundColor Yellow
if ($status -eq "enabled")
{Write-Host " Windows Defender is ENABLED" -ForegroundColor Green}
else{Write-Host " Windows Defender's DISABLED" -ForegroundColor Red}
if ($programUsable -eq $true)
{Write-Host " Defender can be toggled" -ForegroundColor Green}
else{Write-Host " Connect to the Internet" -ForegroundColor Red}
Write-Host " __________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Choose an option:" -ForegroundColor Yellow
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "1"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Enable Windows Defender | Restore Protection"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "2"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Disable Windows Defender | Turn Off Protection"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "3"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Information | Useful Information"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "4"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Exit | Close Program"
Write-Host ""
Write-Host " __________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Choose a menu option using your keyboard [1,2,3,4] :" -ForegroundColor Green
Write-Host ""
Write-Host " ______________________________________________________________" -ForegroundColor DarkGray
Write-Host ""
$host.UI.RawUI.KeyAvailable > $null 2>&1
$choice = $host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').Character
switch ($choice) {
'1' { EnableDefender }
'2' { DisableDefender }
'3' { ShowInformation }
'4' { ExitProgram }
default { MainMenu }
}
}
function EnableDefender {
cls
CheckDefenderStatus;
switch ($status) {
"enabled" {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Defender is already enabled."
}
default {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "PROCESSING"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Enabling Defender..."
Add-Privileges
$ProgressPreference = 'SilentlyContinue'; $WarningPreference = 'SilentlyContinue';
Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*AntiBlocker*' } | ForEach-Object {
Remove-WindowsPackage -Online -PackageName $_.PackageName -NoRestart
} | Out-Null 2>&1
$ProgressPreference = 'Continue'; $WarningPreference = 'Continue';
Remove-Privileges
CheckDefenderStatus;
switch ($status) {
"enabled" {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Defender has been enabled."
}
default {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Failed to enable Defender."
Write-Host ""
Write-Host "Try to reboot your PC and try again."
Write-Host "If error occurs, try to use program in safe boot with ethernet option."
Write-Host "If nothing helped, please, make an issue on GitHub or write in Rapid Community's discord server for help."
}
}
}
}
if ($interactiveMode) {
pause
MainMenu
} else {
exit
}
}
function DisableDefender {
cls
CheckDefenderStatus;
switch ($status) {
"disabled" {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Defender is already disabled."
}
default {
if ($programUsable -eq $true) {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "PROCESSING"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Disabling Defender..."
Add-Privileges
ProcessDefender -InstallCAB $true
ProcessDefender -LinkManifests $true
Remove-Privileges
CheckDefenderStatus;
switch ($status) {
"disabled" {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Defender has been disabled."
}
default {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Failed to disable Defender."
Write-Host ""
Write-Host "Try to reboot your PC and try again."
Write-Host "If error occurs, try to use program in safe boot with ethernet option."
Write-Host "If nothing helped, please, make an issue on GitHub or write in Rapid Community's discord server for help."
}
}
} else {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Connect to the internet and restart Defender Switcher to proceed."
}
}
}
if ($interactiveMode) {
pause
MainMenu
} else {
exit
}
}
function ProcessDefender {
param (
[switch]$InstallCAB,
[switch]$LinkManifests
)
if ($InstallCAB) {
$cabPath = gci -Path "$env:WinDir\DefenderSwitcher" -Filter "*AntiBlocker*" -File | Select-Object -First 1
if (!$cabPath) {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Connect to the internet and restart Defender Switcher to proceed."
return
}
$filePath = $cabPath.FullName
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Checking certificate..."
try {
$cert = (Get-AuthenticodeSignature $filePath).SignerCertificate
if ($cert.Extensions.EnhancedKeyUsages.Value -ne "1.3.6.1.4.1.311.10.3.6") {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Cert doesn't have proper key usages, can't continue."
return
}
$certRegPath = "HKLM:\Software\Microsoft\SystemCertificates\ROOT\Certificates\8A334AA8052DD244A647306A76B8178FA215F344"
if (!(Test-Path "$certRegPath")) {
New-Item -Path $certRegPath -Force | Out-Null
}
} catch {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Cert error from '$filePath': $_"
return
}
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Adding package..."
try {
$ProgressPreference = 'SilentlyContinue'
Add-WindowsPackage -Online -PackagePath $filePath -NoRestart -IgnoreCheck -LogLevel 1 *>$null
$ProgressPreference = 'Continue'
} catch {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Error when adding package '$filePath': $_"
$host.UI.RawUI.ForegroundColor = 'Yellow'; Write-Host -NoNewline "["; Write-Host -NoNewline "WARN"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Attempting to use DISM to install the package..."
try {
$ProgressPreference = 'SilentlyContinue'
DISM /Online /Add-Package /PackagePath:$filePath /NoRestart *>$null
$ProgressPreference = 'Continue'
} catch {return}
}
}
if ($LinkManifests) {
CheckDefenderStatus;
if ($status -eq "disabled") {
$version = '38655.38527.65535.65535'
$srcPathExpanded = [System.Environment]::ExpandEnvironmentVariables("%WinDir%\DefenderSwitcher\WinSxS")
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Getting manifests..."
$manifests = gci "$env:WinDir\WinSxS\Manifests" -File -Filter "*$version*"
if ($manifests.Count -eq 0) {
$host.UI.RawUI.ForegroundColor = 'Red'; Write-Host -NoNewline "["; Write-Host -NoNewline "ERROR"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "No manifests found! Can't create repair source."
return
}
if (Test-Path $srcPathExpanded -PathType Container) {
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Deleting old RepairSrc..."
Remove-Item $srcPathExpanded -Force -Recurse
}
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Creating RepairSrc path..."
New-Item "$srcPathExpanded\Manifests" -Force -ItemType Directory | Out-Null
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "["; Write-Host -NoNewline "INFO"; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Hard linking manifests..."
foreach ($manifest in $manifests) {
New-Item -ItemType HardLink -Path "$srcPathExpanded\Manifests\$manifest" -Target $manifest.FullName | Out-Null
}
$servicingPolicyKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing"
if (!(Test-Path $servicingPolicyKey)) { New-Item -Path $servicingPolicyKey -Force | Out-Null }
Set-ItemProperty -Path $servicingPolicyKey -Name LocalSourcePath -Value "%WinDir%\DefenderSwitcher\WinSxS" -Type ExpandString -Force
}
}
}
function ShowInformation {
cls
Write-Host "`n`n`n`n"
Write-Host " ______________________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Defender Switcher"
Write-Host ""
Write-Host " Credits:" -ForegroundColor Yellow
Write-Host ""
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "1"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "AtlasOS CAB Method"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "2"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Design Based on MAS"
Write-Host ""
Write-Host " __________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Our links:" -ForegroundColor Yellow
Write-Host ""
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "3"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "GitHub"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "4"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Discord"
$host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline " ["; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host -NoNewline "5"; $host.UI.RawUI.ForegroundColor = 'Green'; Write-Host -NoNewline "] "; $host.UI.RawUI.ForegroundColor = 'White'; Write-Host "Website"
Write-Host ""
Write-Host " __________________________________________________" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Choose a menu option using your keyboard [1,2,3,4,5,q] :" -ForegroundColor Green
Write-Host ""
Write-Host " ______________________________________________________________" -ForegroundColor DarkGray
$choice = ""
while ($choice -ne 'q') {
$choice = $host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').Character
switch ($choice) {
'1' { Start-Process "https://github.com/Atlas-OS/Atlas" }
'2' { Start-Process "https://github.com/massgravel/Microsoft-Activation-Scripts" }
'3' { Start-Process "https://github.com/instead1337/Defender-Switcher" }
'4' { Start-Process "https://dsc.gg/rapid-community" }
'5' { Start-Process "https://rapid-community.ru" }
'q' { MainMenu }
}
}
}
function ExitProgram {
Start-Sleep -Seconds 1
exit
}
if ($enable_av) { AdjustDesign; EnableDefender }
if ($disable_av) { AdjustDesign; DisableDefender }
if ($interactiveMode) { CheckSystemIntegrity; AdjustDesign -QuickEditOFF; MainMenu } else { exit }