forked from mateor/auto-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_patcher
executable file
·653 lines (588 loc) · 21.4 KB
/
auto_patcher
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
#!/bin/bash
# version: beta v1.9.8, patches 2012.09.04.
# PDroid created by svyat. Official PDroid thread is
# http://forum.xda-developers.com/showthread.php?t=1357056
# The Auto-Patcher created by pastime1971 and mateorod
# Thread and support for the Auto-Patcher can be found at
# http://forum.xda-developers.com/showthread.php?p=27589651#post27589651
# ChangeLog
# 2012.05.00. (v0.1)
# ...........
# 2012.05.12. (v0.2) allows user to specify a different version of patches
# 2012.05.13. (v0.3.0) force "patch -N", remove temp upon failure, generate log output
# 2012.05.13. (v0.3.1) revised the generation of updater-script (SGS2)
# 2012.05.15. added AOSP patches
# 2012.05.15. added crespo-aosp patches, added device-specific patching if patch exists
# 2012.05.15. remove restore.zip upon failure
# 2012.05.15. (v0.4.1) added CM7 (GB) patches
# 2012.05.18. (v0.4.2) added checking for tool commands
# 2012.05.21. (v0.4.3) apply device-specific patche only when it is specified
# 2012.05.26. added task title to log
# 2012.05.31. (v0.4.4) CM9 patches updated, crespo-aosp added
# 2012.06.04. (v0.4.5) added checking tools and rom, added aroma installer support, add patch outputs reroute
# 2012.06.15. CM9 patches updated
# 2012.06.16. (v0.4.6) AOKP patches updated, patch versions restructured
# 2012.06.17. (v0.5.0) patcher script reorganized, removed build.prop
# 2012.06.17. (v0.6.0) auto patcher script for pdroid and v6 patches
# 2012.06.19. (v0.6.1) add patches for CM7.2 Final
# 2012.06.20. (v0.6.2) updated CM 7.2 patches
# 2012.06.23. (v0.6.3) fix symlinks
# 2012.06.26. (v0.6.4) added 0618 patches for cm7 nightlies; removed 0619 cm7.2 final
# 2012.06.27. (v0.6.5) added new CM9 patches (20120626)
# 2012.06.27. (v0.6.6) added CM7 nightly patches (20120625) (finally!)
# 2012.07.02. (v0.7.0) Redid AOSP/AOKP; add Windows support (using Cygwin). Thanks kobik77!
# 2012.07.06. (v0.7.1) updated CM9 patches (20120706)
# 2012.07.08. (v0.7.2) updated AOKP (20120707) and CM9 (20120708) pdroid patches
# 2012.07.11. (v1.0.0) reworked script works on Linux, Mac OSX, and Windows (on Cygwin);
# added new ICS/JellyBean support for the new V6-Supercharger
# 2012.07.18. (v1.0.1) new CM7/CM9 Pdroid patches (20120718)
# 2012.07.23. (v1.0.2) updated CM9 patches (20120723)
# 2012.07.23. (v1.0.3) updated CM9 patches (20120724)
# 2012.08.06. (v1.5.0) updated smali/baksmali binaries to 1.33
# 2012.08.06. Added Pdroid/V6supercharger support for CM10 Jellybean!
# 2012.08.06. Improved PDroid stability and efficiency (Thanks CollegeDev)
# 2012.08.06. (v1.6.0) added aokp-jb patches for pdroid/v6supercharger, script update
# 2012.08.17. (v1.9.5) Added support for pdroid_addon, by CollegeDev.
# Added insecure boot.img mod
# Added support for aosp-jb (This needs testing, and may not be
# a wide patch due to large variation between AOSP roms.
# -Please report all experiences!
# Updated all v6supercharger patches w/new edits to ProcessList
# Major script overhaul in preparation for additional mods!
# 2012.08.20. (1.9.6) Conditional support for Official cm10 and aokp-jb builds
# 2012.08.23. (1.9.7) Final/confirmed pdroid support for Official CM10 and AOKP-JB
# 2012.09.04 (1.9.8) Bundled cygwin-compatible tools (original was corrupt).
# For Cygwin, replaced h2b function with simple bash math
# conversion (req'd for compat w/ Cygwin tools).
# 2012.08.26. (2.0.0) Added .apk patching
# Added 3G Dongle support for Nexus 7
# TabletUI support for Nexus 7 (maybe more)
# Google Voice support for Nexus 7
# mods are 3gdongle, tabletUI, voice, or nexus7suite (for all)
# Added provisional file copy menu to widen patching base
# SHELL PROGRAMMING NOTES:
# [ -s FILE ]
# [[ -n STRING ]] or [[ -z STRING ]]
echo " "
echo "The Auto-Patcher v1.9.8"
echo " "
# by pastime1971 and mateorod
# pass variables to children
set -a
# function for converting hex to binary- for testing
#function h2b { echo "obase=2; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; }
printtask () {
echo "" >> "$LOG"
echo $1 | tee -a "$LOG"
}
printusage () {
echo "smali auto patcher v1.9.8"
echo " pdroid 1.32 patches 2012.08.20."
echo " v6supercharger patches 2012.08.17."
echo ""
echo "usage: $0 ROM.ZIP MODS [ROMTYPE] [PATCHDATE]"
echo ""
echo "MODS can be pdroid,v6supercharger or pdroid or v6supercharger"
echo "optional [ROMTYPE] can be cm9, aokp, etc."
echo "optional [PATCHDATE] can be specified to use older patch versions."
echo "try \"$0 ROM.ZIP -h\" to see what is available"
echo ""
exit
}
printerror () {
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! error:" $1
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
debug
}
askconsent () {
echo ""
echo "These are the files for which patching failed:"
echo "---------------------------------------------"
echo ""
grep FAILED ${JAR}.log | sed -e "s/.*.\///"
echo ""
echo "---------------------------------------------"
echo ""
echo "We can try to add a premade copy of those files."
echo "This sometimes works."
echo ""
echo "But IT MAY NOT WORK!!!"
echo ""
echo ""
sleep 1
echo -n "Do you want to proceed ? (YES/no) "
read PROCEED
case $PROCEED in
[Yy] | [Yy][Ee][Ss])
echo ""
;;
*)
return 1; # error
;;
esac
echo -n "Are you sure ? (YES/no) "
read PROCEED
case $PROCEED in
[Yy] | [Yy][Ee][Ss])
return 0; # successful
;;
*)
return 1; # error
;;
esac
}
debug () {
echo "! please refer to $LOG for any debugging"
echo ""
echo "! patching failed."
echo "! it may be possible to patch $ROM using other patch version"
echo ""
[ -d $TEMP ] && \rm -rf $TEMP
printusage
}
#contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
parse () {
echo ${1%%_*}
}
getbuildprop () {
if [ -f system/build.prop ]; then
result=(`grep $1 system/build.prop | tr '=' ' '`)
echo ${result[1]}
else
echo ""
fi
}
proberom () {
VID=$(getbuildprop ro.build.version.release)
#if [ "${VID%%.*}" == "2" ]; then
if [ "${VID%.*}" == "2.3" ]; then
RID=cm7
echo "### Result of ROM check Gingerbread. Trying cm7 patches ###"
elif [ "${VID%.*}" == "4.0" ]; then
MID=$(getbuildprop ro.rommanager.developerid)
[[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
DID=$(getbuildprop ro.product.device)
[[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
case "$MID" in
cm9|cm|cyanogenmod*)
RID=cm9
echo "### Result of ROM check CM9 ###"
;;
aokp|teamkang)
RID=aokp
echo "### Result of ROM check ICS AOKP ###"
;;
aosp|AOSP) # AOSP probing does not work yet
RID=aosp
;;
*)
echo "!!! $MID is not supported yet, trying generic latest !!!"
RID=generic
;;
esac
elif [ "${VID%.*}" == "4.1" ]; then
MID=$(getbuildprop ro.build.display.id)
[[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
DID=$(getbuildprop ro.product.device)
[[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
case "$MID" in
cm10|cm*|cyanogenmod*)
RID=cm10
echo "### Result of ROM check cm10 ###"
;;
aokp*|teamkang)
RID=aokp-jb
echo "### Result of ROM check aokp-jb ###"
;;
# aosp|AOSP) # AOSP probing does not work yet
# RID=aosp
# ;;
*)
echo "!!! $MID may not be supported yet, trying aosp-jb latest !!!"
RID=aosp-jb
;;
esac
else
printerror "unknown ROM version $VID"
fi
}
abspath () {
case `uname -s` in
CYGWIN*)
echo $(cygpath -ua "$1")
;;
Darwin)
#[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
[[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
;;
Linux)
echo $(readlink -f "$1")
;;
*)
if [[ ${1:0:1} == "/" ]]; then
echo "$1"
elif [[ ${1:0:2} == "./" ]]; then
echo "$PWD/${1:2}"
else
echo "$PWD/$1"
fi
;;
esac
}
extpath () {
case `uname -s` in
CYGWIN*)
echo $(cygpath -da "$1")
;;
*)
echo $(abspath "$1")
;;
esac
}
[[ $# -lt 1 || $1 == "-h" || -z $1 ]] && printusage
ROOT=$(abspath "`dirname $0`")
TOOL="$ROOT/patch_tools.tgz"
PTCH="$ROOT/patch_patches.tgz"
ROM=$(abspath "$1")
ROMX=$(extpath "$1")
if [[ $OSTYPE == "cygwin" ]]; then
EXE=".exe"
PGFORM="0x"
fi
#DATE=`date +%s`
DATE=`date +%Y%m%d%H%M%S`
TEMP=tmp$DATE
LOG=$(abspath log$DATE)
#echo $ROOT $TOOL $ROM $TEMP "$LOG"
echo "ROOT= $ROOT" >> "$LOG"
echo "TOOL= $TOOL" >> "$LOG"
echo "ROM= $ROM" >> "$LOG"
echo "ROMX= $ROMX" >> "$LOG"
\rm -f restore.zip update.zip
#CHK=$(getconf LONG_BIT)
#if [[ $CHK = "64" ]]; then
# BIT=64
#else [[ $BIT = "32" ]];
# BIT=32
#fi
#echo "*** You are using a $BIT bit OS ***" >> "$LOG"
#echo "### You are using $BIT bit OS ###"
printtask "### verify tools ###"
which patch >> "$LOG" || printerror "Missing \"patch diff tools\""
which tar >> "$LOG" || printerror "Missing \"tar zip tools\""
which jar >> "$LOG" || printerror "Missing \"jar (JDK)\""
which java >> "$LOG" || printerror "Missing \"java (JRE)\""
which cpio >> "$LOG" || printerror "Missing \"cpio (JRE)\""
[ -f "$TOOL" ] || printerror "patch tool is missing"
[ -f "$PTCH" ] || printerror "patch patches are missing"
printtask "### verify ROM ###"
[ -f "$ROM" ] || printerror "Cannot find $ROM"
echo "# running" $0 $@ >> "$LOG"
mkdir $TEMP
cd $TEMP
TEMP=`pwd`
printtask "### unzip patch tools ###"
tar xvzf "$TOOL" >> "$LOG" 2>> "$LOG" || printerror "failed extracting tools !!!"
printtask "### unzip patch patches ###"
tar xvzf "$PTCH" > /dev/null || printerror "failed extracting patches !!!"
# build date
if [ $# -gt 3 ]; then
BID=$4
else
BID=latest
fi
# rom type
if [ $# -gt 2 ]; then
RID=$3
else
printtask "### probe rom type ###"
jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || printerror "failed extracting build.prop from $ROMX !!!"
proberom
fi
# patch type
if [ $# -gt 1 ]; then
PID=${2//,/ }
else
#PID=`ls patches/`
PID="pdroid v6supercharger"
fi
echo "# VID=" $VID >> "$LOG"
echo "# MID=" $MID >> "$LOG"
echo "# RID=" $RID >> "$LOG"
echo "# DID=" $DID >> "$LOG"
echo "# BID=" $BID >> "$LOG"
echo "# PID=" ${PID[@]} >> "$LOG"
#[[ -f $PID$DID/*.patch ]] && PID=$PID$DID # untested yet
if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
echo "### supported patch candidates ###"
[ "$PID" != "-h" ] && PL=${PID[@]} || PL=`ls patches/`
for P in ${PL[@]}; do
[ "$PID" != "-h" -a "$RID" != "-h" ] && RL=${RID[@]} || RL=`ls patches/$P/`
for R in ${RL[@]} ; do
[ $R == "common" -o ! -d patches/$P/$R ] && continue
echo -n "$P : $R : "
\ls --ignore="*.sh" --ignore="*.txt" -r patches/$P/$R/
done
done
else
for P in ${PID[@]}; do
[ -d patches/$P/$RID ] && R=$RID || R=generic
[ -d patches/$P/$R/$BID ] && B=$BID || B=latest
PRB=patches/$P/$R/$B
JARS=
[ -f patches/$P/files.txt ] && JARS=`grep .jar patches/$P/files.txt`
[ -f patches/$P/$R/files.txt ] && JARS=`grep .jar patches/$P/$R/files.txt`
for FILE in ${JARS[@]}; do
[[ ${JID[@]} =~ "\t$FILE" ]] || JID=(${JID[@]} $FILE)
done
APKS=
[ -f patches/$P/files.txt ] && APKS=`grep .apk patches/$P/files.txt`
[ -f patches/$P/$R/files.txt ] && APKS=`grep .apk patches/$P/$R/files.txt`
for FILE in ${APKS[@]}; do
[[ ${AID[@]} =~ "\t$FILE" ]] || AID=(${AID[@]} $FILE)
done
COPY=
[ -f patches/$P/copies.txt ] && COPY=`cat patches/$P/copies.txt`
[ -f patches/$P/$R/copies.txt ] && COPY=`cat patches/$P/$R/copies.txt`
for FILE in ${COPY[@]}; do
if [[ ${CID[@]} =~ "\t$FILE" ]]; then
printerror "$FILE is already being copied"
else
echo "... add $FILE to copy list ..."
CID=(${CID[@]} $FILE)
fi
done
[ -s patches/$P/boot_patch.txt ] && BOOTIMG="boot.img"
[ -s patches/$P/$R/boot_patch.txt ] && BOOTIMG="boot.img"
done
echo "### JAR FILES=" ${JID[@]} >> "$LOG"
echo "### APK FILES=" ${AID[@]} >> "$LOG"
echo "### COPY FILES=" ${CID[@]} >> "$LOG"
echo "### BOOTIMG=" $BOOTIMG >> "$LOG"
printtask "### unzip rom ###"
jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${BOOTIMG} 2>> "$LOG" || printerror "failed extracting ${JID[@]} ${AID[@]} $BOOTIMG from $ROMX !!!"
#\cp -a system/ backup # only for debugging purpose
printtask "### create updater script ###"
jar -xvf "$ROMX" META-INF/com/google/android/updater-script META-INF/com/google/android/update-binary
jar -xvf "$ROMX" META-INF/com/google/android/update-binary-installer 1> /dev/null 2> /dev/null
if [ -f META-INF/com/google/android/update-binary-installer ]; then
printtask "... using Aroma installer ..."
\mv META-INF/com/google/android/update-binary-installer META-INF/com/google/android/update-binary
else
printtask "... using Clockworkmod installer ..."
fi
if [ -f META-INF/com/google/android/update-binary ]; then
#echo "# original updater-script" >> "$LOG"
#cat META-INF/com/google/android/updater-script >> "$LOG"
cat META-INF/com/google/android/updater-script | grep ^mount | grep "/system" | head -n 1 > updater-script
[ -s updater-script ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
for FILE in ${CID[@]}; do
# replace with the original or delete it
jar -xvf "$ROMX" $FILE
[ -e $FILE ] || echo "delete(\"/$FILE\");" >> updater-script
done
echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
# add permission management
if [ -s patches/$P/set_perm.txt ]; then
echo "...adding permissions..."
cat patches/$P/set_perm.txt >> updater-script
fi
cat META-INF/com/google/android/updater-script | grep ^unmount | grep "/system" | head -n 1 >> updater-script
[[ -n $BOOTIMG ]] && cat META-INF/com/google/android/updater-script | grep "boot.img" >> updater-script
cat updater-script > META-INF/com/google/android/updater-script
echo "# generated updater-script" >> "$LOG"
cat updater-script >> "$LOG"
else
jar -xvf update-template.zip META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script
fi
printtask "### create restore.zip ###"
# extract system files
jar -cfv tmp.zip ${JID[@]} ${AID[@]} ${CID[@]} ${BOOTIMG} META-INF >> "$LOG" 2>> "$LOG"
#\rm -f system/build.prop # user may have modified it
java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip
\mv signed.zip restore.zip
\rm -f tmp.zip
printtask "### decompile system files ###"
# decompile system files
for FILE in ${JID[@]}; do
JAR=${FILE##*/}
printtask "... decompile $JAR ..."
java -jar baksmali.jar -b -a 15 -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
if [ $FILE == "system/framework/framework.jar" ]; then
printtask "... extract preloaded-classes ..."
jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
fi
done
for FILE in ${AID[@]}; do
APK=${FILE##*/}
printtask "... decompile $APK ..."
if [ $FILE == "system/framework/framework-res.apk" ]; then
printtask "... installing framework files ..."
java -jar apktool.jar if $FILE
fi
java -jar apktool.jar d -f $FILE tmp/$FILE.out
done
if [[ -n $BOOTIMG ]]; then
printtask "### unpacking boot.img ###"
cd boot
./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
cd ramdisk
gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
cd ../../
fi
# Create combo patches
if [ -s patches/$P/$R/create_patch.sh ]; then
. patches/$P/$R/create_patch.sh
elif [ -s patches/$P/create_patch.sh ]; then
. patches/$P/create_patch.sh
fi
# apply system modification
for P in ${PID[@]}; do
[ -d patches/$P/$RID ] && R=$RID || R=generic
[ -d patches/$P/$R/$BID ] && B=$BID || B=latest
PRB=patches/$P/$R/$B
printtask "### copy patch $P/$R/$B ###"
COPY=
[ -f patches/$P/copies.txt ] && COPY=`cat patches/$P/copies.txt`
[ -f patches/$P/$R/copies.txt ] && COPY=`cat patches/$P/$R/copies.txt`
for FILE in ${COPY[@]}; do
printtask "... copying $FILE ..."
DEST=${FILE%/*}
mkdir -p $DEST
if [ -e patches/$P/common/$FILE ]; then
[ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
\cp -a patches/$P/common/$FILE $DEST
fi
done
printtask "### jar patch $P/$R/$B ###"
JARS=
[ -f patches/$P/files.txt ] && JARS=`grep .jar patches/$P/files.txt`
[ -f patches/$P/$R/files.txt ] && JARS=`grep .jar patches/$P/$R/files.txt`
for FILE in ${JARS[@]}; do
JAR=${FILE##*/}
NAME=${JAR%.jar}
printtask "... apply $NAME.patch ..."
case "$NAME" in
framework)
patch -Nls -p1 -d tmp/${FILE}.out < $PRB/${NAME}.patch 2>&1 > ${JAR}.log
cat ${JAR}.log | tee -a "$LOG"
# patch preloaded-classes only if a patch exists
if [ -f $PRB/preloaded.patch ]; then
printtask "... apply preloaded.patch ..."
patch -Nls -p1 < $PRB/preloaded.patch 2>&1 > preloaded.log
cat preloaded.log | tee -a "$LOG"
[[ `grep FAILED preloaded.log` != "" ]] && printerror "failed preloaded.patch"
fi
;;
*)
patch -Nls -p1 -d tmp/${FILE}.out < $PRB/${NAME}.patch 2>&1 > ${JAR}.log
cat ${JAR}.log | tee -a "$LOG"
;;
esac
# substitute failed smali with premade jar
FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
if [[ -n ${FAILS[@]} ]]; then
printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
askconsent || printerror "failed $NAME.patch"
echo "### replacing ${FAILS[@]} from patches/$P/common/${FILE} ###" > ${JAR}.log
#java -jar baksmali.jar -b -a 15 -o tmp/${FILE}.out/smali patches/$P/common/provisionals/${FAIL} >> "$LOG" 2>> "$LOG" || echo "FAILED to baksmali $FILE" >> ${JAR}.log
for FAIL in ${FAILS[@]}; do
[[ ${SID[@]} =~ "\t$FAIL" ]] && printerror "$FAIL was already replaced before"
printtask "... replace $FAIL ..."
\rm -rf tmp/${FILE}.out/smali/${FAIL}
\cp -a patches/$PID/common/provisionals/$FILE.out/${FAIL} tmp/${FILE}.out/smali/${FAIL} || echo "FAILED to cp $FAIL" >> ${JAR}.log
SID=(${SID[@]} $FAIL)
done
fi
[[ `grep FAILED ${JAR}.log` != "" ]] && printerror "failed $NAME.patch"
GARBAGE=`find tmp/${FILE}.out -name "*.orig"` && rm -rf $GARBAGE && echo "GARBAGE=" $GARBAGE >> "$LOG"
GARBAGE=`find tmp/${FILE}.out -name "*.rej"` && rm -rf $GARBAGE && echo "GARBAGE=" $GARBAGE >> "$LOG"
done
printtask "### apk patch $P/$R/$B ###"
APKS=
[ -f patches/$P/files.txt ] && APKS=`grep .apk patches/$P/files.txt`
[ -f patches/$P/$R/files.txt ] && APKS=`grep .apk patches/$P/$R/files.txt`
for FILE in ${APKS[@]}; do
APK=${FILE##*/}
NAME=${APK%.apk}
printtask "... apply $NAME.patch ..."
patch -Nls -p2 -d tmp/${FILE}.out < $PRB/${NAME}.patch 2>&1 >> ${APK}.log
cat ${APK}.log | tee -a "$LOG"
[[ `grep FAILED ${APK}.log` != "" ]] && printerror "failed $NAME.patch"
GARBAGE=`find tmp/${FILE}.out -name "*.orig"` && rm -rf $GARBAGE && echo "GARBAGE=" $GARBAGE >> "$LOG"
GARBAGE=`find tmp/${FILE}.out -name "*.rej"` && rm -rf $GARBAGE && echo "GARBAGE=" $GARBAGE >> "$LOG"
done
if [[ -n $BOOTIMG ]]; then
printtask "### applying boot.img patch ###"
RDFS=
[ -f patches/$P/boot_patch.txt ] && RDFS=$(cat patches/$P/boot_patch.txt)
[ -f patches/$P/$R/boot_patch.txt ] && RDFS=$(cat patches/$P/$R/boot_patch.txt)
echo "RDFS=" ${RDFS[@]} >> "$LOG"
for FILE in ${RDFS[@]}; do
echo "... applying $FILE patch ..."
patch -Nls -p1 -d boot/ramdisk < $PRB/$FILE.patch || printerror "failed patching $FILE"
done
# Special Instructions- married to boot.img patching by necessity, not design. When
# added to it's own section, it only runs for one mod. WIP.
if [ -f patches/$P/$R/special_instructions.sh ]; then
. patches/$P/$R/special_instructions.sh
elif [ -f patches/$P/special_instruction.sh ]; then
. patches/$P/special_instructions.sh
fi
fi
done
printtask "### rebuild jar ###"
for FILE in ${JID[@]}; do
JAR=${FILE##*/}
printtask "... rebuild $JAR ..."
java -Xmx512M -jar smali.jar -a 15 tmp/${FILE}.out/smali -o classes.dex >> "$LOG" 2>> "$LOG"
[ -f classes.dex ] || printerror "failed compiling $JAR !!!"
jar -ufv ${FILE} classes.dex >> "$LOG" 2>> "$LOG"
\rm -f classes.dex
if [ $FILE == "system/framework/framework.jar" ]; then
jar -ufv ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
fi
done
printtask "### rebuild apk ###"
for FILE in ${AID[@]}; do
APK=${FILE##*/}
printtask "... rebuild $APK ..."
java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || printerror "failed compiling $FILE !!!"
cd tmp/${FILE}.out/build/apk
jar -ufv ${TEMP}/${FILE} * >> /dev/null
cd ${TEMP}
#\rm -r tmp/${FILE}.out
done
if [[ -n $BOOTIMG ]]; then
printtask "### rebuild boot.img ###"
# Rebuilding boot.img
cd boot
printtask "... rebuilding ramdisk ..."
./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
printtask "... composing boot.img ..."
BASE=$(cat boot.img-base)
# convert hex to decimal in cygwin by prefixing "0x" and C-style arithmetic
PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
CMDLINE=$(cat boot.img-cmdline)
echo "cmdline = no_console_suspend=1 console=null" $CMDLINE >> "$LOG"
echo "pagesize =" $PGSIZE >> "$LOG"
echo "base =" $BASE >> "$LOG"
printtask "... rebuilding boot.img ..."
./mkbootimg$EXE --kernel boot.img-zImage --ramdisk ramdisk-new.gz --cmdline "no_console_suspend=1 console=null $CMDLINE" --base "$BASE" --pagesize "$PGSIZE" -o ../boot.img || printerror "failed building boot.img"
cd ..
fi
printtask "### create update.zip ###"
jar -cfv tmp.zip ${BOOTIMG} ${JID[@]} ${AID[@]} ${CID[@]} META-INF >> "$LOG" 2>> "$LOG"
java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip
\mv signed.zip update.zip
\rm -f tmp.zip
#echo "# miscellaneous log" >> "$LOG"
\mv restore.zip update.zip ..
echo "### finished ###"
echo "flash update.zip to install the modified"
echo "flash restore.zip to restore the original"
fi
cd ..
\rm -rf $TEMP