Skip to content

Commit

Permalink
Re-instate copyable device bundles.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Mar 7, 2024
1 parent 119af19 commit 49523e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion HotReloading
2 changes: 1 addition & 1 deletion InjectionIII/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>7995</string>
<string>7999</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 3 additions & 1 deletion InjectionIII/build_bundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 &&
Expand Down
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -134,18 +139,41 @@ 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.

### Injection on macOS

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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 $

0 comments on commit 49523e0

Please sign in to comment.