-
Notifications
You must be signed in to change notification settings - Fork 0
/
deodex.sh
executable file
·131 lines (118 loc) · 2.57 KB
/
deodex.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
#!/bin/bash
TOOL_PATH=$(cd "$(dirname "$0")"; pwd)
SMALI=$TOOL_PATH/smali
BAKSMALI=$TOOL_PATH/baksmali
function deodex_one_file() {
if [ "$1" = '-a' ]
then
apilevel=$2
classpath=$3
file=$4
tofile=${file/odex/$5}
echo "processing $tofile"
$BAKSMALI -a $apilevel -c $classpath -d framework -I -x $file || exit -2
else
classpath=$1
file=$2
tofile=${file/odex/$3}
echo "processing $tofile"
$BAKSMALI -c $classpath -d framework -I -x $file || exit -2
fi
$SMALI out -o classes.dex || exit -2
jar uf $tofile classes.dex
rm classes.dex
rm -rf out
rm $file
zipalign 4 $tofile $tofile.aligned
mv $tofile.aligned $tofile
}
#usage
if [ $1 = '--help' ]
then
echo "usage: ./deodex.sh [-a APILevel] absolute_path_to_ota_zip_file"
echo " -a specify APILevel, default Level is 15"
exit 0
fi
if [ ! -x $BAKSMALI -o ! -x $SMALI ]
then
echo "Error: Can not find baksmali/smali"
exit -1
fi
if [ $1 = '-a' ]
then
apilevel=$2
stockzip=$3
else
stockzip=$1
fi
if [ -d $stockzip ]
then
tempdir=$stockzip
else
temppath=`echo $PWD`
tempdir=`mktemp -p $temppath -d tempdir.XXX`
echo "temp dir: $tempdir"
echo "unzip $stockzip to $tempdir"
unzip -q $stockzip -d $tempdir
fi
if [ -d $tempdir/system ]
then
cd $tempdir/system
elif [ -d $tempdir/SYSTEM ]
then
cd $tempdir/SYSTEM
else
echo "can't find system or SYSTEM dir in $tempdir"
exit -1
fi
ls framework/core.odex > /dev/null
if [ $? -eq 0 ]
then
if [ $1 = '-a' ]
then
deodex_one_file -a $apilevel "" framework/core.odex jar
else
deodex_one_file "" framework/core.odex jar
fi
fi
for f in framework/*.jar
do
classpath=$classpath:$f
done
echo "classpath=$classpath"
ls framework/*.odex > /dev/null
if [ $? -eq 0 ]
then
for file in framework/*.odex
do
if [ $1 = '-a' ]
then
deodex_one_file -a $apilevel $classpath $file jar
else
deodex_one_file $classpath $file jar
fi
done
fi
ls app/*.odex > /dev/null
if [ $? -eq 0 ]
then
for file in app/*.odex
do
if [ $1 = '-a' ]
then
deodex_one_file -a $apilevel $classpath $file apk
else
deodex_one_file $classpath $file apk
fi
done
fi
if [ ! -d $stockzip ]
cd $tempdir
echo "zip tmp_target_files"
zip -q -r -y "tmp_target_files" *
echo "replaces $stockzip"
mv "tmp_target_files.zip" ../$stockzip
echo "remove $tempdir"
rm -rf $tempdir
fi
echo "deodex done. deodex zip: $stockzip"