mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 14:53:25 +01:00
[AltServer] Supports enabling JIT on devices running iOS 17
AltServer embeds the AltJIT CLI tool in its app bundle and runs it as an admin subprocess.
This commit is contained in:
16
AltServer/Extensions/Logger+AltServer.swift
Normal file
16
AltServer/Extensions/Logger+AltServer.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Logger+AltServer.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 9/6/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import OSLog
|
||||
|
||||
extension Logger
|
||||
{
|
||||
static let altserverSubsystem = Bundle.main.bundleIdentifier!
|
||||
|
||||
static let main = Logger(subsystem: altserverSubsystem, category: "AltServer")
|
||||
}
|
||||
71
AltServer/Extensions/Process+STPrivilegedTask.swift
Normal file
71
AltServer/Extensions/Process+STPrivilegedTask.swift
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Process+STPrivilegedTask.swift
|
||||
// AltServer
|
||||
//
|
||||
// Created by Riley Testut on 8/22/23.
|
||||
// Copyright © 2023 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Security
|
||||
import OSLog
|
||||
|
||||
import STPrivilegedTask
|
||||
|
||||
extension Process
|
||||
{
|
||||
class func runAsAdmin(_ program: String, arguments: [String], authorization: AuthorizationRef? = nil) throws -> AuthorizationRef?
|
||||
{
|
||||
var launchPath = "/usr/bin/" + program
|
||||
if !FileManager.default.fileExists(atPath: launchPath)
|
||||
{
|
||||
launchPath = "/bin/" + program
|
||||
}
|
||||
|
||||
if !FileManager.default.fileExists(atPath: launchPath)
|
||||
{
|
||||
launchPath = program
|
||||
}
|
||||
|
||||
Logger.main.info("Launching admin process: \(launchPath, privacy: .public)")
|
||||
|
||||
let task = STPrivilegedTask()
|
||||
task.launchPath = launchPath
|
||||
task.arguments = arguments
|
||||
task.freeAuthorizationWhenDone = false
|
||||
|
||||
let errorCode: OSStatus
|
||||
|
||||
if let authorization = authorization
|
||||
{
|
||||
errorCode = task.launch(withAuthorization: authorization)
|
||||
}
|
||||
else
|
||||
{
|
||||
errorCode = task.launch()
|
||||
}
|
||||
|
||||
let executableURL = URL(fileURLWithPath: launchPath)
|
||||
guard errorCode == 0 else { throw ProcessError.failed(executableURL: executableURL, exitCode: errorCode, output: nil) }
|
||||
|
||||
task.waitUntilExit()
|
||||
|
||||
Logger.main.info("Admin process \(launchPath, privacy: .public) terminated with exit code \(task.terminationStatus, privacy: .public).")
|
||||
|
||||
guard task.terminationStatus == 0 else {
|
||||
let executableURL = URL(fileURLWithPath: launchPath)
|
||||
|
||||
let outputData = task.outputFileHandle.readDataToEndOfFile()
|
||||
if let outputString = String(data: outputData, encoding: .utf8), !outputString.isEmpty
|
||||
{
|
||||
throw ProcessError.failed(executableURL: executableURL, exitCode: task.terminationStatus, output: outputString)
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ProcessError.failed(executableURL: executableURL, exitCode: task.terminationStatus, output: nil)
|
||||
}
|
||||
}
|
||||
|
||||
return task.authorization
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user