!/bin/sh

# This should be a C compiler from an android "standalone toolchain" as
# documented at <https://developer.android.com/ndk/guides/standalone_toolchain>.
# Statically linking against glibc doesn't work here because for multithreaded
# code, glibc tries to use set_robust_list, which immediately causes the program
# to be killed by seccomp.
#CC=$HOME/android-sdk/sa-tch/bin/clang
CC=/data3/aosp/prebuilts/clang/host/linux-x86/clang-4579689/bin/clang

# Prepare shellcode - this can use any aarch64 toolchain.
# NOTE: We are changing the page-relative alignment of the shellcode, so normal
# aarch64 RIP-relative addressing doesn't work.
aarch64-linux-gnu-as arm_shellcode.s -o arm_shellcode.o  # 将汇编文件 arm_shellcode.s 汇编成 .o 文件
aarch64-linux-gnu-ld arm_shellcode.o -o arm_shellcode # 将 .o 链接成可执行 elf 文件
aarch64-linux-gnu-objcopy --dump-section .text=arm_shellcode.bin arm_shellcode # 将可执行文件的代码段 .text 提取到文件 arm_shellcode.bin 
xxd -i arm_shellcode.bin > arm_shellcode.h # 将二进制文件放进一个c 语言分格的数组变量，后续在c代码里以数组操作它
rm arm_shellcode.o arm_shellcode arm_shellcode.bin
# need android-ndk-r18b to build
make
