|
| 1 | +# Reductant Translator |
| 2 | +**Translate and patch arm64e binaries or macOS arm64 binaries to run on an arm64 iPhones at runtime.** |
| 3 | + |
| 4 | +As Macs move to ARM, there are many official command-line tools from Apple, Homebrew or others. But the instructions in these binaries are at least ARMv8.3+ since the first arm Mac was based on A12z. |
| 5 | +You can run these utilities directly on arm64e iDevices, if there are dependent libraries on iOS. If not, it's this tool's turn: |
| 6 | + |
| 7 | +- If your iDevice is arm64, you can run them with this tool. |
| 8 | +- If your binaries are linked with macOS frameworks, you can run them with this tool and a dyld_shared_caches_arm64e from macOS. |
| 9 | + |
| 10 | +You can replace **these binaries provided by me**: |
| 11 | +- A patched dyld from macOS 11.4. |
| 12 | +- A customized [Dobby](https://github.com/jmpews/Dobby) Framework. |
| 13 | +- [mimalloc.a](https://github.com/microsoft/mimalloc) built for arm64 iOS. |
| 14 | + |
| 15 | +## Build options in `build.sh` |
| 16 | + |
| 17 | +- enable_dobby_hook Use a custom [Dobby Framework](https://github.com/jmpews/Dobby) to optimize a (CAS + B) sequence. This obviously improve performance. |
| 18 | + |
| 19 | +Requirements: Xcode 12 or later. |
| 20 | + |
| 21 | +## Environment variables |
| 22 | + |
| 23 | +- `RT_OUT_OF_PROCESS=[whatever]` Do not inject threads in target process. |
| 24 | +- `RT_EMULATE_TIME=[whatever]` Do not hook mach_continuous_time. |
| 25 | +- `RT_DYLD_SHARED_CACHE_DIR=[path to dyld_share_cache]` Specify the dyld_share_cache path. It defaults to "/System/macOSSupport/dyld" if exists. Otherwise use the system one. |
| 26 | +- `RT_DYLD_INSERT_LIBRARIES=[libraries to insert]` Pass this env to dyld as `DYLD_INSERT_LIBRARIES`. Default is `/System/macOSSupport/usr/lib/rt_hooker.dylib` to support in-process translating and hooking, and other necessary patches. |
| 27 | +- `RT_DYLD_ROOT_PATH=[libraries to insert]` Pass this env to dyld as `DYLD_ROOT_PATH`. |
| 28 | +- `RT_ARM64_RUNNER_PATH=[path to a binary]` Creating a process with a arm64 binary. Then map the real binary arm64e default) into this process. |
| 29 | +- `RT_FORCE_ARM64_RUNNER=[whatever]` Creating a process with a arm64 binary. Then force map the real binary into this process. (arm64e only runs in this mode.) |
| 30 | +- `RT_DYLD_PATH=[dyld path]` Dyld path, default use a builtin dyld. |
| 31 | +- `RT_DISABLE_DOBBY_HOOK=[whatever]` Disable dobby hook if the build option `enable_dobby_hook` is enabled. |
| 32 | + |
| 33 | +The detail behaviors can be easly gotten in codes. |
| 34 | + |
| 35 | +## Known issues |
| 36 | + |
| 37 | +- NSURLSession will get a `kCFURLErrorCannotFindHost` error with macOS 11 dyld_shared_cache on iOS 13. (iOS 14 is OK.) |
| 38 | +- Metal is not available except A12z or M1 iPad due to missing binary for `/System/Library/Extensions/AGXMetalxxx` in dyld_shared_cache. (I have not tested these iPad, maybe Metal parallel computing works.) |
| 39 | +- `fork()` and `spawn()` is not work properly which means you can not use bash/zsh or other utilities depended on them from macOS. (This can be fixed by hooking.) |
| 40 | +- Some libproc-based (such as `proc_pidinfo(PROC_PIDPATHINFO)`) processes viewer will only treat `arm64_runner` as the process executable. This cannot be fixed because XNU uses the vnode of the executable when `spawn()`. |
| 41 | +- Code signing issues are dependent on your jailbreak tools. |
| 42 | +- A bad mach-o may crash this tool. |
| 43 | + |
| 44 | +## Example |
| 45 | + |
| 46 | +``` sh |
| 47 | +mobile@iPhone-7-Plus ~ % ./rt_spawn ./geekbench_aarch64 |
| 48 | +Geekbench 5.4.2 Corporate : https://www.geekbench.com/ |
| 49 | + |
| 50 | +System Information |
| 51 | + Operating System macOS 14.8 (Build 18H17) |
| 52 | + Model D11AP |
| 53 | + Model ID D11AP |
| 54 | + Motherboard D11AP |
| 55 | + |
| 56 | +Processor Information |
| 57 | + Name Apple processor |
| 58 | + Topology 1 Processor, 2 Cores |
| 59 | + Identifier Apple processor |
| 60 | + Base Frequency 2.33 GHz |
| 61 | + L1 Instruction Cache 64.0 KB |
| 62 | + L1 Data Cache 64.0 KB |
| 63 | + L2 Cache 3.00 MB |
| 64 | + |
| 65 | +Memory Information |
| 66 | + Size 2.93 GB |
| 67 | + |
| 68 | + |
| 69 | +Single-Core |
| 70 | + AES-XTS 1121 1.91 GB/sec |
| 71 | + Text Compression 682 3.45 MB/sec |
| 72 | + Image Compression 744 35.2 Mpixels/sec |
| 73 | + Navigation 727 2.05 MTE/sec |
| 74 | + HTML5 724 849.8 KElements/sec |
| 75 | + SQLite 806 252.6 Krows/sec |
| 76 | + PDF Rendering 112 6.07 Mpixels/sec |
| 77 | + Text Rendering 824 262.7 KB/sec |
| 78 | + Clang 673 5.24 Klines/sec |
| 79 | + Camera 760 8.82 images/sec |
| 80 | + N-Body Physics 413 517.1 Kpairs/sec |
| 81 | + Rigid Body Physics 836 5181.6 FPS |
| 82 | + Gaussian Blur 598 32.9 Mpixels/sec |
| 83 | + Face Detection 896 6.90 images/sec |
| 84 | + Horizon Detection 990 24.4 Mpixels/sec |
| 85 | + Image Inpainting 1159 56.8 Mpixels/sec |
| 86 | + HDR 1276 17.4 Mpixels/sec |
| 87 | + Ray Tracing 934 750.1 Kpixels/sec |
| 88 | + Structure from Motion 608 5.45 Kpixels/sec |
| 89 | + Speech Recognition 545 17.4 Words/sec |
| 90 | + Machine Learning 66 2.54 images/sec |
| 91 | + |
| 92 | +Multi-Core |
| 93 | + AES-XTS 1963 3.35 GB/sec |
| 94 | + Text Compression 1097 5.55 MB/sec |
| 95 | + Image Compression 1371 64.8 Mpixels/sec |
| 96 | + Navigation 1222 3.44 MTE/sec |
| 97 | + HTML5 1299 1.53 MElements/sec |
| 98 | + SQLite 1438 450.7 Krows/sec |
| 99 | + PDF Rendering 177 9.60 Mpixels/sec |
| 100 | + Text Rendering 1455 463.5 KB/sec |
| 101 | + Clang 1103 8.59 Klines/sec |
| 102 | + Camera 1340 15.5 images/sec |
| 103 | + N-Body Physics 723 904.0 Kpairs/sec |
| 104 | + Rigid Body Physics 1496 9268.8 FPS |
| 105 | + Gaussian Blur 1058 58.2 Mpixels/sec |
| 106 | + Face Detection 1623 12.5 images/sec |
| 107 | + Horizon Detection 1771 43.6 Mpixels/sec |
| 108 | + Image Inpainting 1852 90.9 Mpixels/sec |
| 109 | + HDR 2336 31.8 Mpixels/sec |
| 110 | + Ray Tracing 1721 1.38 Mpixels/sec |
| 111 | + Structure from Motion 1082 9.69 Kpixels/sec |
| 112 | + Speech Recognition 832 26.6 Words/sec |
| 113 | + Machine Learning 118 4.55 images/sec |
| 114 | + |
| 115 | +Benchmark Summary |
| 116 | + Single-Core Score 634 |
| 117 | + Crypto Score 1121 |
| 118 | + Integer Score 601 |
| 119 | + Floating Point Score 623 |
| 120 | + Multi-Core Score 1095 |
| 121 | + Crypto Score 1963 |
| 122 | + Integer Score 1030 |
| 123 | + Floating Point Score 1091 |
| 124 | + |
| 125 | +Upload results to the Geekbench Browser? [Y/n] |
| 126 | +``` |
| 127 | + |
| 128 | +## Credits |
| 129 | +- [iOS-run-macOS-executables-tools](https://github.com/zhuowei/iOS-run-macOS-executables-tools) for the idea and some implementation details. |
| 130 | +- [Dobby](https://github.com/jmpews/Dobby) for the idea of single instruction hook. |
0 commit comments