Skip to content

Commit

Permalink
fix: deny loader usage if very specific edge-case is detected
Browse files Browse the repository at this point in the history
This is for when the user chooses to have a hidden environment, but manually removed via a file manager or command line without rebooting fully. This shouldn't happen after a re-jailbreak as palera1n will automatically fix any missing symlinks for rootless.
  • Loading branch information
khcrysalis committed Aug 1, 2024
1 parent 313924b commit 13f7aa0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
59 changes: 44 additions & 15 deletions palera1nLoader/Configuration/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ var device: String {
}

enum jbStatus {
case simulated
case rootful
case rootless
case simulated
case rootful
case rootless
}

enum installStatus {
case rootful_installed
case rootless_installed
case rootless_partial
case none
}

Expand Down Expand Up @@ -58,20 +59,31 @@ class Status {
}()
}

static public func installation() -> jbStatus {
#if targetEnvironment(simulator)
return .simulated
#else
if paleInfo.palerain_option_rootful {
static func bootmanifestHash() -> String? {
let registryEntry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/chosen")

guard let bootManifestHashUnmanaged = IORegistryEntryCreateCFProperty(registryEntry, "boot-manifest-hash" as CFString, kCFAllocatorDefault, 0),
let bootManifestHash = bootManifestHashUnmanaged.takeRetainedValue() as? Data else {
return nil
}

return bootManifestHash.map { String(format: "%02X", $0) }.joined()
}

static public func installation() -> jbStatus {
#if targetEnvironment(simulator)
return .simulated
#else
if paleInfo.palerain_option_rootful {
return .rootful
}
}

if paleInfo.palerain_option_rootless {
if paleInfo.palerain_option_rootless {
return .rootless
}
return .rootless
#endif
}
}
return .rootless
#endif
}

static public func checkInstallStatus() -> installStatus {
#if targetEnvironment(simulator)
Expand All @@ -87,9 +99,26 @@ class Status {
if FileManager.default.fileExists(atPath: "/var/jb/.procursus_strapped") {
return .rootless_installed
}

if let bootManifestHash = bootmanifestHash() {
let directoryPath = "/private/preboot/\(bootManifestHash)"
let fileManager = FileManager.default

do {
let fileURLs = try fileManager.contentsOfDirectory(at: URL(fileURLWithPath: directoryPath), includingPropertiesForKeys: nil)
let matchingFiles = fileURLs.filter { $0.lastPathComponent.hasPrefix("jb-") }

if !matchingFiles.isEmpty {
return .rootless_partial
}
} catch {
print("Error accessing directory: \(error)")
}
}
}

return .none
#endif
}

}

3 changes: 3 additions & 0 deletions palera1nLoader/View/ManagerActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ extension ViewController {
}

actions.append(managerAction)
case (.rootless, .rootless_partial):
log(type: .fatal, msg: String.localized("Detected partial rootless installation (missing /var/jb). Please rejailbreak with palera1n and try again"))
return
default: break
}

Expand Down

0 comments on commit 13f7aa0

Please sign in to comment.