Skip to content

Instantly share code, notes, and snippets.

@johnno1962
Last active November 23, 2022 02:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnno1962/1eb00f8d58c1919c0e7547b6d5bf8c02 to your computer and use it in GitHub Desktop.
Save johnno1962/1eb00f8d58c1919c0e7547b6d5bf8c02 to your computer and use it in GitHub Desktop.
Injection Injection

InjectionIII is an app available that provides "code injection" functionality allowing you to update the implementation of functions, memeber function and SwiftUI content body properties without having to restart your application. This can be useful to iterate over code or design without having to rebuild and restart your application continuously.

https://github.com/johnno1962/InjectionIII

Part of the implementation of injection is that it requires a user to add the following line somewhere in their code:

Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()

This "bundle" sets up a service which is notified when source files in a project have been changed and recompiles and dynamically loads a .dylib with the new implemntation of the members of the source file which is in effect swizzled in using the dyld_dynamic_interpose api (http://johnholdsworth.com/dyld_dynamic_interpose.html)

A recent blog noted that it is possible to "inject" (in another sence) dylibs into the startup of appications in the iOS simulator by specifying a DYLD_INSERT_LIBRARIES environment variable for the appllication startup using launchd.

https://curvedlayer.com/2020/08/09/ios-simulator-plugin-simctl.html

I'd like to explore whether it is possible to use this to bootstap the injection bundle into an application without the user having to modify their app (converting the bundle executable into a dylib). Unfortunately I've not been able to find the syntax of the command line utility simctl. It's possible to inject "system" application such as Springboard using a command such as the following:

xcrun simctl spawn booted launchctl debug system/com.apple.SpringBoard --environment DYLD_INSERT_LIBRARIES=/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection

If you wanted to inject an app with bundle id of say com.johnholdsworth.myapp would the command be the following?

xcrun simctl spawn booted launchctl debug gui/501/com.johnholdsworth.myapp --environment DYLD_INSERT_LIBRARIES=/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection

This doesn't seem to work giving an error:

Unrecognized target specifier. <service-target> takes a form of <domain-target>/<service-id>.

Would it be possible to know the syntax of this specifier for the simulator version of launchd?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment