Skip to content

Commit 697a9e6

Browse files
committed
security - defender improvements
- better package status cheking if a package installed with errors - disable MDCoreSvc after DisableAntiSpyware - run enableDefender when uninstalling defender package
1 parent ae44c11 commit 697a9e6

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/commands/win_package_command.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class WindowsPackageCommand extends Command<String> {
7777

7878
Future<void> _uninstallPackage(final WinPackageType packageType) async {
7979
stdout.writeln('$tag Uninstalling package: ${packageType.packageName}');
80+
if (packageType == WinPackageType.defenderRemoval) {
81+
await _securityService.enableDefender();
82+
}
8083
await _winPackageService.uninstallPackage(packageType);
8184
}
8285
}

lib/services/security_service.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class SecurityService implements SetupService {
9191
await _shell.run(
9292
'start /WAIT /MIN /B "" "%systemroot%\\System32\\gpupdate.exe" /Target:Computer /Force');
9393

94+
await _shell.run(
95+
'"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\System\\ControlSet001\\Services\\MDCoreSvc" /v Start /t REG_DWORD /d 2 /f');
96+
9497
RegistryUtilsService.writeString(
9598
Registry.localMachine,
9699
r'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',
@@ -128,6 +131,14 @@ class SecurityService implements SetupService {
128131
await _shell.run(
129132
'"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\SOFTWARE\\Microsoft\\Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f');
130133

134+
await _shell.run(
135+
'"$directoryExe\\MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\System\\ControlSet001\\Services\\MDCoreSvc" /v Start /t REG_DWORD /d 4 /f');
136+
137+
RegistryUtilsService.deleteValue(
138+
Registry.localMachine,
139+
r'SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',
140+
'RevisionEnableDefenderCMD');
141+
131142
await _winPackageService.installPackage(WinPackageType.defenderRemoval);
132143
}
133144

lib/services/win_package_service.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ class WinPackageService {
4040
.lastWhereOrNull(
4141
(final element) => element.startsWith(packageType.packageName));
4242

43+
if (key == null) {
44+
return false;
45+
}
46+
47+
final int currentState = RegistryUtilsService.readInt(
48+
RegistryHive.localMachine, cbsPackagesRegPath + key, 'CurrentState')!;
49+
4350
// installation codes - https://forums.ivanti.com/s/article/Understand-Patch-installation-failure-codes?language=en_US
44-
return key != null &&
45-
RegistryUtilsService.readInt(RegistryHive.localMachine,
46-
cbsPackagesRegPath + key, 'CurrentState') !=
47-
5;
51+
return currentState != 5 || currentState != 4294967264;
4852
}
4953

5054
Future<void> downloadPackage(final WinPackageType packageType) async {

0 commit comments

Comments
 (0)