2019-02-06 21:13:43 +00:00
|
|
|
#!/bin/bash
|
2015-06-02 01:54:15 +00:00
|
|
|
|
2017-11-03 18:53:11 +00:00
|
|
|
# You can modify these variables
|
2015-06-02 01:54:15 +00:00
|
|
|
PREFIX="/usr"
|
2017-11-03 18:53:11 +00:00
|
|
|
INSTALL_DST="/tmp/r2ios"
|
|
|
|
USE_SIMULATOR=0
|
2017-12-31 10:51:54 +00:00
|
|
|
#SIMULATOR_ARCHS="i386+x86_64"
|
|
|
|
SIMULATOR_ARCHS="x86_64"
|
2017-11-03 18:53:11 +00:00
|
|
|
PACKAGE_RADARE=0
|
2018-01-02 04:40:55 +00:00
|
|
|
EMBED_BITCODE=1
|
2019-01-30 04:10:07 +00:00
|
|
|
CFLAGS="-O2 -miphoneos-version-min=10.0"
|
2018-05-09 21:31:52 +00:00
|
|
|
DOSH=0
|
2017-11-03 18:53:11 +00:00
|
|
|
ARCHS="" # Will be set by -archs argument. If you want to set it -> e.g. ARCHS="armv7+arm64".
|
|
|
|
MERGE_LIBS=1 # Will merge libs if you build for arm and simulator
|
|
|
|
|
|
|
|
# Environment variables
|
|
|
|
export PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH
|
|
|
|
export PATH=`pwd`/sys:${PATH}
|
|
|
|
export CC=`pwd`/sys/ios-sdk-gcc
|
|
|
|
export IOSVER=9.0
|
|
|
|
export IOSINC=`pwd`/sys/ios-include
|
2018-05-09 21:31:52 +00:00
|
|
|
export USE_IOS_STATIC=0
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2019-02-06 21:13:43 +00:00
|
|
|
echo "If xcrun --sdk iphoneos cant find the profile use this line:"
|
|
|
|
echo " sudo xcode-select -switch /Applications/Xcode.app"
|
|
|
|
|
2018-05-28 15:14:49 +00:00
|
|
|
PLUGINS_CFG=plugins.ios-store.cfg
|
|
|
|
#PLUGINS_CFG=plugins.ios.cfg
|
|
|
|
|
2017-11-03 18:53:11 +00:00
|
|
|
if [ "${EMBED_BITCODE}" = 1 ]; then
|
|
|
|
export CFLAGS="$CFLAGS -fembed-bitcode"
|
2018-05-15 09:26:42 +00:00
|
|
|
export LDFLAGS="$LDFLAGS -fembed-bitcode"
|
2017-11-03 18:53:11 +00:00
|
|
|
fi
|
2017-10-09 08:53:41 +00:00
|
|
|
|
2017-10-08 23:56:44 +00:00
|
|
|
iosConfigure() {
|
2018-05-28 15:14:49 +00:00
|
|
|
cp -f ${PLUGINS_CFG} plugins.cfg
|
|
|
|
./configure --with-libr --prefix=${PREFIX} --with-ostype=darwin \
|
2018-10-21 12:56:56 +00:00
|
|
|
--disable-debugger --without-gpl \
|
2018-10-20 23:41:48 +00:00
|
|
|
--without-fork --without-libuv --with-compiler=ios-sdk \
|
2018-10-21 12:56:56 +00:00
|
|
|
--target=arm64-unknown-darwin
|
2017-10-08 23:56:44 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
iosClean() {
|
|
|
|
make clean
|
2019-02-06 21:13:43 +00:00
|
|
|
rm -rf libr/.libr libr/.libr2 libr/libr.a libr/libr.dylib shlr/libr_shlr.a
|
2019-02-11 14:59:23 +00:00
|
|
|
rm -rf shlr/capstone
|
2017-10-08 23:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iosBuild() {
|
2019-02-10 23:09:46 +00:00
|
|
|
time make -j4 AR="xcrun --sdk ${SDK} ar" || exit 1
|
2018-05-09 21:31:52 +00:00
|
|
|
# Build and sign
|
|
|
|
( cd binr/radare2 ; make ios_sdk_sign )
|
|
|
|
make install DESTDIR="$INSTALL_DST"
|
2020-12-16 13:35:03 +00:00
|
|
|
rm -rf "$INSTALL_DST/$PREFIX"/share/radare2/*/www/*/node_modules
|
2018-05-09 21:31:52 +00:00
|
|
|
return $?
|
2017-11-03 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iosMergeLibs() {
|
2018-05-09 21:31:52 +00:00
|
|
|
mkdir -p $INSTALL_DST/$PREFIX/lib_merged
|
|
|
|
#echo "Merging dynamic libs"
|
|
|
|
#lipo "$INSTALL_DST/$PREFIX"/lib/libr*git.dylib $INSTALL_DST/$PREFIX/lib_simulator/libr*git.dylib -output $INSTALL_DST/$PREFIX/lib_merged/libr2.dylib -create
|
2017-11-03 18:53:11 +00:00
|
|
|
echo "Merging static libs (only libr.a)"
|
2018-05-09 21:31:52 +00:00
|
|
|
lipo "$INSTALL_DST/$PREFIX"/lib/libr.a "$INSTALL_DST/$PREFIX"/lib_simulator/libr.a -output "$INSTALL_DST/$PREFIX"/lib_merged/libr.a -create
|
|
|
|
echo "Merging shared libs (only libr.dylib)"
|
|
|
|
lipo "$INSTALL_DST/$PREFIX/lib/libr.dylib" \
|
|
|
|
"$INSTALL_DST/$PREFIX"/lib_simulator/libr.dylib \
|
|
|
|
-output "$INSTALL_DST/$PREFIX"/lib_merged/libr.dylib -create
|
|
|
|
echo "You can find the merged libs in $INSTALL_DST$PREFIX/lib_merged"
|
2017-10-08 23:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iosPackage() {
|
2018-05-09 21:31:52 +00:00
|
|
|
( cd "$INSTALL_DST" && tar czvf $INSTALL_DST-${CPU}.tar.gz * )
|
2017-10-08 23:56:44 +00:00
|
|
|
# Prepare radare2
|
|
|
|
rm -rf sys/cydia/radare2/root
|
|
|
|
rm -rf sys/cydia/radare2/root/usr/lib/*.dSYM
|
|
|
|
rm -rf sys/cydia/radare2/root/usr/lib/*.a
|
|
|
|
mkdir -p sys/cydia/radare2/root
|
2018-05-09 21:31:52 +00:00
|
|
|
sudo tar xpzvf "$INSTALL_DST"-${CPU}.tar.gz -C sys/cydia/radare2/root
|
2017-10-08 23:56:44 +00:00
|
|
|
rm -rf sys/cydia/radare2-dev/root
|
|
|
|
# Prepare radare2-dev
|
|
|
|
mkdir -p sys/cydia/radare2-dev/root
|
|
|
|
mkdir -p sys/cydia/radare2-dev/root/usr/include
|
|
|
|
mv sys/cydia/radare2/root/usr/include/* sys/cydia/radare2-dev/root/usr/include
|
|
|
|
mkdir -p sys/cydia/radare2-dev/root/usr/lib
|
|
|
|
mv sys/cydia/radare2/root/usr/lib/lib* sys/cydia/radare2-dev/root/usr/lib
|
|
|
|
mv sys/cydia/radare2/root/usr/lib/pkgconfig sys/cydia/radare2-dev/root/usr/lib
|
|
|
|
(
|
|
|
|
cd sys/cydia/radare2/root/usr/bin ;
|
|
|
|
for a in * ; do strip $a ; done
|
|
|
|
)
|
|
|
|
( cd sys/cydia/radare2 ; sudo make clean ; sudo make )
|
|
|
|
( cd sys/cydia/radare2-dev ; sudo make clean ; sudo make )
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:53:11 +00:00
|
|
|
showHelp() {
|
|
|
|
echo "The following arguments are available:"
|
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " -a, --archs"
|
|
|
|
echo " Select the archs, you want to build for."
|
|
|
|
echo " Available archs: armv7, armv7s, arm64, all"
|
|
|
|
echo " You can select multiple archs by concatenating"
|
|
|
|
echo " them with a '+' sign."
|
|
|
|
echo " Or specify 'all' to build for armv7+armv7s+arm64."
|
|
|
|
echo " See the examples below."
|
|
|
|
|
|
|
|
echo " -h, --help"
|
|
|
|
echo " Show this text."
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " -p, --package"
|
|
|
|
echo " Package radare2."
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " -s, --shell"
|
|
|
|
echo " Run shell."
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " -f, --full"
|
|
|
|
echo " Same as -archs all -simulator."
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " -simulator"
|
|
|
|
echo " Build also for i386 and x86_64 archs."
|
|
|
|
echo " So you can use radare2 in the iOS simulator."
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo "Examples:"
|
|
|
|
echo " sys/ios-sdk.sh -archs arm64"
|
2018-06-06 15:28:55 +00:00
|
|
|
echo " sys/ios-sdk.sh -archs armv7s+arm64 -simulator"
|
2018-05-09 21:31:52 +00:00
|
|
|
echo " sys/ios-sdk.sh -archs all -simulator"
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
echo "You can also modify some variables in sys/ios-sdk.sh."
|
2017-11-03 18:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Show help text, if no archs are selected
|
|
|
|
if [ $# -eq 0 ] && [ "${#ARCHS}" = 0 ] && [ "${USE_SIMULATOR}" = 0 ]; then
|
|
|
|
echo "You need to specify the archs you want to build for."
|
2018-05-09 21:31:52 +00:00
|
|
|
echo "Use the -archs/-simulator argument or modify the ARCHS/USE_SIMULATOR variable in sys/ios-sdk.sh."
|
|
|
|
echo
|
2017-11-03 18:53:11 +00:00
|
|
|
showHelp
|
2017-10-08 23:56:44 +00:00
|
|
|
exit 0
|
2015-06-04 02:30:48 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-03 18:53:11 +00:00
|
|
|
while test $# -gt 0; do
|
2017-12-31 10:51:54 +00:00
|
|
|
case "$1" in
|
2018-10-21 12:56:56 +00:00
|
|
|
-full|--full|-f)
|
|
|
|
shift
|
|
|
|
ARCHS="armv7s+arm64"
|
|
|
|
USE_SIMULATOR=1
|
|
|
|
;;
|
|
|
|
-shell|--shell|-s)
|
|
|
|
DOSH=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-archs|-a|--archs)
|
|
|
|
shift
|
|
|
|
if test $# -gt 0; then
|
|
|
|
if [ "$1" == "all" ]; then
|
|
|
|
ARCHS="armv7+armv7s+arm64"
|
|
|
|
else
|
|
|
|
ARCHS=$1
|
2017-12-31 10:51:54 +00:00
|
|
|
fi
|
2018-10-21 12:56:56 +00:00
|
|
|
fi
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-p|--package)
|
|
|
|
iosPackage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-simulator)
|
|
|
|
USE_SIMULATOR=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*|-h|--help)
|
|
|
|
showHelp
|
|
|
|
exit 0
|
|
|
|
;;
|
2017-11-03 18:53:11 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
### BUILD PHASE
|
|
|
|
|
|
|
|
# Print which archs we are building for
|
|
|
|
echo "Will build for \\c"
|
|
|
|
if [ "${#ARCHS}" -gt 0 ]; then
|
|
|
|
echo "$ARCHS \\c"
|
|
|
|
[ "${USE_SIMULATOR}" = 1 ] && echo "and \\c"
|
|
|
|
fi
|
|
|
|
[ "${USE_SIMULATOR}" = 1 ] && echo "simulator($SIMULATOR_ARCHS)"
|
2018-05-09 21:31:52 +00:00
|
|
|
|
|
|
|
if [ "${DOSH}" = 1 ]; then
|
|
|
|
echo "Inside ios-sdk shell"
|
|
|
|
if [ "${USE_SIMULATOR}" = 1 ]; then
|
|
|
|
export CPU="$SIMULATOR_ARCHS"
|
|
|
|
export SDK=iphonesimulator
|
|
|
|
else
|
2018-06-06 15:28:55 +00:00
|
|
|
[ -z "$ARCHS" ] && ARCHS="armv7s+arm64"
|
2018-05-09 21:31:52 +00:00
|
|
|
export CPU="$ARCHS"
|
|
|
|
export SDK=iphoneos
|
|
|
|
fi
|
|
|
|
CPUS=""
|
|
|
|
CPU=`echo $CPU | sed -e 's,+, ,g'`
|
|
|
|
EXTRA=""
|
|
|
|
for a in `IFS=+ echo ${CPU}` ; do
|
|
|
|
CPUS="-arch $a ${CPUS}"
|
|
|
|
done
|
2018-06-09 23:07:46 +00:00
|
|
|
export CPUS="${CPUS}"
|
2019-02-10 23:09:46 +00:00
|
|
|
export LD="xcrun --sdk ${SDK} ld"
|
2018-05-15 22:11:04 +00:00
|
|
|
export ALFLAGS="${CPUS}"
|
2018-05-09 21:31:52 +00:00
|
|
|
export LDFLAGS="${LDFLAGS} ${CPUS}"
|
|
|
|
export PS1="[ios-sdk-$CPU]> "
|
|
|
|
${SHELL}
|
|
|
|
echo "Outside ios-sdk shell"
|
|
|
|
exit $?
|
|
|
|
fi
|
2017-12-31 10:51:54 +00:00
|
|
|
echo
|
2018-05-09 21:31:52 +00:00
|
|
|
sleep 1
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2018-05-09 21:31:52 +00:00
|
|
|
rm -rf "$INSTALL_DST"
|
2017-11-03 18:53:11 +00:00
|
|
|
|
2017-12-31 10:51:54 +00:00
|
|
|
# Build radare2 for i386 and x86_64
|
2017-11-03 18:53:11 +00:00
|
|
|
if [ "${USE_SIMULATOR}" = 1 ]; then
|
|
|
|
iosClean
|
2018-10-21 12:56:56 +00:00
|
|
|
if [ 1 = 0 ]; then
|
|
|
|
iosConfigure
|
|
|
|
if [ $? = 0 ]; then
|
|
|
|
export CPU="$SIMULATOR_ARCHS"
|
|
|
|
export SDK=iphonesimulator
|
|
|
|
echo "Building for simulator($SIMULATOR_ARCHS)"
|
|
|
|
sleep 1
|
|
|
|
iosBuild
|
2018-05-09 21:31:52 +00:00
|
|
|
fi
|
2018-10-21 12:56:56 +00:00
|
|
|
else
|
|
|
|
sys/ios-simulator.sh
|
|
|
|
fi
|
|
|
|
# backup lib folder of simulator
|
|
|
|
if [ "${#ARCHS}" -gt 0 ]; then
|
|
|
|
rm -rf "$INSTALL_DST/$PREFIX"/lib_simulator
|
|
|
|
mv "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
|
|
|
else
|
|
|
|
cp -r "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
2017-11-03 18:53:11 +00:00
|
|
|
fi
|
2015-06-02 01:54:15 +00:00
|
|
|
fi
|
2017-11-03 18:53:11 +00:00
|
|
|
|
|
|
|
# check if arm archs were selected and if so build radare2 for them
|
2019-02-06 21:13:43 +00:00
|
|
|
# XXX this is a bashism
|
2017-11-03 18:53:11 +00:00
|
|
|
if [ "${#ARCHS}" -gt 0 ]; then
|
|
|
|
iosClean
|
|
|
|
iosConfigure
|
2018-05-20 10:03:35 +00:00
|
|
|
if [ "$?" = 0 ]; then
|
2019-02-06 21:13:43 +00:00
|
|
|
export CPU="$ARCHS"
|
2017-11-03 18:53:11 +00:00
|
|
|
export SDK=iphoneos
|
2018-05-09 21:31:52 +00:00
|
|
|
echo "Building for $CPU"
|
2017-11-03 18:53:11 +00:00
|
|
|
sleep 1
|
|
|
|
iosBuild
|
|
|
|
if [ "${PACKAGE_RADARE}" = 1 ]; then
|
|
|
|
iosPackage
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Merge libs if built for simulator and arm archs
|
|
|
|
if [ "${MERGE_LIBS}" = 1 ]; then
|
|
|
|
if [ "${USE_SIMULATOR}" = 1 ] && [ "${#ARCHS}" -gt 0 ]; then
|
|
|
|
iosMergeLibs
|
|
|
|
fi
|
2017-12-31 10:51:54 +00:00
|
|
|
fi
|