Skip to content

Commit 1faead2

Browse files
committed
3.1.5
1 parent 34d0f80 commit 1faead2

3 files changed

Lines changed: 131 additions & 18 deletions

File tree

StikDebug.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
"$(PROJECT_DIR)/StikDebug/idevice",
483483
);
484484
MACOSX_DEPLOYMENT_TARGET = 15.1;
485-
MARKETING_VERSION = 3.1.4;
485+
MARKETING_VERSION = 3.1.5;
486486
PRODUCT_BUNDLE_IDENTIFIER = com.stik.stikdebug;
487487
PRODUCT_NAME = "$(TARGET_NAME)";
488488
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -544,7 +544,7 @@
544544
"$(PROJECT_DIR)/StikDebug/idevice",
545545
);
546546
MACOSX_DEPLOYMENT_TARGET = 15.1;
547-
MARKETING_VERSION = 3.1.4;
547+
MARKETING_VERSION = 3.1.5;
548548
PRODUCT_BUNDLE_IDENTIFIER = com.stik.stikdebug;
549549
PRODUCT_NAME = "$(TARGET_NAME)";
550550
PROVISIONING_PROFILE_SPECIFIER = "";

StikDebug/Support/ProcessInfo+TXM.swift

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,72 @@
66
import Foundation
77

88
public extension ProcessInfo {
9+
var hasTXMClassic: Bool {
10+
ProcessInfo.processInfo.isiOSAppOnMac ? false : ProcessInfo.detectLocalTXM()
11+
}
12+
913
var hasTXM: Bool {
1014
if isTXMOverridden {
1115
return true
1216
}
1317

1418
return ProcessInfo.hasTXMSupport(
15-
operatingSystemVersion: operatingSystemVersion,
16-
localTXMDetector: ProcessInfo.detectLocalTXM
19+
isIOS266OrNewer: ProcessInfo.isIOS266OrNewer,
20+
hasTXMClassic: hasTXMClassic,
21+
hardwareIdentifier: hardwareIdentifier()
1722
)
1823
}
1924

2025
var isTXMOverridden: Bool {
2126
UserDefaults.standard.bool(forKey: UserDefaults.Keys.txmOverride)
2227
}
2328

24-
static func hasTXMSupport(
25-
operatingSystemVersion: OperatingSystemVersion,
26-
localTXMDetector: () -> Bool
29+
internal static func hasTXMSupport(
30+
isIOS266OrNewer: Bool,
31+
hasTXMClassic: Bool,
32+
hardwareIdentifier: String
2733
) -> Bool {
28-
guard operatingSystemVersion.majorVersion >= 26 else {
34+
if isIOS266OrNewer, !hasTXMClassic {
35+
let firstTXM = 14.2
36+
let iPadTXM = 14.5
37+
38+
if let ver = ProcessInfo.processInfo.deviceVersion(from: hardwareIdentifier) {
39+
if hardwareIdentifier.hasPrefix("iPad") {
40+
return ver >= iPadTXM
41+
} else {
42+
return ver >= firstTXM
43+
}
44+
}
45+
2946
return false
3047
}
31-
return localTXMDetector()
48+
49+
return hasTXMClassic
50+
}
51+
52+
func deviceVersion(from identifier: String) -> Double? {
53+
let iPhonePattern = #"iPhone(\d+),(\d+)"#
54+
let iPadPattern = #"iPad(\d+),(\d+)"#
55+
56+
let extractVersion: (_ pattern: String) -> Double? = { pattern in
57+
guard let regex = try? NSRegularExpression(pattern: pattern),
58+
let match = regex.firstMatch(
59+
in: identifier,
60+
range: NSRange(identifier.startIndex..., in: identifier)
61+
),
62+
let majorRange = Range(match.range(at: 1), in: identifier),
63+
let minorRange = Range(match.range(at: 2), in: identifier),
64+
let major = Double(identifier[majorRange]),
65+
let minor = Double(identifier[minorRange])
66+
else {
67+
return nil
68+
}
69+
70+
let divisor = pow(10.0, Double(String(Int(minor)).count))
71+
return major + (minor / divisor)
72+
}
73+
74+
return extractVersion(iPhonePattern) ?? extractVersion(iPadPattern)
3275
}
3376

3477
private static func detectLocalTXM() -> Bool {
@@ -41,4 +84,23 @@ public extension ProcessInfo {
4184
access("\($0)/usr/standalone/firmware/FUD/Ap,TrustedExecutionMonitor.img4", F_OK) == 0
4285
} ?? false
4386
}
87+
88+
private static var isIOS266OrNewer: Bool {
89+
if #available(iOS 26.6, *) {
90+
return true
91+
}
92+
93+
return false
94+
}
95+
96+
private func hardwareIdentifier() -> String {
97+
var systemInfo = utsname()
98+
uname(&systemInfo)
99+
100+
return withUnsafePointer(to: &systemInfo.machine) {
101+
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
102+
String(cString: $0)
103+
}
104+
}
105+
}
44106
}

StikDebugTests/StikDebugTests.swift

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,71 @@ import Testing
1111

1212
struct StikDebugTests {
1313

14-
@Test func txmDetectionIgnoresFirmwareFileBeforeIOS26() async throws {
15-
let isSupported = ProcessInfo.hasTXMSupport(
16-
operatingSystemVersion: OperatingSystemVersion(majorVersion: 18, minorVersion: 7, patchVersion: 2),
17-
localTXMDetector: { true }
14+
@Test func txmDetectionUsesClassicTXMBeforeIOS266() async throws {
15+
#expect(
16+
ProcessInfo.hasTXMSupport(
17+
isIOS266OrNewer: false,
18+
hasTXMClassic: false,
19+
hardwareIdentifier: "iPhone15,2"
20+
) == false
1821
)
22+
#expect(
23+
ProcessInfo.hasTXMSupport(
24+
isIOS266OrNewer: false,
25+
hasTXMClassic: true,
26+
hardwareIdentifier: "iPhone1,1"
27+
) == true
28+
)
29+
}
30+
31+
@Test func txmDetectionUsesClassicTXMWhenAvailableOnIOS266() async throws {
32+
#expect(
33+
ProcessInfo.hasTXMSupport(
34+
isIOS266OrNewer: true,
35+
hasTXMClassic: true,
36+
hardwareIdentifier: "iPhone1,1"
37+
) == true
38+
)
39+
}
1940

20-
#expect(isSupported == false)
41+
@Test func txmDetectionFallsBackToIPhoneThresholdOnIOS266() async throws {
42+
#expect(
43+
ProcessInfo.hasTXMSupport(
44+
isIOS266OrNewer: true,
45+
hasTXMClassic: false,
46+
hardwareIdentifier: "iPhone14,1"
47+
) == false
48+
)
49+
#expect(
50+
ProcessInfo.hasTXMSupport(
51+
isIOS266OrNewer: true,
52+
hasTXMClassic: false,
53+
hardwareIdentifier: "iPhone14,2"
54+
) == true
55+
)
2156
}
2257

23-
@Test func txmDetectionRequiresLocalTXMOnIOS26() async throws {
24-
let iOS26 = OperatingSystemVersion(majorVersion: 26, minorVersion: 0, patchVersion: 0)
58+
@Test func txmDetectionFallsBackToIPadThresholdOnIOS266() async throws {
59+
#expect(
60+
ProcessInfo.hasTXMSupport(
61+
isIOS266OrNewer: true,
62+
hasTXMClassic: false,
63+
hardwareIdentifier: "iPad14,4"
64+
) == false
65+
)
66+
#expect(
67+
ProcessInfo.hasTXMSupport(
68+
isIOS266OrNewer: true,
69+
hasTXMClassic: false,
70+
hardwareIdentifier: "iPad14,5"
71+
) == true
72+
)
73+
}
2574

26-
#expect(ProcessInfo.hasTXMSupport(operatingSystemVersion: iOS26, localTXMDetector: { false }) == false)
27-
#expect(ProcessInfo.hasTXMSupport(operatingSystemVersion: iOS26, localTXMDetector: { true }) == true)
75+
@Test func deviceVersionParsesSupportedIdentifiers() async throws {
76+
#expect(ProcessInfo.processInfo.deviceVersion(from: "iPhone14,2") == 14.2)
77+
#expect(ProcessInfo.processInfo.deviceVersion(from: "iPad14,5") == 14.5)
78+
#expect(ProcessInfo.processInfo.deviceVersion(from: "Mac14,2") == nil)
2879
}
2980

3081
}

0 commit comments

Comments
 (0)