From 0d4869532bc9f2226c007ece16673eda2d2d1908 Mon Sep 17 00:00:00 2001 From: F1248 Date: Tue, 31 Dec 2024 00:33:42 +0100 Subject: [PATCH] Improve SIP detection by using `csrutil` --- Genius/Extensions/Swift/Bool.swift | 4 ++-- Genius/Extensions/Swift/StringProtocol.swift | 8 ++++++-- Genius/Models/SystemInformation/MaintenanceChecks.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index 0750317..c898e11 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -22,14 +22,14 @@ extension Bool: DataInitializable { guard let string = string.map({ $0[($0.range(of: ":", options: .backwards)?.upperBound ?? $0.startIndex)...] })?.lowercased() else { return nil } - if string.contains(any: [ + if string.contains(anyWholeWord: [ "yes", "on", "true", "enabled", ]) { self = true - } else if string.contains(any: [ + } else if string.contains(anyWholeWord: [ "no", "off", "false", diff --git a/Genius/Extensions/Swift/StringProtocol.swift b/Genius/Extensions/Swift/StringProtocol.swift index 9c74adf..18e2e6a 100644 --- a/Genius/Extensions/Swift/StringProtocol.swift +++ b/Genius/Extensions/Swift/StringProtocol.swift @@ -19,8 +19,12 @@ extension StringProtocol { self.init(data) } - func contains(any strings: [some StringProtocol]) -> Bool { - strings.contains(where: contains) + func contains(anyWholeWord strings: [String]) -> Bool { + strings.contains { contains(wholeWord: $0) } + } + + func contains(wholeWord: String) -> Bool { + components(separatedBy: .alphanumerics.inverted).contains(wholeWord) } func remove(_ string: some StringProtocol) -> String { diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index c2e5629..a61fcc7 100644 --- a/Genius/Models/SystemInformation/MaintenanceChecks.swift +++ b/Genius/Models/SystemInformation/MaintenanceChecks.swift @@ -35,7 +35,7 @@ extension SystemInformation { enum MalwareProtection { static let systemIntegrityProtection = SystemInformationData( - { Bool(SystemProfiler.software?["system_integrity"] as? String) }, + { Bool(Process("/usr/bin/csrutil", ["status"])?.runSafe()) }, applicable: Software.OS.bootMode.value !=? .recovery ) static let firewall = SystemInformationData(