-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathdecode_all.sh
executable file
·131 lines (114 loc) · 2.41 KB
/
decode_all.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
#####################################################
#
# use to decode all of the apk and jar in the system
# note: unzip the zip first
#
#####################################################
CUR_DIR=$(dirname $0)
APKTOOL=$CUR_DIR/apktool
THREAD_NUM=4
IN_DIR=""
OUT_DIR=""
# echo the usage of decode_all
function usage
{
echo "usage: decode_all [OPTIONS] SYSTEM_DIR [OUT_DIR]"
echo " OPTIONS: -j[0-9]* jobs number"
echo " SYSTEM_DIR: the apk/jar's directory which will be decoded"
echo " OUT_DIR: output directory for decoded, current directory is default."
echo "eg: decode_all system/framework ."
}
# setup the parameters
function setParam
{
if [ $# -eq 0 ]
then
usage
exit 1
fi
set -- `getopt "j:" "$@"`
while :
do
case "$1" in
-j) shift; THREAD_NUM=$1 ;;
--) break ;;
esac
shift
done
shift
IN_DIR=$1
if [ $# -eq 1 ]
then
OUT_DIR="."
else
OUT_DIR=$2
if [ ! -d $OUT_DIR ]
then
mkdir -p $OUT_DIR
fi
fi
}
# init multi build jobs through fifo
function initMultiJobs
{
tmp_fifofile="/tmp/$$.fifo"
mkfifo "$tmp_fifofile"
exec 6<>"$tmp_fifofile"
rm $tmp_fifofile
for ((i=0;i<$THREAD_NUM;i++));do
echo
done >&6
}
# decode all apks
function decodeApks
{
for line in `find $IN_DIR -name "*.apk"`
do
read -u6
{
echo ">>> begin decode $line"
out_file=${line:${#IN_DIR}:${#line}}
let "len=${#out_file}-4"
out_file=${out_file:0:$len}
$APKTOOL d $line -o $OUT_DIR"/"$out_file
echo "<<< decode $line done"
echo >&6
} &
done
}
# decode all jars
function decodeJars
{
for line in `find $IN_DIR -name "*.jar"`
do
read -u6
{
echo ">>> begin decode $line"
out_file=${line:${#IN_DIR}:${#line}}
let "len=${#out_file}"
#out_file=${line:${#file_path}:${#line}}
out_file=${out_file:0:$len}
$APKTOOL d $line -o $OUT_DIR"/"$out_file".out"
echo "<<< decode $line done"
echo >&6
} &
done
}
# wait for the end
function waitToEnd
{
# wait it for done
for ((i=0;i<$THREAD_NUM;i++));do
read -u6
done
}
function main
{
setParam $@
initMultiJobs
decodeApks
decodeJars
waitToEnd
}
main $@