forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios-sdk.sh
executable file
·255 lines (228 loc) · 6.58 KB
/
ios-sdk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/sh
# You can modify these variables
PREFIX="/usr"
INSTALL_DST="/tmp/r2ios"
USE_SIMULATOR=0
#SIMULATOR_ARCHS="i386+x86_64"
SIMULATOR_ARCHS="x86_64"
PACKAGE_RADARE=0
EMBED_BITCODE=1
CFLAGS="-O2"
DOSH=0
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 LD="xcrun --sdk iphoneos ld"
export IOSVER=9.0
export IOSINC=`pwd`/sys/ios-include
export USE_IOS_STORE=1
export USE_IOS_STATIC=0
if [ "${EMBED_BITCODE}" = 1 ]; then
export CFLAGS="$CFLAGS -fembed-bitcode"
export LDFLAGS="$LDFLAGS -fembed-bitcode"
fi
iosConfigure() {
if [ "${USE_IOS_STORE}" = 1 ]; then
cp -f plugins.ios-store.cfg plugins.cfg
else
cp -f plugins.ios.cfg plugins.cfg
fi
./configure --enable-merged --prefix=${PREFIX} --with-ostype=darwin \
--without-pic --with-nonpic --without-fork \
--with-compiler=ios-sdk --target=arm-unknown-darwin
return $?
}
iosClean() {
make clean
rm -rf libr/.libr libr/libr.a libr/libr.dylib
}
iosBuild() {
time make -j4 || exit 1
# Build and sign
( cd binr/radare2 ; make ios_sdk_sign )
make install DESTDIR="$INSTALL_DST"
rm -rf "$INSTALL_DST/$PREFIX"/share/radare2/*/www/enyo/node_modules
return $?
}
iosMergeLibs() {
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
echo "Merging static libs (only libr.a)"
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"
}
iosPackage() {
( cd "$INSTALL_DST" && tar czvf $INSTALL_DST-${CPU}.tar.gz * )
# 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
sudo tar xpzvf "$INSTALL_DST"-${CPU}.tar.gz -C sys/cydia/radare2/root
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 $?
}
showHelp() {
echo "The following arguments are available:"
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."
echo " -p, --package"
echo " Package radare2."
echo " -s, --shell"
echo " Run shell."
echo " -f, --full"
echo " Same as -archs all -simulator."
echo " -simulator"
echo " Build also for i386 and x86_64 archs."
echo " So you can use radare2 in the iOS simulator."
echo "Examples:"
echo " sys/ios-sdk.sh -archs arm64"
echo " sys/ios-sdk.sh -archs armv7+arm64 -simulator"
echo " sys/ios-sdk.sh -archs all -simulator"
echo "You can also modify some variables in sys/ios-sdk.sh."
}
# 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."
echo "Use the -archs/-simulator argument or modify the ARCHS/USE_SIMULATOR variable in sys/ios-sdk.sh."
echo
showHelp
exit 0
fi
while test $# -gt 0; do
case "$1" in
-full|--full|-f)
shift
ARCHS="armv7+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
fi
fi
shift
;;
-p|--package)
iosPackage
exit 0
;;
-simulator)
USE_SIMULATOR=1
shift
;;
*|-h|--help)
showHelp
exit 0
;;
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)"
if [ "${DOSH}" = 1 ]; then
echo "Inside ios-sdk shell"
if [ "${USE_SIMULATOR}" = 1 ]; then
export CPU="$SIMULATOR_ARCHS"
export SDK=iphonesimulator
else
[ -z "$ARCHS" ] && ARCHS="armv7+armv7s+arm64"
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
export LDFLAGS="${LDFLAGS} ${CPUS}"
export PS1="[ios-sdk-$CPU]> "
${SHELL}
echo "Outside ios-sdk shell"
exit $?
fi
echo
sleep 1
rm -rf "$INSTALL_DST"
# Build radare2 for i386 and x86_64
if [ "${USE_SIMULATOR}" = 1 ]; then
iosClean
iosConfigure
if [ $? = 0 ]; then
export CPU="$SIMULATOR_ARCHS"
export SDK=iphonesimulator
echo "Building for simulator($SIMULATOR_ARCHS)"
sleep 1
iosBuild
# 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
fi
fi
fi
# check if arm archs were selected and if so build radare2 for them
if [ "${#ARCHS}" -gt 0 ]; then
iosClean
iosConfigure
if [ "$?" = 0 ] && [ "${#ARCHS}" -gt 0 ]; then
export CPU=$ARCHS
export SDK=iphoneos
echo "Building for $CPU"
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
fi