Skip to content

Commit

Permalink
env/corellium: update setup scripts
Browse files Browse the repository at this point in the history
Change-Id: Idb4febcab45131bd5461dbb4536646ae703d3866
Reviewed-on: https://go-review.googlesource.com/c/build/+/519095
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Changkun Ou <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
  • Loading branch information
changkun authored and gopherbot committed Aug 15, 2023
1 parent b87b3bc commit 2349f06
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
14 changes: 9 additions & 5 deletions env/corellium/android/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.


# install.sh sets up newly installed Android Corellium device.
# Connect to the device with "adb connect <ip>:5001" where
# <ip> is the device adb address.
# Setting up a Corellium Android device
#
# install.sh sets up newly installed Android Corellium device. Before
# executing install.sh, one must prepare the following steps:
#
# place a valid builder key in the `buildkey` file.
# 1. Connect to the device with "adb connect 10.11.1.1:5001" where
# 10.11.1.1 is the device adb address in Corellium.
# 2. Put a valid builder key as `buildkey` file in the same folder as
# `install.sh`.

curl -o com.termux.apk "https://f-droid.org/repo/com.termux_118.apk"
curl -o com.termux.boot.apk "https://f-droid.org/repo/com.termux.boot_7.apk"
Expand Down Expand Up @@ -48,6 +51,7 @@ termux mkdir -p /data/data/com.termux/files/home/tmpdir
# Run builder at boot.
termux mkdir -p /data/data/com.termux/files/home/.termux/boot
adb push files/run-builder-at-boot /data/data/com.termux/files/home/.termux/boot
termux pkg up
termux pkg install -y openssh tmux ndk-multilib clang git golang lld
termux go build clangwrap.go

Expand Down
62 changes: 40 additions & 22 deletions env/corellium/ios/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,69 @@
# license that can be found in the LICENSE file.


# install.sh sets up a newly created Corellium iPhone device.
# Set HOST to root@<ip> where <ip> is the device ssh
# address.
# Setting up a Corellium iPhone device
#
# Put a builder key in `buildkey`.
# install.sh sets up a newly created Corellium iPhone device. Before executing
# install.sh, one must prepare the following steps:
#
# Use `bootstrap.bash` from the Go standard distribution and build a
# ios/arm64 bootstrap toolchain with cgo enabled and the compiler set
# to the clang wrapper from $GOROOT/misc/ios:
# 1. A public key must be added to the device's /root/.ssh/authorized_keys file.
# 2. A builder key file `buildkey` in the same folder as `install.sh`.
# 3. Use `bootstrap.bash` from the Go standard distribution and build a
# ios/arm64 bootstrap toolchain with cgo enabled and the compiler set
# to the clang wrapper from $GOROOT/misc/ios:
#
# GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$(pwd)/../misc/ios/clangwrap.sh ./bootstrap.bash
# GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$(pwd)/../misc/ios/clangwrap.sh ./bootstrap.bash
#
# Put it in `go-ios-arm64-bootstrap.tbz`.
#
# Finally, install.sh assumes an iPhone SDK in `iPhoneOS.sdk`.
# 4. Put `go-ios-arm64-bootstrap.tbz` in the same folder as `install.sh`.
# 5. Finally, put an iPhone SDK in `iPhoneOS.sdk` in the same folder as `install.sh`.
# It can be found from Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk.

# Set HOST to [email protected] where 10.11.1.1 is the device ssh address in Corellium.
[email protected]

ios() {
ssh "$HOST" "$@"
}

# Install necessary toolchains.
ios apt-get update
ios apt-get upgrade
ios apt install -y --allow-unauthenticated git tmux rsync org.coolstar.iostoolchain ld64 com.linusyang.localeutf8

# Run builder at boot.
scp files/org.golang.builder.plist $HOST:/Library/LaunchDaemons/
ios launchctl load -w /Library/LaunchDaemons/org.golang.builder.plist
scp files/builder.sh $HOST:/var/root
# Codesign necessary binaries.
ios ldid -S /usr/bin/git
ios ldid -S /usr/bin/tmux
ios ldid -S /usr/bin/rsync

# Upload Go bootstrap toolchain and related files.
scp go-ios-arm64-bootstrap.tbz $HOST:/var/root
ios tar xjf go-ios-arm64-bootstrap.tbz
scp buildkey $HOST:/var/root/.gobuildkey-host-ios-arm64-corellium-ios
scp files/profile $HOST:/var/root/.profile
rsync -va iPhoneOS.sdk $HOST:/var/root/

# Dummy sign Go bootstrap toolchain.
ios find go-ios-arm64-bootstrap -executable -type f| ios xargs -n1 ldid -S

ios mkdir -p /var/root/bin

# Build wrappers on the host.
# Build wrappers on the host, and sign them.
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
CGO_ENABLED=1 GOOS=ios CC=$(go env GOROOT)/misc/ios/clangwrap.sh GOARCH=arm64 go build -o arwrap files/arwrap.go
ios mkdir -p /var/root/bin
scp arwrap $HOST:/var/root/bin/ar
scp clangwrap $HOST:/var/root/bin/clangwrap
# Dummy sign them.

# Codesign everything.
ios find go-ios-arm64-bootstrap -executable -type f | ios xargs -n1 ldid -S
ios ldid -S /var/root/bin/clangwrap
ios ldid -S /var/root/bin/ar

# Run builder at boot.
scp files/org.golang.builder.plist $HOST:/Library/LaunchDaemons/
ios launchctl load -w /Library/LaunchDaemons/org.golang.builder.plist
scp files/builder.sh $HOST:/var/root

# Install buildlet.
ios HOME=/var/root \
CC=$HOME/bin/clangwrap \
GO_BUILDER_ENV=host-ios-arm64-corellium-ios \
GOROOT_BOOTSTRAP=$HOME/go-ios-arm64-bootstrap \
PATH=$HOME/bin:$PATH $GOROOT_BOOTSTRAP/bin/go install -v golang.org/x/build/cmd/buildlet@latest

ios reboot

0 comments on commit 2349f06

Please sign in to comment.