diff --git a/AltServer/Connections/RequestHandler.swift b/AltServer/Connections/RequestHandler.swift index 0a683a00..6d879951 100644 --- a/AltServer/Connections/RequestHandler.swift +++ b/AltServer/Connections/RequestHandler.swift @@ -155,21 +155,35 @@ struct ServerRequestHandler: RequestHandler case .success: ALTDeviceManager.shared.startDebugConnection(to: device) { (connection, error) in guard let connection = connection else { return completionHandler(.failure(error!)) } - - connection.enableUnsignedCodeExecutionForProcess(withID: request.processID) { (success, error) in + + func finish(success: Bool, error: Error?) + { if let error = error, !success { - print("Failed to enable unsigned code execution for process \(request.processID):", error) + print("Failed to enable unsigned code execution for process \(request.processID?.description ?? request.processName ?? "nil"):", error) completionHandler(.failure(ALTServerError(error))) } else { - print("Enabled unsigned code execution for process:", request.processID) + print("Enabled unsigned code execution for process:", request.processID ?? request.processName ?? "nil") let response = EnableUnsignedCodeExecutionResponse() completionHandler(.success(response)) } } + + if let processID = request.processID + { + connection.enableUnsignedCodeExecutionForProcess(withID: processID, completionHandler: finish) + } + else if let processName = request.processName + { + connection.enableUnsignedCodeExecutionForProcess(withName: processName, completionHandler: finish) + } + else + { + finish(success: false, error: ALTServerError(.invalidRequest)) + } } } } diff --git a/Shared/Server Protocol/ServerProtocol.swift b/Shared/Server Protocol/ServerProtocol.swift index bf6fcf45..2b0041c9 100644 --- a/Shared/Server Protocol/ServerProtocol.swift +++ b/Shared/Server Protocol/ServerProtocol.swift @@ -445,12 +445,14 @@ public struct EnableUnsignedCodeExecutionRequest: ServerMessageProtocol public var identifier = "EnableUnsignedCodeExecutionRequest" public var udid: String - public var processID: Int + public var processID: Int? + public var processName: String? - public init(udid: String, processID: Int) + public init(udid: String, processID: Int? = nil, processName: String? = nil) { self.udid = udid self.processID = processID + self.processName = processName } }