-
-
Notifications
You must be signed in to change notification settings - Fork 312
feat: allow injecting into all extensions #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
waruhachi
wants to merge
4
commits into
claration:main
Choose a base branch
from
waruhachi:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ class TweakHandler { | |||||||||||||||||||||||||
| private let _fileManager = FileManager.default | ||||||||||||||||||||||||||
| private var _urlsToInject: [URL] = [] | ||||||||||||||||||||||||||
| private var _directoriesToCheck: [URL] = [] | ||||||||||||||||||||||||||
| private var _injectedDylibNames: [String] = [] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private let _app: URL | ||||||||||||||||||||||||||
| private var _options: Options | ||||||||||||||||||||||||||
|
|
@@ -94,6 +95,11 @@ class TweakHandler { | |||||||||||||||||||||||||
| try await _handleExtractedDirectoryContents(at: _urlsToInject) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // inject into all extensions if enabled | ||||||||||||||||||||||||||
| if !_injectedDylibNames.isEmpty { | ||||||||||||||||||||||||||
| _injectIntoAllExtensions(dylibNames: _injectedDylibNames) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // finally, handle extracted contents | ||||||||||||||||||||||||||
|
|
@@ -157,6 +163,8 @@ class TweakHandler { | |||||||||||||||||||||||||
| appExecutable: appexe.path, | ||||||||||||||||||||||||||
| with: "\(_options.injectPath.rawValue)\(injectFolder.rawValue)\(destinationURL.lastPathComponent)" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| _injectedDylibNames.append(destinationURL.lastPathComponent) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Inject imported framework dir | ||||||||||||||||||||||||||
|
|
@@ -249,6 +257,92 @@ class TweakHandler { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Discovers all .appex bundles in the app's PlugIns and Extensions directories | ||||||||||||||||||||||||||
| private func _discoverAppExtensions() -> [URL] { | ||||||||||||||||||||||||||
| var extensions: [URL] = [] | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let plugInsPath = _app.appendingPathComponent("PlugIns") | ||||||||||||||||||||||||||
| let extensionsPath = _app.appendingPathComponent("Extensions") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for directory in [plugInsPath, extensionsPath] { | ||||||||||||||||||||||||||
| guard _fileManager.fileExists(atPath: directory.path) else { continue } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||
| let contents = try _fileManager.contentsOfDirectory( | ||||||||||||||||||||||||||
| at: directory, | ||||||||||||||||||||||||||
| includingPropertiesForKeys: nil, | ||||||||||||||||||||||||||
| options: [.skipsHiddenFiles] | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let appexBundles = contents.filter { url in | ||||||||||||||||||||||||||
| url.pathExtension.lowercased() == "appex" && url.hasDirectoryPath | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extensions.append(contentsOf: appexBundles) | ||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||
| Logger.misc.warning("Failed to enumerate \(directory.path): \(error.localizedDescription)") | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return extensions | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Injects a dylib into an extension's executable | ||||||||||||||||||||||||||
| private func _injectIntoExtension(extensionURL: URL, dylibName: String) { | ||||||||||||||||||||||||||
| guard let extensionBundle = Bundle(url: extensionURL), | ||||||||||||||||||||||||||
| let extensionExecutable = extensionBundle.executableURL else { | ||||||||||||||||||||||||||
| Logger.misc.warning("Skipping \(extensionURL.lastPathComponent): couldn't read bundle") | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+293
to
+297
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| var injectFolder = _options.injectFolder | ||||||||||||||||||||||||||
| if _options.injectPath == .rpath && _options.injectFolder == .frameworks { | ||||||||||||||||||||||||||
| injectFolder = .root | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let injectPath: String | ||||||||||||||||||||||||||
| if _options.injectPath == .rpath { | ||||||||||||||||||||||||||
| injectPath = "@rpath/\(dylibName)" | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| if injectFolder == .frameworks { | ||||||||||||||||||||||||||
| injectPath = "@executable_path/../../Frameworks/\(dylibName)" | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| injectPath = "@executable_path/../../\(dylibName)" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let success = Zsign.injectDyLib( | ||||||||||||||||||||||||||
| appExecutable: extensionExecutable.path, | ||||||||||||||||||||||||||
| with: injectPath | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if success { | ||||||||||||||||||||||||||
| Logger.misc.info("Injected \(dylibName) into extension: \(extensionURL.lastPathComponent)") | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| Logger.misc.warning("Failed to inject into extension: \(extensionURL.lastPathComponent)") | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Injects all dylibs into all discovered extensions | ||||||||||||||||||||||||||
| private func _injectIntoAllExtensions(dylibNames: [String]) { | ||||||||||||||||||||||||||
| guard _options.injectIntoExtensions else { return } | ||||||||||||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let extensions = _discoverAppExtensions() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| guard !extensions.isEmpty else { | ||||||||||||||||||||||||||
| Logger.misc.info("No app extensions found for injection") | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Logger.misc.info("Found \(extensions.count) app extension(s) for injection") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for extensionURL in extensions { | ||||||||||||||||||||||||||
| for dylibName in dylibNames { | ||||||||||||||||||||||||||
| _injectIntoExtension(extensionURL: extensionURL, dylibName: dylibName) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // MARK: - Find correct files in debs | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.