-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathOneClickInstall.sh
178 lines (148 loc) · 5.11 KB
/
OneClickInstall.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
#!/bin/sh
if [ $# -lt 2 ]
then
echo "Usage: ./OneClickInstall.sh ipaddress My.apk"
echo "Example: ./OneClickInstall.sh 192.168.1.100 Waze.apk"
exit 127
fi
uname=`uname`
echo "Disconnecting other adb devices\n"
adb disconnect
sleep 1
echo "Connecting to $1\n"
adb connect $1
sleep 1
echo "Checking for root..."
./check_root.sh $1
gotroot=`echo $?`
if [ $gotroot -gt 0 ]; then
echo "No root yet, addressing the situation"
echo "Attempting to push payloads to /data/local/tmp/rootme\n"
adb shell 'mkdir /data/local/tmp/rootme'
adb push factory_reset_mod.sh /data/local/tmp/rootme/
adb push dirtycow /data/local/tmp/rootme/
adb push nefarious.sh /data/local/tmp/rootme/
adb push su /data/local/tmp/rootme/
adb shell 'chmod 777 /data/local/tmp/rootme/*'
echo "Exploiting dirtycow to replace factory_reset.sh with our own\n"
adb shell '/data/local/tmp/rootme/dirtycow /system/etc/factory_reset.sh /data/local/tmp/rootme/factory_reset_mod.sh'
echo "Okay - should be all set, initiate factory reset and hope for the best!"
echo "Go to Home ->Settings->System->Factory Data Reset (scroll all the way down) and ititiate factory reset, press enter when unit has rebooted & reconnected to WiFi"
read root
echo "Okay - checking for successfull root\n"
adb disconnect
sleep 1
adb connect $1
sleep 1
./check_root.sh $1
gotroot=`echo $?`
if [ $gotroot -gt 0 ]; then
"Hmm, didn't get root. Aborting further operations."
exit 1
else
"Got root!!!"
fi
else
echo "Already rooted!"
fi
#If we're at this point of the script, we have root & ADB connection established
echo "Okay, getting signature of $2"
if [ "$uname" = "Darwin" ]; then
sig=`java -jar bin/GetAndroidSig.jar "$2" | grep "To char" | sed -E 's/^.{9}//'`
else
sig=`java -jar bin/GetAndroidSig.jar "$2" | grep "To char" | sed -r 's/^.{9}//'`
fi
echo "Signature: $sig"
echo "Getting package information"
if [ "$uname" = "Darwin" ]; then
package=`aapt dump permissions "$2" | head -1 | sed -E 's/^.{9}//'`
else
package=`aapt dump permissions "$2" | head -1 | sed -r 's/^.{9}//'`
fi
echo "Package name: $package"
echo "Retrieving current whitelist..."
`adb shell "su -c 'cp /data/system/whitelist.xml /data/local/tmp/'"`
`adb shell "su -c 'chown shell:shell /data/local/tmp/whitelist.xml'"`
`adb pull /data/local/tmp/whitelist.xml 2>/dev/null`
echo "Preparing replacement whitelist"
`cat whitelist.xml | grep -v "</applicationLists" | grep -v "</whiteList" > whitelist-new.xml`
echo " <application>
<property>
<name>$package</name>
<package>$package</package>
<versionCode>1-999999999</versionCode>
<keyStoreLists> " >> whitelist-new.xml
#Need to hanlde case of sig containing multiple lines - some APKS have more than one sig
for signature in $sig; do
echo " <keyStore>$signature</keyStore> " >> whitelist-new.xml
done
echo " </keyStoreLists>
</property>
<controlData>
<withAudio>without</withAudio>
<audioStreamType>null</audioStreamType>
<regulation>null</regulation>
<revert>no</revert>
</controlData>
</application>
</applicationLists>
</whiteList>" >> whitelist-new.xml
echo "Okay - all set to replace the whitelist. Below are the final steps:
1. Backup existing whitelist to /data/local/tmp/
2. Upload whitelist to head unit
3. Reboot head unit
4. Install APK normally
Please review the below items carefully - if anything doesn't look right, ABORT NOW!\n"
if [ $gotroot -eq 0 ]; then
echo "Root status: rooted"
else
echo "Root status: not rooted (bad!)"
fi
if [ ! -z "$sig" ]; then
echo "APK signature obtained"
else
echo "APK signature NOT obtained (bad!)"
fi
if [ ! -z "$package" ]; then
echo "Have package name: $package"
else
echo "Did not get package name (bad!)"
fi
wlcheck=`ls -al whitelist.xml | awk '{print $5}'`
if [ $wlcheck -gt 20000 ]; then
echo "Original whitelist.xml size seems okay"
else
echo "Original whitelist.xml size DOES NOT seem okay (bad!)"
fi
packagecheck=`grep $package whitelist-new.xml`
if [ ! -z "$packagecheck" ]; then
echo "Package name is present in new whitelist"
else
echo "Package name is NOT present in new whitelist (bad!)"
fi
echo "
Would you like to proceed? (y/n):"
read retval
if [ "$retval" != "y" ]; then
echo "Okay - aborting"
exit 1
fi
`adb shell "su -c 'mount -o remount,rw /system'"`
ts=`date '+%d-%m-%Y--%H-%M-%S'`
echo "Backing up whitelist to /data/local/tmp/whitelist-$ts.xml"
`adb shell "su -c 'cp /data/system/whitelist.xml /data/local/tmp/whitelist-$ts.xml'"`
echo "Uploading whitelist"
`adb push whitelist-new.xml /data/local/tmp/whitelist.xml`
`adb shell "su -c 'cp /data/local/tmp/whitelist.xml /data/system/'"`
`adb shell "su -c 'mount -o remount,ro /system'"`
echo "Rebooting head unit"
`adb shell "su -c 'reboot' 2>/dev/null" &`
echo "Press enter when head unit has rebooted and is connected to WiFi"
read dummy
echo "Issuing APK installation command - this may take a while depending on APK size"
`adb disconnect`
sleep 1
adb connect $1
sleep 1
adb install $2
echo "All done - hope you enjoy!"