@@ -3,6 +3,7 @@ import 'dart:io';
33import 'package:collection/collection.dart' ;
44import 'package:mixin_logger/mixin_logger.dart' ;
55import 'package:revitool/services/network_service.dart' ;
6+ import 'package:revitool/services/win_package_service.dart' ;
67import 'package:win32_registry/win32_registry.dart' ;
78
89import '../utils.dart' ;
@@ -14,6 +15,7 @@ import 'package:path/path.dart' as p;
1415class SecurityService implements SetupService {
1516 static final _shell = Shell ();
1617 static final _networkService = NetworkService ();
18+ static final _winPackageService = WinPackageService ();
1719
1820 static const _instance = SecurityService ._private ();
1921
@@ -34,30 +36,28 @@ class SecurityService implements SetupService {
3436 }
3537
3638 bool get statusDefender {
37- const path =
38- r'SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\' ;
39- final String ? key = Registry .openPath (RegistryHive .localMachine, path: path)
40- .subkeyNames
41- .lastWhereOrNull ((element) =>
42- element.startsWith ("Revision-ReviOS-Defender-Removal" ));
43-
44- return key == null ||
45- RegistryUtilsService .readInt (
46- RegistryHive .localMachine, path + key, 'CurrentState' ) ==
47- 5 ; // installation codes - https://forums.ivanti.com/s/article/Understand-Patch-installation-failure-codes?language=en_US
39+ return ! _winPackageService
40+ .checkPackageInstalled (WinPackageType .defenderRemoval);
4841 }
4942
5043 bool get statusDefenderProtections {
51- return (RegistryUtilsService .readInt (
52- RegistryHive .localMachine,
53- r'SOFTWARE\Microsoft\Windows Defender\Features' ,
54- 'TamperProtection' ) !=
55- 4 ||
56- RegistryUtilsService .readInt (
57- RegistryHive .localMachine,
58- r'SOFTWARE\Microsoft\Windows Defender\Real-Time Protection' ,
59- 'DisableRealtimeMonitoring' ) !=
60- 1 );
44+ return statusDefenderProtectionTamper || statusDefenderProtectionRealtime;
45+ }
46+
47+ bool get statusDefenderProtectionTamper {
48+ return RegistryUtilsService .readInt (
49+ RegistryHive .localMachine,
50+ r'SOFTWARE\Microsoft\Windows Defender\Features' ,
51+ 'TamperProtection' ) !=
52+ 4 ;
53+ }
54+
55+ bool get statusDefenderProtectionRealtime {
56+ return RegistryUtilsService .readInt (
57+ RegistryHive .localMachine,
58+ r'SOFTWARE\Microsoft\Windows Defender\Real-Time Protection' ,
59+ 'DisableRealtimeMonitoring' ) !=
60+ 1 ;
6161 }
6262
6363 Future <ProcessResult > openDefenderThreatSettings () async {
@@ -86,8 +86,7 @@ class SecurityService implements SetupService {
8686 RegistryUtilsService .writeDword (Registry .localMachine,
8787 r'SOFTWARE\Microsoft\Windows Defender' , 'DisableAntiVirus' , 0 );
8888
89- await _shell.run (
90- 'PowerShell -NonInteractive -NoLogo -NoP -C "Get-WindowsPackage -Online -PackageName \' Revision-ReviOS-Defender-Removal*\' | Remove-WindowsPackage -Online -NoRestart"' );
89+ await _winPackageService.uninstallPackage (WinPackageType .defenderRemoval);
9190
9291 await _shell.run (
9392 'start /WAIT /MIN /B "" "%systemroot%\\ System32\\ gpupdate.exe" /Target:Computer /Force' );
@@ -103,27 +102,7 @@ class SecurityService implements SetupService {
103102 }
104103
105104 Future <void > disableDefender () async {
106- final cabPath = p.join (Directory .systemTemp.path, 'Revision-Tool' , 'CAB' );
107- if (await Directory (cabPath).exists ()) {
108- try {
109- await Directory (cabPath).delete (recursive: true );
110- } catch (e) {
111- stderr.writeln ('Failed to delete CAB directory: $e ' );
112- }
113- }
114-
115- final Map <String , dynamic > json =
116- await _networkService.getGHLatestRelease (ApiEndpoints .cabPackages);
117- final List <dynamic > assests = json['assets' ];
118- String name = '' ;
119-
120- final String downloadUrl = assests.firstWhereOrNull ((element) {
121- name = element['name' ];
122- return name
123- .startsWith ("Revision-ReviOS-Defender-Removal31bf3856ad364e35" ) &&
124- name.contains (RegistryUtilsService .cpuArch);
125- })['browser_download_url' ];
126- await _networkService.downloadFile (downloadUrl, "$cabPath \\ $name " );
105+ await _winPackageService.downloadPackage (WinPackageType .defenderRemoval);
127106
128107 RegistryUtilsService .writeDword (
129108 Registry .localMachine,
@@ -149,9 +128,7 @@ class SecurityService implements SetupService {
149128 await _shell.run (
150129 '"$directoryExe \\ MinSudo.exe" --NoLogo --TrustedInstaller reg add "HKLM\\ SOFTWARE\\ Microsoft\\ Windows Defender" /v DisableAntiVirus /t REG_DWORD /d 1 /f' );
151130
152- // running it via TrustedInstaller causes 'Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer'
153- await _shell.run (
154- "powershell -EP Unrestricted -NoLogo -NonInteractive -NoP -File \" $directoryExe \\ cab-installer.ps1\" -Path \" $cabPath \" " );
131+ await _winPackageService.installPackage (WinPackageType .defenderRemoval);
155132 }
156133
157134 bool get statusUAC {
0 commit comments