-
Notifications
You must be signed in to change notification settings - Fork 11
/
install.sh
320 lines (286 loc) · 9.36 KB
/
install.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/bin/sh
ADBBINARY="./adb.linux"
OS=$(uname)
BASEDIR="$( dirname "$0" )"
cd "$BASEDIR"
chmod +x files/adb.linux
chmod +x files/adb.mac
chmod +x files/unzip.linux
echo ""
echo "=============================================="
echo "= ="
echo "= Easy Root Tool v12 ="
echo "= Supports various Xperia devices ="
echo "= created by zxz0O0 ="
echo "= ="
echo "= http://forum.xda-developers.com/ ="
echo "= showthread.php?p=53448680 ="
echo "= ="
echo "= Many thanks to: ="
echo "= - [NUT] ="
echo "= - geohot ="
echo "= - MohammadAG ="
echo "= - cubeundcube ="
echo "= - nhnt11 ="
echo "= - xsacha ="
echo "= ="
echo "=============================================="
echo ""
if [ "$OS" = "Linux" ]; then
ADBBINARY="./adb.linux"
fi
if [ "$OS" = "Darwin" ]; then
ADBBINARY="./adb.mac"
fi
adb version > /dev/null 2>&1 || { ADBBINARY="adb" && echo "Using local adb"; }
if [ "$ADBBINARY" != "adb" ]; then
echo "Using $ADBBINARY"
fi
echo ""
cd ./files
SONYRIC=1
unset ANDROID_SERIAL
if [ ! -f libexploit.so ];
then
if [ ! -f tr.apk ];
then
echo "============================================="
echo "tr.apk not found. Trying to download from"
echo "https://towelroot.com/tr.apk"
echo "============================================="
curl -\# -O https://towelroot.com/tr.apk
echo ""
fi
if [ ! -f tr.apk ];
then
echo "============================================="
echo "Error downloading tr.apk with curl"
echo "Please download towelroot from https://towelroot.com"
echo "and save it as tr.apk in folder files/"
echo ""
echo "If you still have problems, please disable"
echo "your Antivirus and try again"
echo "============================================="
echo "Press any key to continue"
read tmpvar
echo ""
if [ ! -f tr.apk ];
then
echo "Error: tr.apk not found. Aborting..."
echo "Press any key to quit"
read tmpvar
exit 1
fi
fi
fsize=`ls -l tr.apk | awk '{ print $5 }'`
if [ $fsize -lt 1000 ]; then
echo "============================================="
echo "Error: tr.apk seems not valid"
echo "Please try again"
echo ""
echo "Make sure your Antivirus is disabled"
echo "============================================="
rm tr.apk
read tmpvar
exit 1
fi
echo "============================================="
echo "Extracting libexploit.so"
echo "============================================="
if [ "$OS" = "Darwin" ]; then
unzip -j tr.apk lib/armeabi/libexploit.so > /dev/null
else
if [ "`whereis unzip`" = "unzip:" ]; then
./unzip.linux -j tr.apk lib/armeabi/libexploit.so > /dev/null
else
unzip -j tr.apk lib/armeabi/libexploit.so > /dev/null
fi
fi
if [ ! -f libexploit.so ]; then
echo "Error extracting libexploit.so from tr.apk"
echo "Press any key to quit"
read tmpvar
exit 1
fi
echo "OK!"
rm tr.apk
echo ""
fi
if [ "$OS" = "Linux" ]; then
echo "It looks like you are running Linux"
echo "Please make sure ia32-libs is installed if you get any errors"
echo ""
fi
${ADBBINARY} kill-server
${ADBBINARY} start-server
echo "============================================="
echo "Waiting for Device, connect USB cable now..."
echo ""
echo "Make sure that you authorize the connection"
echo "if you get any message on the phone"
echo "============================================="
${ADBBINARY} wait-for-device
echo "Device found!"
CDevices=`${ADBBINARY} devices | wc -l`
if [ $CDevices -gt 3 ]; then
echo "More than one device connected."
availDevices=""
CavailDevices=0
adb_devices=`${ADBBINARY} devices`
Cadb_devices=`echo "$adb_devices" | wc -l`
adb_devices=`echo "$adb_devices" | tail -$((Cadb_devices-1))`
for line in `${ADBBINARY} devices`; do
case "$line" in
"emulator"*)
;;
"List"|"of"|"devices"|"attached")
;;
"device")
;;
"")
;;
*)
CurDev=`echo "$line" | cut -f1 | cut -d' ' -f1`
CavailDevices=$((CavailDevices+1))
availDevices="$availDevices$CurDev"'\n'
;;
esac
done
if [ $CavailDevices -eq 1 ]; then
export ANDROID_SERIAL=`echo "$availDevices" | tr -d '\r\n'`
echo "Using device $ANDROID_SERIAL since other is emulator.."
else
DevChosen=
while ! "$DevChosen" -ne 0 > /dev/null 2>&1 && ! "$DevChosen" -eq 0 > /dev/null 2>&1; do
echo ""
echo "Please choose the connected device you would"
echo "like to root. You can check under:"
echo "Settings => About phone => Status => Serial number"
echo ""
echo "Available devices are:"
CDevices=0
echo "$availDevices" | while read -r line; do
CDevices=$((CDevices+1))
echo "$CDevices. $line"
done
echo "Please choose device [1 - $CDevices]:"
read DevChosen
done
export ANDROID_SERIAL=`echo "$availDevices" | head -$DevChosen | tail -1`
echo "Connecting to device $ANDROID_SERIAL"
fi
fi
echo ""
echo "============================================="
echo "Getting device variables"
echo "============================================="
product_name=`${ADBBINARY} shell "getprop ro.build.product"`
echo "Device model is $product_name"
firmware=`${ADBBINARY} shell "getprop ro.build.id"`
echo "Firmware is $firmware"
kernelver=`${ADBBINARY} shell "cat /proc/version"`
year=`echo $kernelver | sed 's/ /\n/g' | tail -n1`
if [ $year -gt 2014 ]; then
echo ""
echo "WARNING: The kernel of your device was built after May 2014."
echo "It's highly likely that rooting will fail because the exploit was patched"
echo "Try flashing an older kernel"
echo ""
echo "If you still want to try, press any key to continue"
read tmpvar
else
if [ $year -eq 2014 ]; then
split=`echo $kernelver | awk -F'PREEMPT ' '{print $2}'`
month=`date -d "$split" "+%m"`
if [ $month -gt 5 ]; then
echo ""
echo "WARNING: The kernel of your device was built after May 2014."
echo "It's highly likely that rooting will fail because the exploit was patched"
echo "Try flashing an older kernel"
echo ""
echo "If you still want to try, press any key to continue"
read tmpvar
fi
fi
fi
echo ""
echo "============================================="
echo "Sending files"
echo "============================================="
${ADBBINARY} push zxz.sh /data/local/tmp/zxz.sh
${ADBBINARY} push installmount.sh /data/local/tmp
${ADBBINARY} push writekmem /data/local/tmp
${ADBBINARY} push findricaddr /data/local/tmp
${ADBBINARY} push busybox /data/local/tmp
${ADBBINARY} shell "chmod 777 /data/local/tmp/zxz.sh"
${ADBBINARY} shell "chmod 777 /data/local/tmp/installmount.sh"
${ADBBINARY} shell "chmod 777 /data/local/tmp/writekmem"
${ADBBINARY} shell "chmod 777 /data/local/tmp/findricaddr"
${ADBBINARY} shell "chmod 777 /data/local/tmp/busybox"
echo ""
echo "Copying kernel module..."
${ADBBINARY} push "wp_mod.ko" /data/local/tmp
${ADBBINARY} push "kernelmodule_patch.sh" /data/local/tmp
${ADBBINARY} shell "chmod 777 /data/local/tmp/kernelmodule_patch.sh"
${ADBBINARY} push "modulecrcpatch" /data/local/tmp
${ADBBINARY} shell "chmod 777 /data/local/tmp/modulecrcpatch"
${ADBBINARY} shell "/data/local/tmp/kernelmodule_patch.sh"
echo ""
echo "============================================="
echo "Loading geohot's towelroot (modified by zxz0O0)"
echo "============================================="
${ADBBINARY} push towelzxperia_ert /data/local/tmp
${ADBBINARY} push libexploit.so /data/local/tmp
${ADBBINARY} shell "chmod 777 /data/local/tmp/towelzxperia_ert"
echo "============================================="
echo ""
echo "Waiting for towelroot to exploit..."
${ADBBINARY} shell "/data/local/tmp/towelzxperia_ert"
echo "done"
echo ""
echo "Checking if device is rooted..."
sleep 1
#${ADBBINARY} wait-for-device
isRooted=`${ADBBINARY} shell "su -c ls -l" | tr -d '\r\n'`
if [ "$isRooted" = "/system/bin/sh: su: not found" ] || [ "$isRooted" = "" ]; then
echo "Error: device not rooted"
exit 1
fi
echo ""
echo "Device rooted."
echo ""
echo "============================================="
echo "Checking for Sony RIC"
echo "============================================="
SONYRIC=`${ADBBINARY} shell "su -c /data/local/tmp/busybox grep 'sony_ric/enable' /init*.rc" | wc -l | tr -d '\r\n'`
if [ $SONYRIC -gt 0 ]; then
echo "Sony RIC Service found."
echo "Installing RIC kill script installmount.sh..."
sleep 1
${ADBBINARY} wait-for-device
${ADBBINARY} shell "su -c /data/local/tmp/installmount.sh"
else
echo "No Sony RIC Service found."
fi
echo ""
echo "Done. You can now unplug your device."
echo "Enjoy root!"
echo "============================================="
${ADBBINARY} shell "rm /data/local/tmp/zxz.sh"
${ADBBINARY} shell "rm /data/local/tmp/kernelmodule_patch.sh"
${ADBBINARY} shell "rm /data/local/tmp/findricaddr"
${ADBBINARY} shell "rm /data/local/tmp/installmount.sh"
${ADBBINARY} shell "rm /data/local/tmp/towelzxperia_ert"
${ADBBINARY} shell "rm /data/local/tmp/libzxploit.so"
${ADBBINARY} shell "rm /data/local/tmp/libexploit.so"
${ADBBINARY} kill-server
echo ""
echo "What to do next?"
echo "- Donate to the people involved"
echo "- Install SuperSU by Chainfire"
echo "- Install dualrecovery by [NUT]"
echo "- Backup TA partition"
echo ""
echo "Press any key to quit"
read tmpvar
exit 0