From 8543bd6876bba85d2ed96f18d7c590f0ce69180c Mon Sep 17 00:00:00 2001 From: F1248 Date: Sun, 29 Dec 2024 13:00:06 +0100 Subject: [PATCH 01/11] Fix scrollbar overlapping content in `SystemInformationTabView` and `MaintenanceDataView` --- Genius/Views/Maintenance/MaintenanceDataView.swift | 2 +- Genius/Views/SystemInformation/SystemInformationTabView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Genius/Views/Maintenance/MaintenanceDataView.swift b/Genius/Views/Maintenance/MaintenanceDataView.swift index df410bd..8a151b5 100644 --- a/Genius/Views/Maintenance/MaintenanceDataView.swift +++ b/Genius/Views/Maintenance/MaintenanceDataView.swift @@ -65,7 +65,7 @@ struct MaintenanceDataView: View { } .frame(width: 512) } - .padding(.bottom) + .padding() } } } diff --git a/Genius/Views/SystemInformation/SystemInformationTabView.swift b/Genius/Views/SystemInformation/SystemInformationTabView.swift index 423b8e8..ca93963 100644 --- a/Genius/Views/SystemInformation/SystemInformationTabView.swift +++ b/Genius/Views/SystemInformation/SystemInformationTabView.swift @@ -69,7 +69,7 @@ struct SystemInformationTabView: View { } .frame(width: 512) } - .padding(.bottom) + .padding() } } } From f130ae7a4ac892f94bdfb508dc28081774743011 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 17:36:47 +0100 Subject: [PATCH 02/11] Improve firewall detection by using `socketfilterfw` --- Genius/Extensions/Swift/Bool.swift | 3 --- Genius/Models/Helpers/SystemProfiler.swift | 1 - Genius/Models/SystemInformation/MaintenanceChecks.swift | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index ab05d6d..12b0a9d 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -24,15 +24,12 @@ extension Bool: DataInitializable { "no", "false", "disabled", - "spfirewall_globalstate_allow_all", ]) { self = false } else if string.contains(any: [ "yes", "true", "enabled", - "spfirewall_globalstate_limit_connections", - "spfirewall_globalstate_block_all", ]) { self = true } else { return nil } diff --git a/Genius/Models/Helpers/SystemProfiler.swift b/Genius/Models/Helpers/SystemProfiler.swift index 36e8026..2fcea77 100644 --- a/Genius/Models/Helpers/SystemProfiler.swift +++ b/Genius/Models/Helpers/SystemProfiler.swift @@ -10,7 +10,6 @@ import Foundation enum SystemProfiler { - static let firewall = get("Firewall") static let hardware = get("Hardware") static let software = get("Software") diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index d63553d..7dc1a0d 100644 --- a/Genius/Models/SystemInformation/MaintenanceChecks.swift +++ b/Genius/Models/SystemInformation/MaintenanceChecks.swift @@ -39,7 +39,7 @@ extension SystemInformation { applicable: Software.OS.bootMode.value !=? .recovery ) static let firewall = SystemInformationData( - { Bool(SystemProfiler.firewall?["spfirewall_globalstate"]) }, + { Bool(Process("/usr/libexec/ApplicationFirewall/socketfilterfw", ["--getglobalstate"])?.runSafe()) }, applicable: Software.OS.bootMode.value !=? .recovery ) static let gatekeeper = SystemInformationData(Bool(Process("/usr/sbin/spctl", ["--status"])?.runSafe())) From 7376cd9b503a3564a7541e91c9d3b779e516f6f2 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 17:53:01 +0100 Subject: [PATCH 03/11] Fix activation lock being applicable in virtual machines --- Genius/Models/SystemInformation/MaintenanceChecks.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index 7dc1a0d..db80d35 100644 --- a/Genius/Models/SystemInformation/MaintenanceChecks.swift +++ b/Genius/Models/SystemInformation/MaintenanceChecks.swift @@ -16,7 +16,7 @@ extension SystemInformation { static let activationLock = SystemInformationData( { IORegistry(class: "IODTNVRAMVariables").keyExists("fmm-mobileme-token-FMM") }, - applicable: Hardware.securityChip.value >=? .t2 + applicable: Hardware.securityChip.value >=? .t2 &&? !?Hardware.Model.isVirtualMachine.value ) static let firmwarePassword = SystemInformationData( { Bool(Process("/usr/sbin/firmwarepasswd", ["-check"], requiresRoot: true)?.runSafe()) }, From 2e5364634915c1afccf991f3b4de1d5d8c3da073 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 17:59:49 +0100 Subject: [PATCH 04/11] Fix FileVault being unknown when disabled --- Genius/Extensions/Swift/Bool.swift | 2 ++ Genius/Models/SystemInformation/MaintenanceChecks.swift | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index 12b0a9d..d0e5469 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -22,12 +22,14 @@ extension Bool: DataInitializable { guard let string = (string as? String)?.lowercased() else { return nil } if string.contains(any: [ "no", + "off", "false", "disabled", ]) { self = false } else if string.contains(any: [ "yes", + "on", "true", "enabled", ]) { diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index db80d35..1413e39 100644 --- a/Genius/Models/SystemInformation/MaintenanceChecks.swift +++ b/Genius/Models/SystemInformation/MaintenanceChecks.swift @@ -27,7 +27,7 @@ extension SystemInformation { enum DataSecurity { static let fileVault = SystemInformationData( - { Bool(Process("/usr/bin/fdesetup", ["isactive"])?.runSafe()) }, + { Bool(Process("/usr/bin/fdesetup", ["status"])?.runSafe()) }, applicable: Software.OS.bootMode.value !=? .recovery ) } From fef75f365a87b688730f683d14bc6e7dd887c750 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 19:50:48 +0100 Subject: [PATCH 05/11] Simplify code --- Genius/Extensions/Foundation/Pipe.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Genius/Extensions/Foundation/Pipe.swift b/Genius/Extensions/Foundation/Pipe.swift index 1f24596..acaaca0 100644 --- a/Genius/Extensions/Foundation/Pipe.swift +++ b/Genius/Extensions/Foundation/Pipe.swift @@ -11,6 +11,6 @@ import Foundation extension Pipe { func read() -> String? { - String(try? fileHandleForReading.readToEnd()) + try? String(fileHandleForReading.readToEnd()) } } From c47e8c7d790cdce8a40fde5f872165d5da50c488 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 19:55:49 +0100 Subject: [PATCH 06/11] Simplify code --- Genius/Extensions/Swift/Bool.swift | 4 ++-- Genius/Models/SystemInformation/MaintenanceChecks.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index d0e5469..1c2ed86 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -18,8 +18,8 @@ extension Bool: DataInitializable { } } - init?(_ string: Any?) { - guard let string = (string as? String)?.lowercased() else { return nil } + init?(_ string: String?) { + guard let string = string?.lowercased() else { return nil } if string.contains(any: [ "no", "off", diff --git a/Genius/Models/SystemInformation/MaintenanceChecks.swift b/Genius/Models/SystemInformation/MaintenanceChecks.swift index 1413e39..c2e5629 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"]) }, + { Bool(SystemProfiler.software?["system_integrity"] as? String) }, applicable: Software.OS.bootMode.value !=? .recovery ) static let firewall = SystemInformationData( From 313c09855979603c1ebdb9c2b8277950bdba1b35 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 20:04:07 +0100 Subject: [PATCH 07/11] Fix provisioning UDID being unknown on Intel Macs in recoveryOS --- Genius/Models/SystemInformation/Hardware.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Genius/Models/SystemInformation/Hardware.swift b/Genius/Models/SystemInformation/Hardware.swift index e411918..4b6e463 100644 --- a/Genius/Models/SystemInformation/Hardware.swift +++ b/Genius/Models/SystemInformation/Hardware.swift @@ -119,7 +119,7 @@ extension SystemInformation { static let hardwareUUID = SystemInformationData(IORegistry(class: "IOPlatformExpertDevice").read(kIOPlatformUUIDKey)) static let provisioningUDID = SystemInformationData( - { SystemProfiler.hardware?["provisioning_UDID"] ?? (CPU.type.value == .intel ? hardwareUUID : nil) }, + { SystemProfiler.hardware?["provisioning_UDID"] ?? (CPU.type.value == .intel ? hardwareUUID.value : nil) }, applicable: Software.OS.bootMode.value !=? .recovery ||? CPU.type.value == .intel ) } From f4f5ca50a9dd5369f69ade6a1a61ff9b7d267352 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 20:11:44 +0100 Subject: [PATCH 08/11] Fix code order --- Genius/Models/SystemInformation/SystemInformationData.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Genius/Models/SystemInformation/SystemInformationData.swift b/Genius/Models/SystemInformation/SystemInformationData.swift index be045f5..a77d918 100644 --- a/Genius/Models/SystemInformation/SystemInformationData.swift +++ b/Genius/Models/SystemInformation/SystemInformationData.swift @@ -21,12 +21,12 @@ struct SystemInformationData: SystemInformationDataProtocol { } init(_ value: () -> T, applicable: Bool?) where T == W? { - self.applicable = applicable self.value = applicable ?? true ? value() : nil + self.applicable = applicable } init(_ value: () -> Any?, applicable: Bool?) where T == W? { - self.applicable = applicable self.value = applicable ?? true ? value() as? W : nil + self.applicable = applicable } } From 1be55ac473585af05de8a1c77864e8d54d3c0503 Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 20:15:47 +0100 Subject: [PATCH 09/11] Improve code readability --- .../Models/SystemInformation/Hardware.swift | 2 +- .../Models/SystemInformation/Software.swift | 19 ++++++++++++------- .../SystemInformationData.swift | 9 --------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Genius/Models/SystemInformation/Hardware.swift b/Genius/Models/SystemInformation/Hardware.swift index 4b6e463..b5fab12 100644 --- a/Genius/Models/SystemInformation/Hardware.swift +++ b/Genius/Models/SystemInformation/Hardware.swift @@ -119,7 +119,7 @@ extension SystemInformation { static let hardwareUUID = SystemInformationData(IORegistry(class: "IOPlatformExpertDevice").read(kIOPlatformUUIDKey)) static let provisioningUDID = SystemInformationData( - { SystemProfiler.hardware?["provisioning_UDID"] ?? (CPU.type.value == .intel ? hardwareUUID.value : nil) }, + { SystemProfiler.hardware?["provisioning_UDID"] as? String ?? (CPU.type.value == .intel ? hardwareUUID.value : nil) }, applicable: Software.OS.bootMode.value !=? .recovery ||? CPU.type.value == .intel ) } diff --git a/Genius/Models/SystemInformation/Software.swift b/Genius/Models/SystemInformation/Software.swift index 61d204c..f512409 100644 --- a/Genius/Models/SystemInformation/Software.swift +++ b/Genius/Models/SystemInformation/Software.swift @@ -16,7 +16,7 @@ extension SystemInformation { enum SMC { static let version = SystemInformationData( - { SystemProfiler.hardware?["SMC_version_system"] }, + { SystemProfiler.hardware?["SMC_version_system"] as? String }, applicable: Hardware.securityChip.value <=? .t1 &&? OS.bootMode.value !=? .recovery ) } @@ -24,7 +24,7 @@ extension SystemInformation { enum Firmware { static let version = SystemInformationData( - { SystemProfiler.hardware?["boot_rom_version"] }, + { SystemProfiler.hardware?["boot_rom_version"] as? String }, applicable: OS.bootMode.value !=? .recovery ) } @@ -61,15 +61,20 @@ extension SystemInformation { safe ? .safe : .normal } else { nil } }()) - static let bootVolume = - SystemInformationData({ SystemProfiler.software?["boot_volume"] }, applicable: bootMode.value !=? .recovery) - static let loaderVersion = - SystemInformationData({ SystemProfiler.hardware?["os_loader_version"] }, applicable: bootMode.value !=? .recovery) + static let bootVolume = SystemInformationData( + { SystemProfiler.software?["boot_volume"] as? String }, + applicable: bootMode.value !=? .recovery + ) + static let loaderVersion = SystemInformationData( + { SystemProfiler.hardware?["os_loader_version"] as? String }, + applicable: bootMode.value !=? .recovery + ) } enum Computer { - static let name = SystemInformationData(SystemProfiler.software?["local_host_name"] ?? Host.current().localizedName) + static let name = + SystemInformationData(SystemProfiler.software?["local_host_name"] as? String ?? Host.current().localizedName) static let hostName = SystemInformationData(Sysctl.read("kern.hostname")) } diff --git a/Genius/Models/SystemInformation/SystemInformationData.swift b/Genius/Models/SystemInformation/SystemInformationData.swift index a77d918..46bc1f4 100644 --- a/Genius/Models/SystemInformation/SystemInformationData.swift +++ b/Genius/Models/SystemInformation/SystemInformationData.swift @@ -16,17 +16,8 @@ struct SystemInformationData: SystemInformationDataProtocol { self.applicable = true } - init(_ value: Any?) where T == W? { - self.init(value as? W) - } - init(_ value: () -> T, applicable: Bool?) where T == W? { self.value = applicable ?? true ? value() : nil self.applicable = applicable } - - init(_ value: () -> Any?, applicable: Bool?) where T == W? { - self.value = applicable ?? true ? value() as? W : nil - self.applicable = applicable - } } From 819f1de9c49e3a1a3079c3dafee3c3734b311c3a Mon Sep 17 00:00:00 2001 From: F1248 Date: Mon, 30 Dec 2024 23:13:43 +0100 Subject: [PATCH 10/11] Improve `Bool` initializer `init?(_: String?)` --- Genius/Extensions/Swift/Bool.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Genius/Extensions/Swift/Bool.swift b/Genius/Extensions/Swift/Bool.swift index 1c2ed86..0750317 100644 --- a/Genius/Extensions/Swift/Bool.swift +++ b/Genius/Extensions/Swift/Bool.swift @@ -19,21 +19,23 @@ extension Bool: DataInitializable { } init?(_ string: String?) { - guard let string = string?.lowercased() else { return nil } + guard + let string = string.map({ $0[($0.range(of: ":", options: .backwards)?.upperBound ?? $0.startIndex)...] })?.lowercased() + else { return nil } if string.contains(any: [ - "no", - "off", - "false", - "disabled", - ]) { - self = false - } else if string.contains(any: [ "yes", "on", "true", "enabled", ]) { self = true + } else if string.contains(any: [ + "no", + "off", + "false", + "disabled", + ]) { + self = false } else { return nil } } } From 0d4869532bc9f2226c007ece16673eda2d2d1908 Mon Sep 17 00:00:00 2001 From: F1248 Date: Tue, 31 Dec 2024 00:33:42 +0100 Subject: [PATCH 11/11] 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(