golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/corellium/ios/install.sh (about) 1 #!/bin/sh 2 # Copyright 2022 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 7 # Setting up a Corellium iPhone device 8 # 9 # install.sh sets up a newly created Corellium iPhone device. Before executing 10 # install.sh, one must prepare the following steps: 11 # 12 # 1. A public key must be added to the device's /root/.ssh/authorized_keys file. 13 # 2. A builder key file `buildkey` in the same folder as `install.sh`. 14 # 3. Use `bootstrap.bash` from the Go standard distribution and build a 15 # ios/arm64 bootstrap toolchain with cgo enabled and the compiler set 16 # to the clang wrapper from $GOROOT/misc/ios: 17 # 18 # GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$(pwd)/../misc/ios/clangwrap.sh ./bootstrap.bash 19 # 20 # 4. Put `go-ios-arm64-bootstrap.tbz` in the same folder as `install.sh`. 21 # 5. Finally, put an iPhone SDK in `iPhoneOS.sdk` in the same folder as `install.sh`. 22 # It can be found from Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk. 23 24 # Set HOST to root@10.11.1.1 where 10.11.1.1 is the device ssh address in Corellium. 25 HOST=root@10.11.1.1 26 27 ios() { 28 ssh "$HOST" "$@" 29 } 30 31 # Install necessary toolchains. 32 ios apt-get update 33 ios apt-get upgrade 34 ios apt install -y --allow-unauthenticated git tmux rsync org.coolstar.iostoolchain ld64 com.linusyang.localeutf8 35 36 # Codesign necessary binaries. 37 ios ldid -S /usr/bin/git 38 ios ldid -S /usr/bin/tmux 39 ios ldid -S /usr/bin/rsync 40 41 # Upload Go bootstrap toolchain and related files. 42 scp go-ios-arm64-bootstrap.tbz $HOST:/var/root 43 ios tar xjf go-ios-arm64-bootstrap.tbz 44 scp buildkey $HOST:/var/root/.gobuildkey-host-ios-arm64-corellium-ios 45 scp files/profile $HOST:/var/root/.profile 46 rsync -va iPhoneOS.sdk $HOST:/var/root/ 47 48 # Build wrappers on the host, and sign them. 49 CGO_ENABLED=1 GOOS=ios CC=$(go env GOROOT)/misc/ios/clangwrap.sh GOARCH=arm64 go build -o clangwrap -ldflags="-X main.sdkpath=/var/root/iPhoneOS.sdk" files/clangwrap.go 50 CGO_ENABLED=1 GOOS=ios CC=$(go env GOROOT)/misc/ios/clangwrap.sh GOARCH=arm64 go build -o arwrap files/arwrap.go 51 ios mkdir -p /var/root/bin 52 scp arwrap $HOST:/var/root/bin/ar 53 scp clangwrap $HOST:/var/root/bin/clangwrap 54 55 # Codesign everything. 56 ios find go-ios-arm64-bootstrap -executable -type f | ios xargs -n1 ldid -S 57 ios ldid -S /var/root/bin/clangwrap 58 ios ldid -S /var/root/bin/ar 59 60 # Run builder at boot. 61 scp files/org.golang.builder.plist $HOST:/Library/LaunchDaemons/ 62 ios launchctl load -w /Library/LaunchDaemons/org.golang.builder.plist 63 scp files/builder.sh $HOST:/var/root 64 65 # Install buildlet. 66 ios HOME=/var/root \ 67 CC=$HOME/bin/clangwrap \ 68 GO_BUILDER_ENV=host-ios-arm64-corellium-ios \ 69 GOROOT_BOOTSTRAP=$HOME/go-ios-arm64-bootstrap \ 70 PATH=$HOME/bin:$PATH $GOROOT_BOOTSTRAP/bin/go install -v golang.org/x/build/cmd/buildlet@latest 71 72 ios reboot