From 63868a2ff08a8cb36428ad4dba70b5a9fb2aa3a7 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Tue, 9 May 2023 13:40:35 -0500 Subject: [PATCH] Fixes updating apps with manually-removed app extensions (e.g. uYou+) --- AltStore/Operations/ResignAppOperation.swift | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/AltStore/Operations/ResignAppOperation.swift b/AltStore/Operations/ResignAppOperation.swift index 571021a9..563f84e8 100644 --- a/AltStore/Operations/ResignAppOperation.swift +++ b/AltStore/Operations/ResignAppOperation.swift @@ -215,6 +215,7 @@ private extension ResignAppOperation // Prepare app try prepare(appBundle, additionalInfoDictionaryValues: additionalValues) + try self.removeMissingAppExtensionReferences(from: appBundle) if let directory = appBundle.builtInPlugInsURL, let enumerator = FileManager.default.enumerator(at: directory, includingPropertiesForKeys: nil, options: [.skipsSubdirectoryDescendants]) { @@ -263,4 +264,28 @@ private extension ResignAppOperation return progress } + + func removeMissingAppExtensionReferences(from bundle: Bundle) throws + { + // If app extensions have been removed from an app (either by AltStore or the developer), + // we must remove all references to them from SC_Info/Manifest.plist (if it exists). + + let scInfoURL = bundle.bundleURL.appendingPathComponent("SC_Info") + let manifestPlistURL = scInfoURL.appendingPathComponent("Manifest.plist") + + guard let manifestPlist = NSMutableDictionary(contentsOf: manifestPlistURL), let sinfReplicationPaths = manifestPlist["SinfReplicationPaths"] as? [String] else { return } + + // Remove references to missing files. + let filteredReplicationPaths = sinfReplicationPaths.filter { path in + guard let fileURL = URL(string: path, relativeTo: bundle.bundleURL) else { return false } + + let fileExists = FileManager.default.fileExists(atPath: fileURL.path) + return fileExists + } + + manifestPlist["SinfReplicationPaths"] = filteredReplicationPaths + + // Save updated Manifest.plist to disk. + try manifestPlist.write(to: manifestPlistURL) + } }