3 # version: beta v2.1.9, patches 2012.010.16.
5 # PDroid created by svyat. Official PDroid thread is
6 # http://forum.xda-developers.com/showthread.php?t=1357056
8 # The Auto-Patcher created by pastime1971 and mateorod
9 # Thread and support for the Auto-Patcher can be found at
10 # http://forum.xda-developers.com/showthread.php?p=27589651#post27589651
15 # 2012.05.12. (v0.2) allows user to specify a different version of patches
16 # 2012.05.13. (v0.3.0) force "patch -N", remove temp upon failure, generate log output
17 # 2012.05.13. (v0.3.1) revised the generation of updater-script (SGS2)
18 # 2012.05.15. added AOSP patches
19 # 2012.05.15. added crespo-aosp patches, added device-specific patching if patch exists
20 # 2012.05.15. remove restore.zip upon failure
21 # 2012.05.15. (v0.4.1) added CM7 (GB) patches
22 # 2012.05.18. (v0.4.2) added checking for tool commands
23 # 2012.05.21. (v0.4.3) apply device-specific patche only when it is specified
24 # 2012.05.26. added task title to log
25 # 2012.05.31. (v0.4.4) CM9 patches updated, crespo-aosp added
26 # 2012.06.04. (v0.4.5) added checking tools and rom, added aroma installer support, add patch outputs reroute
27 # 2012.06.15. CM9 patches updated
28 # 2012.06.16. (v0.4.6) AOKP patches updated, patch versions restructured
29 # 2012.06.17. (v0.5.0) patcher script reorganized, removed build.prop
30 # 2012.06.17. (v0.6.0) auto patcher script for pdroid and v6 patches
31 # 2012.06.19. (v0.6.1) add patches for CM7.2 Final
32 # 2012.06.20. (v0.6.2) updated CM 7.2 patches
33 # 2012.06.23. (v0.6.3) fix symlinks
34 # 2012.06.26. (v0.6.4) added 0618 patches for cm7 nightlies; removed 0619 cm7.2 final
35 # 2012.06.27. (v0.6.5) added new CM9 patches (20120626)
36 # 2012.06.27. (v0.6.6) added CM7 nightly patches (20120625) (finally!)
37 # 2012.07.02. (v0.7.0) Redid AOSP/AOKP; add Windows support (using Cygwin). Thanks kobik77!
38 # 2012.07.06. (v0.7.1) updated CM9 patches (20120706)
39 # 2012.07.08. (v0.7.2) updated AOKP (20120707) and CM9 (20120708) pdroid patches
40 # 2012.07.11. (v1.0.0) reworked script works on Linux, Mac OSX, and Windows (on Cygwin);
41 # added new ICS/JellyBean support for the new V6-Supercharger
42 # 2012.07.18. (v1.0.1) new CM7/CM9 Pdroid patches (20120718)
43 # 2012.07.23. (v1.0.2) updated CM9 patches (20120723)
44 # 2012.07.23. (v1.0.3) updated CM9 patches (20120724)
45 # 2012.08.06. (v1.5.0) updated smali/baksmali binaries to 1.33
46 # 2012.08.06. Added Pdroid/V6supercharger support for CM10 Jellybean!
47 # 2012.08.06. Improved PDroid stability and efficiency (Thanks CollegeDev)
48 # 2012.08.06. (v1.6.0) added aokp-jb patches for pdroid/v6supercharger, script update
49 # 2012.08.17. (v1.9.5) Added support for pdroid_addon, by CollegeDev.
50 # Added insecure boot.img mod
51 # Added support for aosp-jb (This needs testing, and may not be
52 # a wide patch due to large variation between AOSP roms.
53 # -Please report all experiences!
54 # Updated all v6supercharger patches w/new edits to ProcessList
55 # Major script overhaul in preparation for additional mods!
56 # 2012.08.20. (1.9.6) Conditional support for Official cm10 and aokp-jb builds
57 # 2012.08.23. (1.9.7) Final/confirmed pdroid support for Official CM10 and AOKP-JB
58 # 2012.09.04 (1.9.8) Bundled cygwin-compatible tools (original was corrupt).
59 # For Cygwin, replaced h2b function with simple bash math
60 # conversion (req'd for compat w/ Cygwin tools).
61 # 2012.08.26. (2.0.0) Added .apk patching
62 # Added 3G Dongle support for Nexus 7
63 # TabletUI support for Nexus 7 (maybe more)
64 # Google Voice support for Nexus 7
65 # mods are 3gdongle, tabletUI, voice, or nexus7suite (for all)
66 # Added provisional file copy menu to widen patching base
68 # 2012.09.11. (2.0.1) Cygwin support fixes
69 # 2012.09.11. (2.0.2) Bugfix for 3gdongle (all)
70 # 2012.09.16. (2.1.0) Significant restructuring of core operations; added edit text file
71 # fix for "method-cap" errors in pdroid.
72 # 2012.09.20. (2.1.1) Fix for Phone FC's; OSX support finalized; ContentResolver resolved
73 # 2012.09.28. (2.1.2) Hotfix for failed pdroid patching. Logging improvements.
74 # 2012.10.07. (2.1.5) Final pdroid support for CM7.2 Official Releases
75 # Added aosp-mod patches for pdroid patching of AOSP kangs
76 # Switched to Chainfire's (f)aapt for speed/space reasons
77 # 2012.10.13. (2.1.6) New PDroid patches for aokp-jb and cm10 4.1.2
78 # Revert (f)aapt- temporary due to reported issues
79 # 2012.10.15. (2.17) New (again) CM10 pdroid patches.
80 # Move files to be copied into $p/$R/$B
81 # -This required a bunch of file moving-report broken symlinks.
82 # Some error check on the old RIL delete functions (thanks bundrik)
83 # 2012.10.16. (2.1.7.5) Fix FC on phone with CM10 pdroid patches
84 # 2012.10.19. (2.1.9) Testing CM10 support for PDroid Extension by CollegeDev.
86 # SHELL PROGRAMMING NOTES:
88 # [[ -n STRING ]] or [[ -z STRING ]]
90 VERSION
="Auto-Patcher v2.1.9"
95 # by pastime1971 and mateorod
98 # pass variables to children
101 # function for converting hex to binary- for testing
102 #function h2b { echo "obase=2; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; }
106 echo " pdroid 1.32 patches 2012.09.13."
107 echo " v6supercharger patches 2012.08.17."
109 echo "usage: $0 ROM.ZIP MODS [ROMTYPE] [PATCHDATE]"
111 echo "MODS can be pdroid,v6supercharger or pdroid or v6supercharger"
112 echo "optional [ROMTYPE] can be cm9, aokp, etc."
113 echo "optional [PATCHDATE] can be specified to use older patch versions."
114 echo "try \"$0 ROM.ZIP -h\" to see what is available"
120 echo "! please refer to $LOG for any debugging"
122 echo "! patching failed."
123 echo "! it may be possible to patch $ROM using other patch version"
125 [ -d "$TEMP" ] && \rm
-rf "$TEMP"
130 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
132 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
139 echo $@ |
tee -a "$LOG"
144 echo "File for which patching failed:"
145 echo "---------------------------------------------"
149 echo "---------------------------------------------"
151 echo "We can try to add a premade copy of those files."
152 echo "This sometimes works."
154 echo "But IT MAY NOT WORK!!!"
157 askconsent
&& return 0 ||
return 1
162 echo -n "Do you want to proceed ? (YES/no) "
164 echo "askconsent intial = ${PROCEED}" >> "$LOG"
173 echo -n "Are you sure ? (YES/no) "
175 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
178 return 0; # successful
189 echo $
(cygpath
-ua "$1")
192 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
193 [[ ${1:0:1} == "/" ]] && echo "$1" ||
echo "$PWD/$1"
196 echo $
(readlink
-f "$1")
199 if [[ ${1:0:1} == "/" ]]; then
201 elif [[ ${1:0:2} == "./" ]]; then
213 echo $
(cygpath
-da "$1")
221 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
223 parse
() { echo "${1%%_*}"; }
226 if [ -f system
/build.prop
]; then
227 result
=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
235 VID
=$
(getbuildprop ro.build.version.release
)
237 if [ "${VID%.*}" == "2.3" ]; then
240 elif [ "${VID%.*}" == "4.0" ]; then
242 MID
=$
(getbuildprop ro.rommanager.developerid
)
243 [[ "$MID" == "" ]] && MID
=$
(parse $
(getbuildprop ro.modversion
))
244 DID
=$
(getbuildprop ro.product.device
)
245 [[ "$DID" == "" ]] && DID
=$
(getbuildprop ro.build.product
)
248 pa|cm9|cm|cyanogenmod
*)
254 # aosp|AOSP) # AOSP probing does not work yet
259 echo "!!! $MID is not supported yet, trying generic latest !!!"
262 elif [ "${VID%.*}" == "4.1" ]; then
264 MID
=$
(getbuildprop ro.build.display.id
)
265 [[ "$MID" == "" ]] && MID
=$
(parse $
(getbuildprop ro.build.display.id
))
266 DID
=$
(getbuildprop ro.product.device
)
267 [[ "$DID" == "" ]] && DID
=$
(getbuildprop ro.build.product
)
270 pa
*|cm10|cm
*|cyanogenmod
*)
281 printerror
"unknown ROM version $VID"
283 echo "... result of ROM check: version= $VID rom= $RID ..."
285 # Adding build date query
286 UTC
=$
(getbuildprop ro.build.
date.utc
)
287 BDID
=`date -d "1970-01-01 UTC $UTC seconds" +"%Y-%m-%d"`
291 if [ -s 'jar -xvf "$ROMX" system/framework/framework2.jar' ]; then
293 echo "No framework2.jar found; defaulting to $RID"
296 echo "Framework2.jar found; using $RID patches"
300 RIL
=$
(getbuildprop ro.telephony.ril_class
)
301 [[ -n $RIL ]] && printtask
"... result of ROM check: RIL= $RIL"
306 GARBAGE
=($
(find $@
-name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
307 GARBAGE
=($
(find $@
-name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
311 echo "# VER= $VERSION" >> "$LOG"
312 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
313 echo "# VID= $VID" >> "$LOG"
314 echo "# MID= $MID" >> "$LOG"
315 echo "# RID= $RID" >> "$LOG"
316 echo "# BDID= $BDID" >> "$LOG"
317 echo "# DID= $DID" >> "$LOG"
318 echo "# BID= $BID" >> "$LOG"
319 echo "# PID= ${PID[@]}" >> "$LOG"
322 [[ $# -lt 1 ||
$1 == "-h" ||
-z $1 ]] && printusage
324 ROOT
=$
(abspath
`dirname "$0"`)
325 TOOL
="$ROOT/patch_tools.tgz"
326 PTCH
="$ROOT/patch_patches.tgz"
330 if [[ $OSTYPE == "cygwin" ]]; then
335 DATE
=`date +%Y%m%d%H%M%S`
336 TEMP
=$
(abspath .
/tmp
$DATE)
337 LOG
=$
(abspath .
/log
$DATE)
338 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
339 echo "ROOT= $ROOT" >> "$LOG"
340 echo "TOOL= $TOOL" >> "$LOG"
341 echo "ROM= $ROM" >> "$LOG"
342 echo "ROMX= $ROMX" >> "$LOG"
344 \rm
-f restore.
zip update.
zip
346 CHK
=$
(getconf LONG_BIT
)
347 if [[ $CHK = "64" ]]; then
349 else [[ $BIT = "32" ]];
354 printtask
"### verify tools ###"
355 which patch >> "$LOG" || printerror
"Missing \"patch diff command\""
356 which tar >> "$LOG" || printerror
"Missing \"tar archive command\""
357 which jar
>> "$LOG" || printerror
"Missing \"jar (JDK)\""
358 which java
>> "$LOG" || printerror
"Missing \"java (JRE)\""
359 which cpio >> "$LOG" || printerror
"Missing \"cpio archive command\""
360 [ -f "$TOOL" ] || printerror
"patch tool is missing"
361 [ -f "$PTCH" ] || printerror
"patch patches are missing"
362 printtask
"### verify ROM ###"
363 [ -f "$ROM" ] || printerror
"Cannot find $ROM"
364 echo "### running $0 $@" >> "$LOG"
370 echo "PATH= $PATH" >> "$LOG"
372 printtask
"### unzip patch tools ###"
373 tar xvzf
"$TOOL" > /dev
/null || printerror
"failed extracting tools !!!"
375 # Get OS specific tools
378 \
mv cygwin
/aapt.exe .
379 \
mv cygwin
/*.exe boot
/
380 \rm
-rf cygwin
# why? If you want to we can keep/add it to mac/linux, though.
393 printtask
"### unzip patch patches ###"
394 tar xvzf
"$PTCH" > /dev
/null || printerror
"failed extracting patches !!!"
396 # we need build.prop for both RIL probing and ROM probing
397 jar
-xvf "$ROMX" system
/build.prop
2>> "$LOG" || printerror
"failed extracting build.prop from $ROMX !!!"
400 printtask
"### probe rom type ###"
402 \rm
-f system
/build.prop
404 if [ $# -gt 3 ]; then
410 if [ $# -gt 2 ]; then
412 echo "... Using $RID patches ..."
414 echo "... Using results of ROM check ..."
418 if [ $# -gt 1 ]; then
422 PIL
="pdroid v6supercharger"
424 # a hack to make sure pdroid is the first mod
425 [[ ${PIL[@]} =~ pdroid
]] && PID
=(pdroid
)
426 for P
in ${PIL[@]}; do
427 [[ ${PID[@]} =~
$P ]] || PID
=(${PID[@]} $P)
433 if [[ ( "$PID" == "-h" ||
"$RID" == "-h" ||
"$BID" == "-h" ) ]]; then
434 echo "### supported patch candidates ###"
435 [ "$PID" != "-h" ] && PL
=${PID[@]} || PL
=`ls patches/`
436 for P
in ${PL[@]}; do
437 [ "$PID" != "-h" -a "$RID" != "-h" ] && RL
=${RID[@]} || RL
=`ls patches/$P/`
438 for R
in ${RL[@]} ; do
439 [ $R == "common" -o ! -d patches
/$P/$R ] && continue
441 \
ls --ignore="*.sh" --ignore="*.txt" -r patches
/$P/$R/
445 for P
in ${PID[@]}; do
446 [ -d patches
/$P ] || printerror
"$P is not available"
448 [ -d patches
/$P/$RID ] && R
=$RID || R
=generic
449 #[ -d patches/$P/$R/$BID ] && B=$BID || B=latest
452 [ -f patches
/$P/files.txt
] && FILES
=$
(cat patches
/$P/files.txt
)
453 [ -f patches
/$P/$R/files.txt
] && FILES
=$
(cat patches
/$P/$R/files.txt
)
454 for FILE
in ${FILES[@]}; do
457 [[ ${CID[@]} =~ ${FILE:1} ]] && printerror "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
460 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
463 [[ ${JID[@]} =~
$FILE ]] || JID
=(${JID[@]} $FILE)
466 [[ ${AID[@]} =~
$FILE ]] || AID
=(${AID[@]} $FILE)
469 [[ ${IID[@]} =~
$FILE ]] || IID
=(${IID[@]} $FILE)
472 [[ ${TID[@]} =~
$FILE ]] || TID
=(${TID[@]} $FILE)
477 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
478 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
479 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
480 echo "### APK FILES= ${AID[@]}" >> "$LOG"
481 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
482 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
484 printtask
"### unzip rom ###"
485 # extract system files
486 jar
-xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || printerror "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from
$ROMX !!!"
487 #\cp -a system/ backup # only for debugging purpose
489 printtask "### create updater script ###"
490 jar
-xvf "$ROMX" META-INF
/com
/google
/android
/updater-script META-INF
/com
/google
/android
/update-binary
491 jar
-xvf "$ROMX" META-INF
/com
/google
/android
/update-binary-installer
1> /dev
/null
2> /dev
/null
492 if [ -f META-INF
/com
/google
/android
/update-binary-installer
]; then
493 printtask
"... using Aroma installer ..."
494 \
mv META-INF
/com
/google
/android
/update-binary-installer META-INF
/com
/google
/android
/update-binary
496 printtask
"... using Clockworkmod installer ..."
498 if [ -f META-INF
/com
/google
/android
/update-binary
]; then
499 #echo "# original updater-script" >> "$LOG"
500 #cat META-INF/com/google/android/updater-script >> "$LOG"
502 cat META-INF
/com
/google
/android
/updater-script |
grep ^mount |
grep "/system" |
head -n 1 > updater-script
503 [ -s updater-script
] ||
echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
505 for FILE
in ${EID[@]}; do
506 # restore the original
507 jar
-xvf "$ROMX" $FILE 2> /dev
/null || printtask
"!!! warning $FILE cannot be restored !!!"
509 for FILE
in ${CID[@]}; do
510 # replace with the original or delete it
511 jar
-xvf "$ROMX" $FILE 2> /dev
/null ||
echo "delete(\"/$FILE\");" >> updater-script
514 echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
515 # add permission management
516 cat META-INF
/com
/google
/android
/updater-script |
grep set_perm |
grep "/system" >> updater-script
517 # TODO: remove if we don't need it any more
518 for P
in ${PID[@]}; do
519 if [ -s patches
/$P/set_perm.txt
]; then
520 echo "...adding permissions..."
521 cat patches
/$P/set_perm.txt
>> updater-script
525 cat META-INF
/com
/google
/android
/updater-script |
grep ^unmount |
grep "/system" |
head -n 1 >> updater-script
527 [[ ${IID[@]} =~ boot.img
]] && cat META-INF
/com
/google
/android
/updater-script |
grep "boot.img" >> updater-script
529 cat updater-script
> META-INF
/com
/google
/android
/updater-script
531 echo "# generated updater-script" >> "$LOG"
532 cat updater-script
>> "$LOG"
534 # this is not enough any more
535 jar
-xvf update-template.
zip META-INF
/com
/google
/android
/update-binary META-INF
/com
/google
/android
/updater-script
538 printtask
"### create restore.zip ###"
539 jar
-cfv tmp.
zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF
> /dev
/null
2>> "$LOG"
540 java
-jar signapk.jar updatecert.pem updatekey.pk8 tmp.
zip signed.
zip 2>> "$LOG"
541 \
mv signed.
zip restore.
zip
544 printtask
"### decompile system files ###"
545 # decompile system files
546 for FILE
in ${JID[@]}; do
548 printtask
"... decompile $JAR ..."
549 java
-jar baksmali.jar
-b -a 15 -o tmp
/${FILE}.out
/smali
${FILE} >> "$LOG" 2>> "$LOG"
550 if [ $FILE == "system/framework/framework.jar" ]; then
551 printtask
"... extract preloaded-classes ..."
552 jar
-xvf ${FILE} preloaded-classes
>> "$LOG" 2>> "$LOG"
553 \
mv preloaded-classes tmp
/${FILE}.out
/
556 for FILE
in ${AID[@]}; do
558 printtask
"... decompile $APK ..."
559 if [ $FILE == "system/framework/framework-res.apk" ]; then
560 printtask
"... installing framework files ..."
561 java
-jar apktool.jar
if $FILE
563 java
-jar apktool.jar d
-f $FILE tmp
/$FILE.out
566 for FILE
in ${IID[@]}; do
567 printtask
"### unpacking $FILE ###"
571 .
/unpackbootimg
$EXE -i ..
/boot.img
>> "$LOG" 2>> "$LOG"
575 gzip -dc ..
/boot.img-ramdisk.gz |
cpio -i >> "$LOG" 2>> "$LOG"
579 printerror
"cannot process $FILE"
585 # apply system modification
586 for P
in ${PID[@]}; do
587 [ -d patches
/$P/$RID ] && R
=$RID || R
=generic
588 [ -d patches
/$P/$R/$BID ] && B
=$BID || B
=latest
592 unset FILES COPY DELS JARS APKS IMGS TXTS
593 [ -f patches
/$P/files.txt
] && FILES
=$
(cat patches
/$P/files.txt
)
594 [ -f patches
/$P/$R/files.txt
] && FILES
=$
(cat patches
/$P/$R/files.txt
)
595 for FILE
in ${FILES[@]}; do
598 COPY
=(${COPY[@]} ${FILE:1})
601 DELS
=(${DELS[@]} ${FILE:1})
604 JARS
=(${JARS[@]} $FILE)
607 APKS
=(${APKS[@]} $FILE)
610 IMGS
=(${IMGS[@]} $FILE)
613 TXTS
=(${TXTS[@]} $FILE)
618 [[ -n ${COPY[@]} ]] && printtask
"### copy patch $P/$R/$B ###"
619 for FILE
in ${COPY[@]}; do
620 printtask
"... copying $FILE ..."
623 if [ -e patches
/$P/$R/$B/$FILE ]; then
624 [ -e $FILE ] && printtask
"... overwriting $FILE from $P ..."
625 \
cp -av patches
/$P/$R/$B/$FILE .
/$DEST >> "$LOG"
627 printerror
"$FILE is missing in the patch"
631 # unconditional smali copying
632 [ -f patches
/$P/smali.txt
] && SMALI
=$
(cat patches
/$P/smali.txt
)
633 [ -f patches
/$P/$R/smali.txt
] && SMALI
=$
(cat patches
/$P/$R/smali.txt
)
634 [ -f patches
/$P/$R/$B/smali.txt
] && SMALI
=$
(cat patches
/$P/$R/$B/smali.txt
)
636 for SMALI
in ${SMALI[@]}; do
637 printtask
"... overwriting $MOVE ..."
638 \
cp -av patches
/$P/$ANDR/provisionals
/$SMALI tmp
/$SMALI >> "$LOG"
642 [[ -n ${DELS[@]} ]] && printtask
"### delete patch $P/$R/$B ###"
643 for FILE
in ${DELS[@]}; do
644 printtask
"... deleting $FILE ..."
648 [[ -n ${JARS[@]} ]] && printtask
"### jar patch $P/$R/$B ###"
649 for FILE
in ${JARS[@]}; do
652 printtask
"... apply $NAME.patch ..."
653 patch -Nls -p1 -d tmp
/${FILE}.out < $PRB/${NAME}.patch 2>&1 > ${JAR}.log
654 cat ${JAR}.log |
tee -a "$LOG"
657 # patch preloaded-classes only if a patch exists
658 if [ -f $PRB/preloaded.
patch ]; then
659 printtask
"... apply preloaded.patch ..."
660 patch -Nls -p1 -d tmp
/${FILE}.out
< $PRB/preloaded.
patch 2>&1 > preloaded.log
661 cat preloaded.log |
tee -a "$LOG"
662 [[ `grep FAILED preloaded.log` != "" ]] && printerror
"failed preloaded.patch"
666 echo -n "" # do nothing else
669 # substitute failed smali with premade jar
671 FAILS
=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
672 if [[ -n ${FAILS[@]} ]]; then
673 printtask
"!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
674 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
675 for FAIL
in ${FAILS[@]}; do
676 echo "!!! patch error for $FAIL !!!" >> "$LOG"
677 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG"
678 [[ ${SID[@]} =~
$FAIL ]] && printerror
"$FAIL was already replaced before"
679 [ -f patches
/$P/$ANDR/provisionals
/${FILE}.out
/smali
/${FAIL} ] || printerror
"failed $FAIL in $JAR cannot be remedied"
680 copyfailed || printerror
"failed $NAME.patch"
681 printtask
"... replace $FAIL ..."
682 \rm
-rf tmp
/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
683 \
cp -av patches
/$P/$ANDR/provisionals
/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} >> "$LOG" || echo "FAILED to cp $FAIL" >> ${JAR}.log
684 #echo "### replacing ${FAILS[@]} from patches/$P/common/${FILE} ###" > ${JAR}.log
685 #java -jar baksmali.jar -b -a 15 -o pmp/${FILE}.out/smali patches/$P/common/provisionals/${FAIL} >> "$LOG" 2>> "$LOG" || echo "FAILED to baksmali $FILE" >> ${JAR}.log
686 #\cp -a pmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} || echo "FAILED to cp $FAIL" >> ${JAR}.log
687 SID
=(${SID[@]} $FAIL)
690 [[ `grep FAILED ${JAR}.log` != "" ]] && printerror
"failed $NAME.patch"
691 garbage tmp
/${FILE}.out
692 if [ -f patches
/$P/$R/$B/{JAR
}.sh
]; then
693 printtask
"... apply $JAR.sh ..."
694 . patches
/$P/$R/$B/{JAR
}.sh
2>&1 > ${JAR}.log
695 cat ${JAR}.log |
tee -a "$LOG"
699 [[ -n ${APKS[@]} ]] && printtask
"### apk patch $P/$R/$B ###"
700 for FILE
in ${APKS[@]}; do
703 printtask
"... apply $APK.patch ..."
704 patch -Nls -p2 -d tmp
/${FILE}.out < $PRB/${APK}.patch 2>&1 >> ${APK}.log
705 cat ${APK}.log |
tee -a "$LOG"
706 [[ `grep FAILED ${APK}.log` != "" ]] && printerror
"failed $APK.patch"
707 garbage tmp
/${FILE}.out
710 [[ -n ${IMGS[@]} ]] && printtask
"### img patch $P/$R/$B ###"
711 for FILE
in ${IMGS[@]}; do
714 echo "... applying $IMG.patch ..."
715 patch -Nls -p1 -d boot
/ramdisk
< $PRB/${IMG}.
patch >> "$LOG" || printerror
"failed patching $FILE"
716 # Special Instructions- married to boot.img patching by necessity, not design. When
717 # added to it's own section, it only runs for one mod. WIP.
718 #if [ -f patches/$P/$R/special_instructions.sh ]; then
719 # . patches/$P/$R/special_instructions.sh
720 #elif [ -f patches/$P/special_instruction.sh ]; then
721 # . patches/$P/special_instructions.sh
725 [[ -n ${TXTS[@]} ]] && printtask
"### text patch $P/$R/$B ###"
726 for FILE
in ${TXTS[@]}; do
728 if [[ -f $PRB/${TXT}.
patch ]]; then
729 printtask
"... apply $TXT.patch ..."
730 patch -Nls -p2 -d system
/ < $PRB/${TXT}.
patch 2>&1 > ${TXT}.log
731 #cat ${TXT}.log | tee -a "$LOG"
732 [[ `grep FAILED ${TXT}.log` != "" ]] && printerror
"failed $TXT.patch"
734 if [[ -f $PR/${TXT}.
awk ]]; then
735 printtask
"... apply $TXT.awk ..."
736 awk -f $PR/${TXT}.
awk $FILE > text || printerror
"failed $TXT.awk"
739 if [[ -f $PR/${TXT}.
sed ]]; then
740 printtask
"... apply $TXT.sed ..."
741 sed -f $PR/${TXT}.
sed $FILE > text || printerror
"failed $TXT.sed"
744 if [[ -f $PR/${TXT}.sh
]]; then
745 printtask
"... apply $TXT.sh ..."
746 .
$PR/${TXT}.sh
2>&1 >> ${TXT}.log || printerror
"failed $TXT.sh"
752 # Rebuilding system files
754 [[ -n ${JID[@]} ]] && printtask
"### rebuild jar ###"
755 for FILE
in ${JID[@]}; do
757 printtask
"... rebuild $JAR ..."
758 java
-Xmx512M -jar smali.jar
-a 15 tmp
/${FILE}.out
/smali
-o tmp
/${FILE}.out
/classes.dex
>> "$LOG" 2>> "$LOG"
759 [ -f tmp
/${FILE}.out
/classes.dex
] || printerror
"failed compiling $JAR !!!"
760 jar
-ufv ${FILE} -C tmp
/${FILE}.out
/ classes.dex
>> "$LOG" 2>> "$LOG"
761 if [ $FILE == "system/framework/framework.jar" ]; then
762 jar
-ufv ${FILE} -C tmp
/${FILE}.out
/ preloaded-classes
>> "$LOG" 2>> "$LOG"
766 [[ -n ${AID[@]} ]] && printtask
"### rebuild apk ###"
767 for FILE
in ${AID[@]}; do
769 printtask
"... rebuild $APK ..."
770 java
-jar apktool.jar b tmp
/${FILE}.out
>> "$LOG" 2>> "$LOG" || printerror
"failed compiling $FILE !!!"
771 jar
-ufv $FILE -C tmp
/${FILE}.out
/build
/apk
/ .
> /dev
/null
2>> "$LOG"
772 #\rm -r tmp/${FILE}.out
775 [[ -n ${IID[@]} ]] && printtask
"### rebuild img ###"
776 for FILE
in ${IID[@]}; do
777 printtask
"### rebuild $FILE ###"
780 # Rebuilding boot.img
782 printtask
"... rebuilding ramdisk ..."
783 .
/mkbootfs
$EXE .
/ramdisk |
gzip > ramdisk-new.gz
785 printtask
"... composing boot.img ..."
786 BASE
=$
(cat boot.img-base
)
787 # convert hex to decimal in cygwin by prefixing "0x" and C-style arithmetic
788 PGSIZE
=$
((${PGFORM}$
(cat boot.img-pagesize
)))
789 CMDLINE
=$
(cat boot.img-cmdline
)
790 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
791 echo "pagesize = $PGSIZE" >> "$LOG"
792 echo "base = $BASE" >> "$LOG"
794 printtask
"... rebuilding boot.img ..."
795 .
/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"
799 printerror
"cannot process $FILE"
804 printtask
"### create update.zip ###"
805 jar
-cfv tmp.
zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF
>> "$LOG" 2>> "$LOG"
806 java
-jar signapk.jar updatecert.pem updatekey.pk8 tmp.
zip update.
zip 2>> "$LOG"
809 #echo "# miscellaneous log" >> "$LOG"
811 \
mv restore.
zip update.
zip ..
812 echo "### finished ###"
813 echo "flash update.zip to install the modified"
814 echo "flash restore.zip to restore the original"
817 for P
in ${PID[@]}; do
818 [ -d patches
/$P/$RID ] && R
=$RID || R
=generic
819 if [ -f patches
/$P/$R/README.txt
]; then
820 cat patches
/$P/$R/README.txt
821 elif [ -f patches
/$P/README.txt
]; then
822 cat patches
/$P/README.txt