|
| 1 | +# AArch64 platform workflows |
| 2 | + |
| 3 | +This repository now implements AArch64 backends for: |
| 4 | + |
| 5 | +- macOS |
| 6 | +- iOS |
| 7 | +- Linux |
| 8 | +- Android |
| 9 | + |
| 10 | +The core trap/replay engine is shared across all of them. The platform-specific |
| 11 | +differences are mostly: |
| 12 | + |
| 13 | +- how executable pages are patched |
| 14 | +- how `sigaction` / `ucontext_t` machine state is remapped |
| 15 | +- how the sidecar payload is injected into the target process |
| 16 | + |
| 17 | +The example `hook.zig` payloads automatically pick the right constructor |
| 18 | +section: |
| 19 | + |
| 20 | +- Mach-O (`macOS`, `iOS`): `__DATA,__mod_init_func` |
| 21 | +- ELF (`Linux`, `Android`): `.init_array` |
| 22 | + |
| 23 | +## Linux AArch64 |
| 24 | + |
| 25 | +Recommended workflows: |
| 26 | + |
| 27 | +- `LD_PRELOAD` for local experiments |
| 28 | +- `patchelf` for persistent sidecar loading |
| 29 | + |
| 30 | +Build a sidecar payload from any example directory: |
| 31 | + |
| 32 | +```bash |
| 33 | +cc -O3 -DNDEBUG -Wl,-export-dynamic -o target target.c |
| 34 | + |
| 35 | +zig build-lib -dynamic -target aarch64-linux-musl -OReleaseFast -femit-bin=hook.so \ |
| 36 | + --dep zighook \ |
| 37 | + -Mroot=hook.zig \ |
| 38 | + -Mzighook=../../src/root.zig \ |
| 39 | + -lc |
| 40 | +``` |
| 41 | + |
| 42 | +Run with preload: |
| 43 | + |
| 44 | +```bash |
| 45 | +LD_PRELOAD=$PWD/hook.so ./target |
| 46 | +``` |
| 47 | + |
| 48 | +Or patch the ELF loader metadata with `patchelf` / equivalent tooling and ship |
| 49 | +the sidecar `.so` next to the target binary. |
| 50 | + |
| 51 | +## iOS AArch64 |
| 52 | + |
| 53 | +Recommended workflow: |
| 54 | + |
| 55 | +- use `prepatched.*` |
| 56 | +- patch `brk #0` into the app binary offline |
| 57 | +- ship a sidecar dylib inside `Frameworks/` |
| 58 | +- inject the load command with `insert-dylib` |
| 59 | +- re-sign the entire app bundle and install |
| 60 | + |
| 61 | +`prepatched_inline_hook` is the best template example for this deployment mode. |
| 62 | + |
| 63 | +Build the payload dylib: |
| 64 | + |
| 65 | +```bash |
| 66 | +IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path) |
| 67 | + |
| 68 | +zig build-lib -dynamic -target aarch64-ios -OReleaseFast -femit-bin=hook.dylib \ |
| 69 | + --dep zighook \ |
| 70 | + -Mroot=hook.zig \ |
| 71 | + -Mzighook=../../src/root.zig \ |
| 72 | + -L"$IOS_SDK/usr/lib" \ |
| 73 | + -lc |
| 74 | +``` |
| 75 | + |
| 76 | +Typical packaging flow afterwards: |
| 77 | + |
| 78 | +1. Copy `hook.dylib` into `MyApp.app/Frameworks/` |
| 79 | +2. Use `insert-dylib` to add a load command to the app Mach-O |
| 80 | +3. Re-sign the full app bundle |
| 81 | +4. Install and run |
| 82 | + |
| 83 | +This repository's iOS support is therefore oriented around **prepatched trap |
| 84 | +sites plus inserted dylibs**, matching the workflow described above. |
| 85 | + |
| 86 | +## Android AArch64 |
| 87 | + |
| 88 | +Recommended workflow: |
| 89 | + |
| 90 | +- use a sidecar `.so` |
| 91 | +- patch the target ELF / native binary with `patch-elf` or equivalent |
| 92 | +- let the app or native packaging flow provide the final shared-library link |
| 93 | + |
| 94 | +The Android backend shares the same Linux-family AArch64 signal/context code |
| 95 | +path. In local verification, the Android target successfully compiled to object |
| 96 | +files against an installed NDK sysroot. |
| 97 | + |
| 98 | +Example compile-to-object smoke commands: |
| 99 | + |
| 100 | +```bash |
| 101 | +ANDROID_NDK=$HOME/Library/Android/sdk/ndk/29.0.13113456 |
| 102 | +ANDROID_SYSROOT=$(find "$ANDROID_NDK/toolchains/llvm/prebuilt" -maxdepth 1 -mindepth 1 -type d | head -n 1)/sysroot |
| 103 | + |
| 104 | +zig build-obj -target aarch64-linux-android -OReleaseFast \ |
| 105 | + --sysroot "$ANDROID_SYSROOT" \ |
| 106 | + src/root.zig \ |
| 107 | + -lc |
| 108 | + |
| 109 | +zig build-obj -target aarch64-linux-android -OReleaseFast \ |
| 110 | + --dep zighook \ |
| 111 | + -Mroot=hook.zig \ |
| 112 | + -Mzighook=../../src/root.zig \ |
| 113 | + --sysroot "$ANDROID_SYSROOT" \ |
| 114 | + -lc |
| 115 | +``` |
| 116 | + |
| 117 | +On the machine used for this implementation, Zig 0.15.2 did not provide a |
| 118 | +fully self-contained Android libc link for the final shared library, so the |
| 119 | +expected final `.so` link should be driven by the NDK / app build system. |
| 120 | + |
| 121 | +## Verification status |
| 122 | + |
| 123 | +- macOS AArch64: native runtime tests and examples executed locally |
| 124 | +- Linux AArch64: core shared library and ELF payload cross-compiled locally |
| 125 | +- iOS AArch64: core dylib and Mach-O payload cross-compiled locally |
| 126 | +- Android AArch64: core library and payload compiled to object files against a |
| 127 | + local NDK sysroot |
0 commit comments