[AltJIT] Adds AltJIT CLI tool to enable JIT on devices running iOS 17+

Commands:

altjit enable [app/pid] --udid [udid]
* Enables JIT for given app/process

altjit mount --udid [udid]
* Mounts personalized developer disk
This commit is contained in:
Riley Testut
2023-09-07 18:00:53 -05:00
committed by Magesh K
parent f83303a6b7
commit a7b28d5027
19 changed files with 1539 additions and 1 deletions

View File

@@ -7,7 +7,10 @@
//
import Foundation
#if !ALTJIT
import AltSign
#endif
public let ALTLocalizedTitleErrorKey = "ALTLocalizedTitle"
public let ALTLocalizedDescriptionKey = "ALTLocalizedDescription"

View File

@@ -0,0 +1,52 @@
//
// JITError.swift
// AltJIT
//
// Created by Riley Testut on 9/3/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
extension JITError
{
enum Code: Int, ALTErrorCode
{
typealias Error = JITError
case processNotRunning
}
static func processNotRunning(_ process: AppProcess, file: StaticString = #file, line: Int = #line) -> JITError {
JITError(code: .processNotRunning, process: process, sourceFile: file, sourceLine: UInt(line))
}
}
struct JITError: ALTLocalizedError
{
let code: Code
var errorTitle: String?
var errorFailure: String?
@UserInfoValue var process: AppProcess?
var sourceFile: StaticString?
var sourceLine: UInt?
var errorFailureReason: String {
switch self.code
{
case .processNotRunning:
let targetName = self.process?.description ?? NSLocalizedString("The target app", comment: "")
return String(format: NSLocalizedString("%@ is not running.", comment: ""), targetName)
}
}
var recoverySuggestion: String? {
switch self.code
{
case .processNotRunning: return NSLocalizedString("Make sure the app is running in the foreground on your device then try again.", comment: "")
}
}
}

View File

@@ -0,0 +1,88 @@
//
// ProcessError.swift
// AltPackage
//
// Created by Riley Testut on 9/1/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
extension ProcessError
{
enum Code: Int, ALTErrorCode
{
typealias Error = ProcessError
case failed
case timedOut
case unexpectedOutput
case terminated
}
static func failed(executableURL: URL, exitCode: Int32, output: String?, file: StaticString = #file, line: Int = #line) -> ProcessError {
ProcessError(code: .failed, executableURL: executableURL, exitCode: exitCode, output: output, sourceFile: file, sourceLine: UInt(line))
}
static func timedOut(executableURL: URL, exitCode: Int32? = nil, output: String? = nil, file: StaticString = #file, line: Int = #line) -> ProcessError {
ProcessError(code: .timedOut, executableURL: executableURL, exitCode: exitCode, output: output, sourceFile: file, sourceLine: UInt(line))
}
static func unexpectedOutput(executableURL: URL, output: String, exitCode: Int32? = nil, file: StaticString = #file, line: Int = #line) -> ProcessError {
ProcessError(code: .unexpectedOutput, executableURL: executableURL, exitCode: exitCode, output: output, sourceFile: file, sourceLine: UInt(line))
}
static func terminated(executableURL: URL, exitCode: Int32, output: String, file: StaticString = #file, line: Int = #line) -> ProcessError {
ProcessError(code: .terminated, executableURL: executableURL, exitCode: exitCode, output: output, sourceFile: file, sourceLine: UInt(line))
}
}
struct ProcessError: ALTLocalizedError
{
let code: Code
var errorTitle: String?
var errorFailure: String?
@UserInfoValue var executableURL: URL?
@UserInfoValue var exitCode: Int32?
@UserInfoValue var output: String?
var sourceFile: StaticString?
var sourceLine: UInt?
var errorFailureReason: String {
switch self.code
{
case .failed:
guard let exitCode else { return String(format: NSLocalizedString("%@ failed.", comment: ""), self.processName) }
let baseMessage = String(format: NSLocalizedString("%@ failed with code %@.", comment: ""), self.processName, NSNumber(value: exitCode))
guard let lastLine = self.lastOutputLine else { return baseMessage }
let failureReason = baseMessage + " " + lastLine
return failureReason
case .timedOut: return String(format: NSLocalizedString("%@ timed out.", comment: ""), self.processName)
case .terminated: return String(format: NSLocalizedString("%@ unexpectedly quit.", comment: ""), self.processName)
case .unexpectedOutput:
let baseMessage = String(format: NSLocalizedString("%@ returned unexpected output.", comment: ""), self.processName)
guard let lastLine = self.lastOutputLine else { return baseMessage }
let failureReason = baseMessage + " " + lastLine
return failureReason
}
}
private var processName: String {
guard let executableName = self.executableURL?.lastPathComponent else { return NSLocalizedString("The process", comment: "") }
return String(format: NSLocalizedString("The process '%@'", comment: ""), executableName)
}
private var lastOutputLine: String? {
guard let output else { return nil }
let lastLine = output.components(separatedBy: .newlines).last(where: { !$0.isEmpty })
return lastLine
}
}