From e084f2a630d5fa2956de397c2a210dd1e8acdad8 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 11:14:50 +0800 Subject: [PATCH] Amethyst route: bring the Swift runtime, from iOS 12.0 Amethyst's executable brings no Swift runtime, so the route stopped at iOS 12.2. The payload now carries the app's back-deployment runtime in Resources/Frameworks, which lands in the host app's Frameworks next to ResizeAccess.dylib; the library searches there after /usr/lib/swift. Release 0.5.1. --- Device/README.md | 8 +++++--- README.md | 4 ++-- THIRD_PARTY_NOTICES.md | 3 ++- Tests/ReleaseTests/test_amethyst_route.py | 9 ++++++++ VERSION | 2 +- scripts/amethyst_route.py | 4 ++-- scripts/build-device-ios12.sh | 25 ++++++++++++++++++++--- scripts/launcher.py | 8 ++++---- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Device/README.md b/Device/README.md index 7cb3302..10805f3 100644 --- a/Device/README.md +++ b/Device/README.md @@ -196,7 +196,7 @@ the steps, what we depend on and what to do when something changed. ### Amethyst (iOS 12 and 13) -On iOS 12.2 to 13.7 the app is the official [Amethyst](https://github.com/staturnzz/amethyst) +On iOS 12.0 to 13.7 the app is the official [Amethyst](https://github.com/staturnzz/amethyst) release (1.1, pinned in `scripts/tools.py` like Dopamine) with Resize APFS in it, installed the same way (`scripts/amethyst_route.py`; xtool always signs, as Xcode builds nothing for iOS 12 and 13). The differences: @@ -224,8 +224,10 @@ and 13). The differences: opened again the app starts from its first page. Afterwards iOS runs from the live volume, so the app's existing "Remove snapshot" frees orig-fs before a shrink (Amethyst's own restore-rootfs needs orig-fs and stops working then). -- **iOS 12.2 and later only:** the library needs the Swift runtime that iOS 12.0 and 12.1 lack, - and Amethyst's executable brings none. The checkra1n route covers those versions. +- **The Swift runtime comes along.** Amethyst's executable brings none, so the payload carries + the app's back-deployment runtime in `Resources/Frameworks`, which lands in the app's + `Frameworks` next to the library. iOS 12.0 and 12.1 load it from there; 12.2 and later take + their own from `/usr/lib/swift`, searched first. Moving to a newer Amethyst: [docs/updating-amethyst.md](../docs/updating-amethyst.md). diff --git a/README.md b/README.md index cb73057..8e50a06 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ open Terminal in the `ResizeAPFS-v…` folder. Then pick the method for your dev | **DFU** (checkra1n) | A7 to A11 | 12 to 14 | | **Dopamine**, no DFU | A8 to A13 | 15.0 to 18.7.1, 26.0 to 26.0.1 | | | A14 and later | 15.0 to 17.3.1 | -| **Amethyst**, no DFU | every device | 12.2 to 13.7 | +| **Amethyst**, no DFU | every device | 12.0 to 13.7 | ### Via DFU (checkra1n / palera1n) @@ -57,7 +57,7 @@ app carries inside. ### Via Amethyst -For iOS 12.2 to 13.7, the iPhone 5s, iPad Air and iPad mini 2 and 3 included. +For iOS 12.0 to 13.7, the iPhone 5s, iPad Air and iPad mini 2 and 3 included. 1. Connect the device, unlock it and trust the computer. 2. Run `./resize-apfs boot --amethyst`. diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 2affc69..5edacce 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -86,7 +86,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The iOS 12-14 app (`out/device-ios12`) contains the Swift runtime and system -overlay libraries in `ResizeAPFS.app/Frameworks`, copied at build time from the +overlay libraries in `ResizeAPFS.app/Frameworks` (and the Amethyst payload's +`access/Resources/Frameworks`), copied at build time from the Xcode toolchain's back-deployment runtime (`usr/lib/swift-5.0/iphoneos`), because iOS 12.0 and 12.1 have no Swift runtime. They are part of the Swift project, licensed under the Apache License 2.0 with the Runtime Library Exception, which diff --git a/Tests/ReleaseTests/test_amethyst_route.py b/Tests/ReleaseTests/test_amethyst_route.py index 9e73c45..4bc12e9 100644 --- a/Tests/ReleaseTests/test_amethyst_route.py +++ b/Tests/ReleaseTests/test_amethyst_route.py @@ -49,6 +49,15 @@ def test_the_executable_built_from_source_takes_the_official_ones_place(self): self.assertEqual(archive.read(app + 'Base.lproj/LaunchScreen.storyboardc/Info.plist'), b'ours') self.assertNotIn(app + embed.HOST + '/Amethyst', archive.namelist()) + def test_the_swift_runtime_lands_next_to_the_library(self): + # Amethyst brings no Swift runtime: iOS 12.0 and 12.1 load the payload's. + (self.payload / 'Resources/Frameworks').mkdir(parents=True) + (self.payload / 'Resources/Frameworks/libswiftCore.dylib').write_bytes(b'runtime') + with self.prepared() as archive: + app = 'Payload/Amethyst.app/Frameworks/' + self.assertEqual(archive.read(app + 'libswiftCore.dylib'), b'runtime') + self.assertEqual(archive.read(app + 'ResizeAccess.dylib'), b'\xcf\xfa\xed\xfe library') + def test_the_official_stripped_executable_is_refused(self): with self.assertRaisesRegex(ValueError, 'run_jailbreak.*built from its source'): embed.check_amethyst(amethyst_executable(stripped=True)) diff --git a/VERSION b/VERSION index 8f0916f..4b9fcbe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/scripts/amethyst_route.py b/scripts/amethyst_route.py index 1614dea..3249d77 100644 --- a/scripts/amethyst_route.py +++ b/scripts/amethyst_route.py @@ -8,8 +8,8 @@ Access/AmethystBridge.m). On a device's first run the whole device restarts once, while Amethyst sets iOS's system snapshot aside; the user opens the app again afterwards. -iOS 12.0 and 12.1 are not served: the app's library needs the Swift runtime that iOS has from -12.2 on, and Amethyst's executable brings none (the checkra1n route covers them). +Amethyst's executable brings no Swift runtime, so the payload brings the app's back-deployment +runtime (scripts/build-device-ios12.sh): iOS 12.0 and 12.1 load it from the app's Frameworks. xtool signs the app with the user's Apple ID and installs it, after one confirmation (sideload.py); where xtool has no release, the prepared app is left for the user to sign and diff --git a/scripts/build-device-ios12.sh b/scripts/build-device-ios12.sh index 105432f..f947aff 100755 --- a/scripts/build-device-ios12.sh +++ b/scripts/build-device-ios12.sh @@ -6,7 +6,7 @@ # also makes the compiler reject any API newer than iOS 12. # # Swift runtime: iOS 12.2 and later have it in /usr/lib/swift; iOS 12.0 and 12.1 do -# not. As Xcode does for apps, the app bundles Apple's back-deployment runtime +# not. As Xcode does for apps, the app (and the Amethyst payload) bundles Apple's back-deployment runtime # (toolchain usr/lib/swift-5.0/iphoneos) in ResizeAPFS.app/Frameworks, searched after # /usr/lib/swift, so the system copy wins wherever it exists. The checkra1n route # copies only the helper file; it always installs the app first and removes it last, @@ -98,8 +98,10 @@ for binary in "$app/ResizeAPFS" "$out/resize-helper"; do done # The app without DFU on iOS 12 and 13 (scripts/embed.py puts this into the pinned Amethyst app # on the user's computer): the interface as a library, the resources it needs, the helper, and -# Amethyst's executable built from its source (scripts/build-amethyst.sh). The library needs -# Swift in iOS (12.2 and later): it is loaded by Amethyst's executable, which brings no runtime. +# Amethyst's executable built from its source (scripts/build-amethyst.sh). Amethyst brings no +# Swift runtime, so the payload brings the app's back-deployment runtime in Resources/Frameworks, +# which lands in the host app's Frameworks next to the library: iOS 12.0 and 12.1 load it from +# there, iOS 12.2 and later take their own from /usr/lib/swift, searched first. access="$out/access" mkdir -p "$access/Resources" "$access/host" xcrun --sdk iphoneos clang -target "$target" -isysroot "$sdk" -Os -fobjc-arc -fmodules \ @@ -108,9 +110,26 @@ xcrun --sdk iphoneos clang -target "$target" -isysroot "$sdk" -Os -fobjc-arc -fm swiftc -parse-as-library -emit-library -module-name ResizeAccess -I "$build" -L "$build" -lResizeCore \ $(ls App/*.swift | grep -v '^App/AppDelegate.swift$') Access/StorageAccess.swift "$build/AmethystBridge.o" \ -Xlinker -install_name -Xlinker @executable_path/Frameworks/ResizeAccess.dylib \ + -Xlinker -rpath -Xlinker @executable_path/Frameworks \ -o "$access/ResizeAccess.dylib" first=$(xcrun otool -l "$access/ResizeAccess.dylib" | awk '/cmd LC_RPATH/ {getline; getline; print $2; exit}') [[ "$first" == /usr/lib/swift ]] || { echo "ResizeAccess.dylib must search /usr/lib/swift first, not $first." >&2; exit 1; } +mkdir -p "$access/Resources/Frameworks" +pending=$(rpath_libs "$access/ResizeAccess.dylib") +while [[ -n "$pending" ]]; do + next="" + for lib in $pending; do + [[ -f "$access/Resources/Frameworks/$lib" || ! -f "$app/Frameworks/$lib" ]] && continue + cp "$app/Frameworks/$lib" "$access/Resources/Frameworks/$lib" + next+=" $(rpath_libs "$app/Frameworks/$lib")" + done + pending=$(echo $next | tr ' ' '\n' | sort -u) +done +for binary in "$access/ResizeAccess.dylib" "$access"/Resources/Frameworks/*.dylib; do + for lib in $(strong_libs "$binary"); do + [[ -f "$access/Resources/Frameworks/$lib" ]] || { echo "$binary needs $lib, which iOS 12.0 lacks and which is not bundled." >&2; exit 1; } + done +done xcrun --sdk iphoneos strip -x "$access/ResizeAccess.dylib" codesign --force --sign - --timestamp=none "$access/ResizeAccess.dylib" cp "$app/Info.plist" "$access/Info.plist" diff --git a/scripts/launcher.py b/scripts/launcher.py index b8b788c..0e91d70 100644 --- a/scripts/launcher.py +++ b/scripts/launcher.py @@ -46,14 +46,14 @@ def route(given, dopamine=False, amethyst=False): require(given is None or given >= 15, 'The Dopamine route needs iOS/iPadOS 15 or later.') return 'dopamine' if amethyst: - require(given is None or given in (12, 13), 'The Amethyst route needs iOS/iPadOS 12.2 to 13.7.') + require(given is None or given in (12, 13), 'The Amethyst route needs iOS/iPadOS 12.0 to 13.7.') return 'amethyst' if given is None: print('iOS/iPadOS version on the device (Settings > General > About):\n' ' 1) 15 or later\n' ' 2) 12, 13 or 14\n' ' 3) 15 or later, without DFU: Dopamine (also iPhone XS, XR, 11 and other A12/A13 devices)\n' - ' 4) 12.2 to 13.7, without DFU: Amethyst (also iPhone 5s, iPad Air, iPad mini 2 and 3)') + ' 4) 12.0 to 13.7, without DFU: Amethyst (also iPhone 5s, iPad Air, iPad mini 2 and 3)') answer = input('> ').strip() require(answer in ('1', '2', '3', '4'), 'Please answer 1, 2, 3 or 4.') return {'1': 'palera1n', '2': 'checkra1n', '3': 'dopamine', '4': 'amethyst'}[answer] @@ -63,14 +63,14 @@ def route(given, dopamine=False, amethyst=False): def main(): parser = argparse.ArgumentParser(description='Prepare and boot Resize APFS: palera1n for iOS 15+, checkra1n for iOS 12-14, ' - 'Dopamine for iOS 15+ and Amethyst for iOS 12.2-13.7 without DFU.') + 'Dopamine for iOS 15+ and Amethyst for iOS 12.0-13.7 without DFU.') parser.add_argument('action', choices=['prepare', 'boot']) parser.add_argument('--ios', type=int, metavar='VERSION', help='the installed iOS major version (e.g. 15 or 12); skips the question') parser.add_argument('--dopamine', action='store_true', help='use Dopamine instead of DFU: the app installed with your Apple ID (iOS 15 or later); skips the question') parser.add_argument('--amethyst', action='store_true', - help='use Amethyst instead of DFU: the app installed with your Apple ID (iOS 12.2 to 13.7); skips the question') + help='use Amethyst instead of DFU: the app installed with your Apple ID (iOS 12.0 to 13.7); skips the question') parser.add_argument('--ssh', action='store_true', help='for developers, with Dopamine: also install an SSH server for root, reachable over USB ' 'only and only with your SSH public key (~/.ssh/id_ed25519.pub)')