Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Catch Supersign analysis exceptions and improve Superdump ipc protocol
kabiroberaibd18ec9f3e37
diff --git a/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift b/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swiftindex 2cc1121..90f0351 100644--- a/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift+++ b/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift@@ -87,7 +87,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {var entitlements: Entitlements// if the executable doesn't already have entitlements, that's// okay. We don't have to throw an error.- if let entitlementsData = context.signerImpl.analyze(executable: executableURL),+ if let entitlementsData = try? context.signerImpl.analyze(executable: executableURL),let decodedEntitlements = try? PropertyListDecoder().decode(Entitlements.self, from: entitlementsData) {entitlements = decodedEntitlementsdiff --git a/Supersign/Model/Entitlements/Entitlements.swift b/Supersign/Model/Entitlements/Entitlements.swiftindex 6642f0f..7b87d60 100644--- a/Supersign/Model/Entitlements/Entitlements.swift+++ b/Supersign/Model/Entitlements/Entitlements.swift@@ -17,14 +17,10 @@ public struct EntitlementContainer: ProtoCodableContainer {// allows access to a parsable entitlements list while not losing unparsed entitlements when it's modifiedpublic struct Entitlements {- public enum Error: Swift.Error {- case dataCorrupted- }-private let decoder = PropertyListDecoder()private let encoder = PropertyListEncoder()- private var dict: [String: PlistItem]+ private var dict: [String: AnyEncodable]public init(entitlements: [Entitlement]) throws {dict = [:]@@ -49,9 +45,7 @@ public struct Entitlements {let newEnts = Dictionary(uniqueKeysWithValues: new.map { (type(of: $0).identifier, $0) })oldEnts.keys.filter { newEnts[$0] == nil }.forEach { dict[$0] = nil }- try newEnts.forEach {- dict[$0] = try PlistItem(value: $1.plistValue(withEncoder: encoder))- }+ newEnts.forEach { dict[$0] = AnyEncodable($1) }}public mutating func setEntitlements(_ new: [Entitlement]) throws {@@ -64,7 +58,8 @@ extension Entitlements: Codable {public init(from decoder: Decoder) throws {self.dict = try decoder.singleValueContainer()- .decode([String: PlistItem].self)+ .decode([String: CodableElement].self)+ .mapValues(AnyEncodable.init)}public func encode(to encoder: Encoder) throws {diff --git a/Supersign/SignerImpl/SignerImpl.swift b/Supersign/SignerImpl/SignerImpl.swiftindex c6e6099..cfbbccb 100644--- a/Supersign/SignerImpl/SignerImpl.swift+++ b/Supersign/SignerImpl/SignerImpl.swift@@ -20,6 +20,7 @@ public struct SignerImpl {public enum Error: LocalizedError {case notFound+ case badFilePathcase signer(String?)public var errorDescription: String? {@@ -28,6 +29,10 @@ public struct SignerImpl {return NSLocalizedString("signer_impl.error.not_found", value: "No signer implementation found", comment: "")+ case .badFilePath:+ return NSLocalizedString(+ "signer_impl.error.bad_file_path", value: "A bad file path was provided", comment: ""+ )case .signer(let error?):return errorcase .signer(nil):@@ -48,13 +53,12 @@ public struct SignerImpl {analyze = signer.analyze}- public static func all() -> [SignerImpl] {- CLinkedList(start: signer_list).map(SignerImpl.init)+ private static func all() -> AnySequence<SignerImpl> {+ .init(CLinkedList(first: signer_list).lazy.map(SignerImpl.init))}public static func first() throws -> SignerImpl {- guard let impl = all().first else { throw Error.notFound }- return impl+ try all().makeIterator().next().orThrow(Error.notFound)}private func _sign(@@ -68,10 +72,11 @@ public struct SignerImpl {encoder.outputFormat = .xmllet entsArray: [entitlements_data_t] = try entitlementMapping.map { url, ents intry url.withUnsafeFileSystemRepresentation { bundlePath in- try encoder.encode(ents).withUnsafeBytes { bytes in+ guard let bundlePath = bundlePath else { throw Error.badFilePath }+ return try encoder.encode(ents).withUnsafeBytes { bytes inlet bound = bytes.bindMemory(to: Int8.self)return entitlements_data_t(- bundle_path: bundlePath, data: bound.baseAddress, len: bound.count+ bundle_path: bundlePath, data: bound.baseAddress!, len: bound.count)}}@@ -87,11 +92,11 @@ public struct SignerImpl {guard sign(app.path,- certBound.baseAddress,+ certBound.baseAddress!,certBound.count,- privBound.baseAddress,+ privBound.baseAddress!,privBound.count,- ents.baseAddress,+ ents.baseAddress!,ents.count,progress,&exception@@ -127,13 +132,17 @@ public struct SignerImpl {}}- public func analyze(executable: URL) -> Data? {- executable.withUnsafeFileSystemRepresentation({ (path: UnsafePointer<Int8>?) -> Data? in+ public func analyze(executable: URL) throws -> Data {+ try executable.withUnsafeFileSystemRepresentation { (path: UnsafePointer<Int8>?) -> Data in+ var exception: UnsafeMutablePointer<Int8>?+ defer { exception.map { free($0) } }var len = 0- guard let out = analyze(path, &len) else { return nil }+ guard let out = analyze(path!, &len, &exception) else {+ throw Error.signer(exception.map { String(cString: $0) })+ }defer { free(out) }- return Data(bytes: UnsafeRawPointer(out), count: len)- })+ return Data(bytes: out, count: len)+ }}}