-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsign_files
executable file
·270 lines (206 loc) · 5.72 KB
/
sign_files
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
############################################################################
#
# Copyright (c) 2011 - dsixda (dislam@rocketmail.com)
# Copyright (c) 2014 - 越狱 (http://weibo.com/206021119)
#
# Android 厨房是100%免费。此脚本文件仅供个人或学习使用
# by hwh132 越狱 汉化
#
############################################################################
clear
base_path=`pwd`
util_dir=../tools/signapk_files
while :
do
clear
echo
echo "签名文件"
echo "----------"
echo
echo "注意: 此功能适用高级用户。如果只是对 ROM 进行简单定制,签名 APK "
echo " 应用程序并不是必须的。如果有未签名的 ZIP 刷机包文件,可以"
echo " 利用此功能签名。"
echo
echo
echo "请输入选择项:"
echo
echo " a = 签名 Working 文件夹中所有 APK 应用程序"
echo " s = 签名 Working 文件夹中一系列 APK 应用程序"
echo " z = 签名非 Working 文件夹中的 APK 应用程序和 ZIP 刷机包"
echo " x = 退出"
echo
echo -n "? "
read enterChoice
#
# All files
#
if [ "$enterChoice" == "a" ]
then
echo
cd $base_path
if [ ! -d WORKING_* ]
then
echo "未发现 Working 文件夹!"
scripts/press_enter
continue
fi
cd WORKING_*
grep_cmd=`find system/framework | grep \\.apk$ | sort -f`
grep_cmd="$grep_cmd `find system/app | grep \\.apk$ | sort -f`"
if [ -d data/app ]
then
echo
echo "注意: 如果签名了 /data/app 中的所有 *.apk 应用程序,则它们使用电子市场"
echo "更新将会失败。您可以选择现在先不签名,稍后单独签名需要的文件。"
echo
echo "所有 /system/app 和 /system/framework 下的 *.apk 应用程序仍将被签名。"
echo
echo -n "是否签名 /data/app 中的所有 *.apk 应用程序(y/n)? (默认为: n): "
read do_data
echo
if [ "$do_data" == "y" ]
then
grep_data=`find data/app | grep \\.apk$ | sort -f`
grep_cmd="$grep_data $grep_cmd"
else
echo "无法签名 data/app/*.apk"
fi
fi
for filename in $grep_cmd
do
new_file=$filename\_new
echo "签名 $filename ..."
java -jar $util_dir/signapk.jar $util_dir/testkey.x509.pem $util_dir/testkey.pk8 $filename $new_file
if [ -e $new_file ]
then
mv -f $new_file $filename
else
echo "错误: 无法签名"
fi
done
cd $base_path
echo
echo "完成"
scripts/press_enter
#
# Single file / Set of files
#
elif [ "$enterChoice" == "s" ]
then
echo
cd $base_path
if [ ! -d WORKING_* ]
then
echo "未发现 Working 文件夹!"
scripts/press_enter
continue
fi
cd WORKING_*
grep_cmd=`find . | grep .apk$ | sort -f`
count=0
rm -f ../temp.list
echo >> ../temp.list
echo "所有 APK 应用程序:" >> ../temp.list
echo >> ../temp.list
for filename in $grep_cmd
do
count=$(($count+1))
# Store file names in an array
file_array[$count]=$filename
file_to_sign[$count]=0
echo " ($count) $filename" >> ../temp.list
done
more ../temp.list
rm -f ../temp.list
echo
echo "请输入文件编号,或系列文件编号(0 = 取消)"
echo "例如: 1 24-39 22"
echo -n "> "
read enterNumbers
echo
if [ "$enterNumbers" == "0" ] || [ "$enterNumbers" == "" ]
then
continue
else
#
# 解析输入并设置排列
#
for num in $enterNumbers
do
num_start=$num
num_end=$num
num_start=`echo $num | sed 's/\([0-9]*\)-[0-9]*/\1/'`
num_end=`echo $num | sed 's/[0-9]*-\([0-9]*\)/\1/'`
if [ "$num_start" == "" ] || [ "`echo $num_start | sed 's/[0-9]*//'`" != "" ]
then
echo "错误: 无效输入('$num' 不是一个有效的数字或范围)"
continue
fi
if [ "$num_end" == "" ] || [ "`echo $num_end | sed 's/[0-9]*//'`" != "" ]
then
echo "错误: 无效输入('$num' 不是一个有效的数字或范围)"
continue
fi
if [ $num_end -lt $num_start ]
then
echo "错误: 无效输入($num_start 不能小于 $num_end)"
continue
fi
#
# 指定被选定的文件
#
for (( i=$num_start; i<=$num_end; i++ ))
do
if [ "${file_array[$i]}" == "" ]
then
echo "错误: 在 #$i 中没有任何文件"
continue
else
file_to_sign[$i]=1
fi
done
done
#
# 通过排列并签署相应的文件
#
for (( i=1; i<=$count; i++ ))
do
if [ "${file_to_sign[$i]}" == "1" ]
then
file_chosen=${file_array[$i]}
if [ "$file_chosen" == "" ]
then
echo "错误: 无效输入(在 $i 未发现文件)"
cd $base_path
scripts/press_enter
break
fi
new_file=$file_chosen\_new
echo "正在签名 #$i: $file_chosen ..."
java -jar $util_dir/signapk.jar $util_dir/testkey.x509.pem $util_dir/testkey.pk8 $file_chosen $new_file
if [ -e $new_file ]
then
mv -f $new_file $file_chosen
else
echo "错误: 无法签名"
cd $base_path
scripts/press_enter
fi
fi
done
cd $base_path
scripts/press_enter
fi
elif [ "$enterChoice" == "z" ]
then
cd $base_path
scripts/sign_files_in_folder
scripts/press_enter
elif [ "$enterChoice" == "x" ]
then
exit 0
else
echo "无效选项"
continue
fi
done