From 49523e0006a44fc60f60d9254f876bf90560bc98 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Thu, 7 Mar 2024 02:30:46 +0100 Subject: [PATCH] Re-instate copyable device bundles. --- HotReloading | 2 +- InjectionIII/Info.plist | 2 +- InjectionIII/build_bundles.sh | 4 ++- README.md | 48 ++++++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/HotReloading b/HotReloading index 884e916c..be4a57fb 160000 --- a/HotReloading +++ b/HotReloading @@ -1 +1 @@ -Subproject commit 884e916c8ca59e66ad64960bc208659e8da7acf3 +Subproject commit be4a57fbe283f5c16b6a5a5464ba6e56f1062dd8 diff --git a/InjectionIII/Info.plist b/InjectionIII/Info.plist index b9904bb1..ddd77ce8 100644 --- a/InjectionIII/Info.plist +++ b/InjectionIII/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 7995 + 7999 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/InjectionIII/build_bundles.sh b/InjectionIII/build_bundles.sh index 7052bf35..11eeb62c 100755 --- a/InjectionIII/build_bundles.sh +++ b/InjectionIII/build_bundles.sh @@ -6,7 +6,7 @@ # Created by John Holdsworth on 04/10/2019. # Copyright © 2019 John Holdsworth. All rights reserved. # -# $Id: //depot/ResidentEval/InjectionIII/build_bundles.sh#88 $ +# $Id: //depot/ResidentEval/InjectionIII/build_bundles.sh#89 $ # # Injection has to assume a fixed path for Xcode.app as it uses @@ -44,6 +44,8 @@ function build_bundle () { #build_bundle macOS MacOSX macosx && if [ "$(hostname)" != "Johns-MacBook-Air.local" ]; then build_bundle xrOS XRSimulator xrsimulator + build_bundle tvdevOS AppleTVOS appletvos + build_bundle xrdevOS XROS xros fi build_bundle iOS iPhoneSimulator iphonesimulator && build_bundle tvOS AppleTVSimulator appletvsimulator && diff --git a/README.md b/README.md index 5b255165..7c83df18 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,13 @@ or removing methods as the `vtable` used for dispatch is itself a data structure which must not change over injection. Injection also can't work out what pieces of code need to be re-executed to update the display as discussed above. -Finally, Injection doesn't cope well with source files being -added/renamed/deleted during injection. You will need to +Also, don't get carried away with access control. `private` +properties and methods can't be injected directly, particularly +in extensions as they are not a `global` interposable symbol. +They generally inject indirectly as they can only be acessed +inside the file being injected but this can cause confusion. +Finally, Injection doesn't cope well with source files being +added/renamed/deleted during injection. You may need to build and relaunch your app or even close and reopen your project to clear out old Xcode build logs. @@ -134,10 +139,31 @@ of the InjectionIII.app, set a user default to opt-in and restart the app. ``` $ defaults write com.johnholdsworth.InjectionIII deviceUnlock any ``` -Then, instead of loading the injection bundles add the following -Swift Package to your project (*only during development*): -[HotReloading project](https://github.com/johnno1962/HotReloading). -This contains details on how to debug having your program connect to the +Then, instead of loading the injection bundles run this script in a "Build Phase": +(You may also need to turn off the project build setting "User Script Sandboxing") + +``` +RESOURCES=/Applications/InjectionIII.app/Contents/Resources +if [ -f "$RESOURCES/copy_bundle.sh" ]; then + "$RESOURCES/copy_bundle.sh" +fi +``` +and, in your application execute the following code on startup: + +``` + #if DEBUG + if let path = Bundle.main.path(forResource: + "iOSInjection", ofType: "bundle") ?? + Bundle.main.path(forResource: + "macOSInjection", ofType: "bundle") { + Bundle(path: path)!.load() + } + #endif +``` +Once you have switched to this configuaration it will also +work when using the simulator. Consult the README of the +[HotReloading project](https://github.com/johnno1962/HotReloading) +for details on how to debug having your program connect to the InjectionIII.app over Wi-Fi. You will also need to select the project directory for the file watcher manually from the pop-down menu. @@ -145,7 +171,9 @@ directory for the file watcher manually from the pop-down menu. It works but you need to temporarily turn off the "app sandbox" and "library validation" under the "hardened runtime" during development -so it can dynamically load code. +so it can dynamically load code. In order to avoid codesigning problems, +use the new `copy_bundle.sh` script as detailed in the instructions for +injection on an iOS device above. ### How it works @@ -209,7 +237,9 @@ file system to be a faithful simulation of a real device. and because you cannot load a bundle off your Mac's filesystem on a real phone you add the [HotReloading Swift Package](https://github.com/johnno1962/HotReloading) to your project (during development only!) which contains all the code that -would normally be in the bundle to perform the dynamic loading. +would normally be in the bundle to perform the dynamic loading. This +requires that you use one of the un-sandboxed binary releases. It has +also been replaced by the `copy_bundle.sh` script described above. "Standalone injection". This was the most recent evolution of the project where you don't run the app itself anymore but simply load one of the @@ -268,4 +298,4 @@ for the code to be evaluated using injection under an MIT license. The fabulous app icon is thanks to Katya of [pixel-mixer.com](http://pixel-mixer.com/). -$Date: 2024/03/06 $ +$Date: 2024/03/07 $