Advertisement
mateorod

Untitled

Aug 27th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/auto_patcher b/auto_patcher
  2. index 582cf98..58358e8 100755
  3. --- a/auto_patcher
  4. +++ b/auto_patcher
  5. @@ -148,15 +148,16 @@
  6.  # 2013.08.07. (v3.0.0) Support for Android-4.3 (Opendproid only- CM and AOSP).
  7.  # 2013.08.09. (v3.0.1) Build date and patch date matching for multiple mods- all mods will now use best available match.
  8.  # 2013.08.12. (v3.0.2) OpD support for Evervolv, PACman and PA and CM10 returns
  9. +# 2013.08.12. (v3.1.0) The big switch to SMALI.patch instead of JAR.patch. It begins...
  10.  
  11.  
  12.  # SHELL PROGRAMMING NOTES:
  13.  # [ -s FILE ]
  14.  # [[ -n STRING ]] or [[ -z STRING ]]
  15.  
  16. -VERSION="v3.0.212"
  17. +VERSION="v3.1.0"
  18.  # PATCHES_VERSION needs to be incremented every time ANY changes occur to patches.
  19. -PATCHES_VERSION="20130815"
  20. +PATCHES_VERSION="20130827"
  21.  CURRENT_ANDROID="4.3.0"
  22.  
  23.  # pass variables to children
  24. @@ -453,8 +454,9 @@ copy_prepatched_provisional () {
  25.  
  26.  prep_alternate_patch () {
  27.       # Use alt.patch, if exists. Increment in case there are multiple alternates.
  28. +     # DEPRECATED as of the upcoming 3.1.0
  29.       mv -v $ALTERNATIVE_PATCH $PARB/${NAME}.patch >> "$LOG"
  30. -     ALT_PATCH_NUMBER=$((PATCH_NUMBER + 1))
  31. +     ALT_PATCH_NUMBER=$(($ALT_PATCH_NUMBER + 1))
  32.  
  33.       # Get fresh files/variables + decompile again (use rm b/c privacy files wouldn't get overwritten)
  34.       # TODO: test patch -R instead of re-decompiling. Should work.
  35. @@ -513,7 +515,7 @@ establish_repo() {
  36.            if ($NETWORK); then
  37.                 mv -v auto-patcher/".git" . >> "$LOG"
  38.                 rm -rf auto-patcher
  39. -               git checkout -q master || auto_update_error
  40. +               git checkout -q 3.1 || auto_update_error
  41.                 git reset --hard 2>&1 >> "$LOG"
  42.                 echo ""
  43.            fi
  44. @@ -1246,7 +1248,7 @@ if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
  45.            if !("$NETWORK"); then
  46.                 printtask "Updater: not able to run auto_update."
  47.            else
  48. -               COMMITS_BEHIND=$(git rev-list HEAD..origin/master --count)
  49. +               COMMITS_BEHIND=$(git rev-list HEAD..origin/3.1 --count)
  50.                 case "$COMMITS_BEHIND" in
  51.                 0)
  52.                      printtask "Updater: Auto-Patcher is already up to date"
  53. @@ -1256,7 +1258,7 @@ if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
  54.                      printtask "... Updater: update found ..."
  55.                      backup_script
  56.                      printtask "... Updating Auto-Patcher ..."
  57. -                    git merge --no-edit origin/master 2>&1 >> "$LOG" || auto_update_error
  58. +                    git merge --no-edit origin/3.1 2>&1 >> "$LOG" || auto_update_error
  59.                      export_log_and_variables
  60.                      printtask "### updated, now rerunning script with latest version ###"
  61.                      $0 "$@"
  62. @@ -1729,13 +1731,66 @@ for ((i=0; i < ${#PID[@]}; i++)); do
  63.       echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
  64.  
  65.       # Iterate through jars and patch. If fails, try prepatched provisionals or look for alternative patch.
  66. +
  67. +context_editor (){
  68. +     # This was originally planned to remove some unsused CM ContextImpl patches..but now it exists to force
  69. +     # efficacy if CM patches are forced on an AOSP-based rom, or AOSP patches on a CM-based.
  70. +
  71. +     # Counts the number of ContextImpl patches in the decompiled jar. Easy enough.
  72. +     CONTEXT_FILES=(tmp/system/framework/framework.jar.out/smali/android/app/ContextImpl*)
  73. +     if ( [ ${#CONTEXT_FILES[@]} == 48 ] ); then
  74. +          # Indicates CM-based roms (PACman, CM)
  75. +          print_to_log "CM-based ContextImpl matching implemented"
  76. +          ROM_BASE=cm
  77. +     elif ( [ ${#CONTEXT_FILES[@]} == 44 ] ); then
  78. +          # Indicates AOSP-based roms (PA, AOSP, Slim, AOKP(?))
  79. +          print_to_log "AOSP-based ContextImpl matching implemented"
  80. +          ROM_BASE=aosp
  81. +     else
  82. +          # Alerts us we need to expand the model, but leaves QUEUES alone for now
  83. +          print_to_log "There are ${#CONTEXT_FILES[@]} context files in this rom"
  84. +          ROM_BASE=$RID
  85. +     fi
  86. +
  87. +     # Remove the, unlikely but possibly, mismatched ContextImpl patches from all Queues
  88. +     FAILED_PATCH_QUEUE=( ${FAILED_PATCH_QUEUE[@]//*'ContextImpl'*} )
  89. +     PATCH_QUEUE=( ${PATCH_QUEUE[@]//*'ContextImpl'*} )
  90. +
  91. +     # Add the proper ContextImpl patches to the PATCH_QUEUE
  92. +     PATCH_QUEUE+=(patches/$P/$A/$ROM_BASE/latest/*'ContextImpl'*.patch)
  93. +}
  94. +
  95. +patch_matcher () {
  96. +     FAILED_FILE=${FAILED_PATCH##*/}     # strip path from file
  97. +     MATCHED_FILE=${FAILED_FILE##*_}     # strip headers from file name (e.g.returns 'SipPhone.patch')
  98. +     POSSIBLE_MATCHES=$( find patches/$P/$ANDR -name "*$MATCHED_FILE*" )
  99. +
  100. +     # Somewhere here we need to test for empty and test for too large (100?) #TODO IMPORTANT!
  101. +
  102. +     # MATCH_SUCCESS is solely used to provide a fail message to log. Is there another way?
  103. +     MATCH_SUCCESS=false
  104. +     for p in $POSSIBLE_MATCHES; do
  105. +          rm -rf ${JAR}.log # needs to be cleared (AND moved to a useful function)
  106. +               if ($PATCH_BINARY --dry-run -Nls -p1 -d tmp/${FILE}.out < $p 2>&1 >> ${JAR}.log ); then
  107. +                    # This below is temporary debug logging.
  108. +                    print_to_log "Succesful match found! Swapping $FAILED_PATCH for $p!!"
  109. +                    PATCH_QUEUE=( ${PATCH_QUEUE[@]//$FAILED_PATCH} )
  110. +                    PATCH_QUEUE+=( "$p" )
  111. +                    FAILED_PATCH_QUEUE=( ${FAILED_PATCH_QUEUE[@]//$FAILED_PATCH} )
  112. +                    MATCH_SUCCESS=true
  113. +                    break
  114. +               fi
  115. +     done
  116. +     [ $MATCH_SUCCESS == true ] || print_to_log "We did not find a working patch for $p...looking for other solutions!"                      
  117. +}
  118. +
  119.       for (( current_jar=0; current_jar < ${#JARS[@]}; current_jar++)); do
  120.            FILE=${JARS[$current_jar]}
  121.            JAR=${FILE##*/}
  122.            if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
  123.                 NAME=${JAR%.jar}
  124.            else
  125. -               # check for abscense of any apks decompiled by baksmali (~* in files.txt). Missing jars will still error
  126. +          # check for abscense of any apks decompiled by baksmali (~* in files.txt). Missing jar will still error
  127.                 if [ ! -d "tmp/${FILE}.out" ] ; then
  128.                      echo "No $JAR in your ROM. Not able to patch this file."
  129.                      echo "## No $JAR in ROM ###" >> "$LOG"
  130. @@ -1744,51 +1799,66 @@ for ((i=0; i < ${#PID[@]}; i++)); do
  131.                 fi
  132.                 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
  133.            fi
  134. +          
  135.            printtask "... apply $NAME.patch ..."
  136. -          $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
  137. -          for INCREMENTAL in $(ls $PARB/${NAME}-*.patch 2>/dev/null); do
  138. -               printtask "... apply $(basename $INCREMENTAL) ..."
  139. -               $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $INCREMENTAL 2>&1 >> ${JAR}.log
  140. -          done
  141. -          cat ${JAR}.log >> "$LOG"
  142. -          case "$NAME" in
  143. -          framework)
  144. -               # patch preloaded-classes only if a patch exists
  145. -               if [ -f $PARB/preloaded.patch ]; then
  146. +
  147. +          # In a test, this failed when retitled framework_00_preloaded.patch and added to QUEUE. But why?
  148. +          if ( [[ "$NAME" == "framework" ]] && [ -f $PARB/preloaded.patch ] ); then
  149.                      printtask "... apply preloaded.patch ..."
  150.                      $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
  151. -                    cat preloaded.log >> "$LOG"
  152.                      [[ $(grep FAILED preloaded.log) != "" ]] && print_error "failed preloaded.patch"
  153. -               fi
  154. -               ;;
  155. -          *)
  156. -               echo -n ""     # do nothing else
  157. -               ;;
  158. -          esac
  159. -          # substitute failed smali with provisional (a prepatched smali file)
  160. -          unset FAILS
  161. -          FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))
  162. -          ALT_PATCH_NUMBER=2
  163. -          if [[ -n ${FAILS[@]} ]]; then
  164. -               print_to_log "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
  165. -               echo "### replace ${FAILS[@]} ###" > ${JAR}.log
  166. -               for FAIL in ${FAILS[@]}; do
  167. +          fi
  168. +
  169. +
  170. +          declare -a PATCH_QUEUE=("patches/$P/$A/$R/$B/$NAME"_*patch)
  171. +          [ -f "patches/$P/$A/$R/$B/$NAME"-* ] && declare -a INCREMENTAL=( "patches/$P/$A/$R/$B/$NAME"-* )
  172. +          declare -a FAILED_PATCH_QUEUE
  173. +          rm -rf {JAR}.log # Needed since we append the patch output now
  174. +
  175. +          for ((k=0;k < ${#PATCH_QUEUE[@]}; k++)) do
  176. +               # dry-run until we build a completely succesful patch queue. Add $k to FAILED upon failure
  177. +               $PATCH_BINARY --dry-run -Nls -p1 -d tmp/${FILE}.out < ${PATCH_QUEUE[$k]} 2>&1 >> ${JAR}.log || FAILED_PATCH_QUEUE+=( ${PATCH_QUEUE[$k]} )
  178. +          done
  179. +
  180. +          FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))          
  181. +          [[ -n ${FAILED_PATCH_QUEUE[@]} ]] && [[ "$NAME" == "framework" ]] && context_editor
  182. +          for FAILED_PATCH in ${FAILED_PATCH_QUEUE[@]}; do
  183. +              patch_matcher
  184. +          done
  185. +          if [[ -n ${FAILED_PATCH_QUEUE[@]} ]]; then # while ?
  186. +               for FAILED_PATCH in ${FAILED_PATCH_QUEUE[@]}; do
  187. +               # Mostly unartful workarounds so we can manipulate either the patch in FAIL or the FILE
  188. +
  189. +                    FAILED_FILE=${FAILED_PATCH##*/}            #strip path from file
  190. +                    MATCHED_FILE=${FAILED_FILE##*_}            #strip headers from file name
  191. +
  192. +                    # MATCH_PATTERN includes period (e.g. 'FILE.') to avoid globbing extra files (e.g.FILE$2)
  193. +                    MATCH_PATTERN=${MATCHED_FILE%patch}
  194. +
  195. +                    for ITEM in ${FAILS[@]}; do
  196. +                         [[ "$ITEM" =~ "${MATCH_PATTERN}" ]] && FAIL=$ITEM && break
  197. +                    done
  198. +
  199.                      PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
  200. -                    ALTERNATIVE_PATCH=$(ls $PARB/${NAME}$ALT_PATCH_NUMBER*.patch 2>/dev/null)
  201.                      if [ ! -f "$PROVISIONAL" ]; then
  202. -                         if [ -f "$ALTERNATIVE_PATCH" ]; then
  203. -                              printtask "## trying alternative ${NAME} patch ###"
  204. -                              prep_alternate_patch
  205. -                         else
  206. -                              print_error "failed $FAIL in $JAR cannot be remedied"
  207. -                         fi
  208. +                         print_error $MATCH_PATTERN"patch in $JAR cannot be remedied"
  209.                      else
  210. -                         echo "!!! patch error for $FAIL !!!" >> "$LOG"
  211. -                         [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
  212. +                         print_to_log "!!! patch error for $FAIL !!!"
  213. +                         [[ ${SID[@]} =~ $MATCHED_FILE ]] && print_error "$MATCHED_FILE was already replaced before"
  214.                           copy_prepatched_provisional
  215. +                         patch_matcher
  216. +  # this includes the period (e.g. 'Instrumentation.') so it does not pick up extra files (e.g. Instrumentation$2
  217.                      fi
  218.                 done
  219.            fi
  220. +          rm -rf ${JAR}.log # needs to be cleared and for the same reason as above
  221. +
  222. +          # Actual application of patches occurs here!
  223. +          for ((k=0;k < ${#PATCH_QUEUE[@]}; k++)) do
  224. +               print_to_log " ...applying ${PATCH_QUEUE[$k]} ..."
  225. +               $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < ${PATCH_QUEUE[$k]} 2>&1 >> ${JAR}.log
  226. +          done
  227. +          # Incremental--use patch_matcher? (how, b/c dry-run...should INCREMENTAL be optional (or fail-possible?
  228.            [[ $(grep FAILED ${JAR}.log) != "" ]] &&  print_error "failed $NAME.patch"
  229.            garbage tmp/${FILE}.out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement