diff --git a/customize.sh b/customize.sh index d407a2e..47b6d13 100644 --- a/customize.sh +++ b/customize.sh @@ -8,6 +8,21 @@ my_grep_prop() { sed -n "$REGEX" $FILES 2>/dev/null | head -n 1 } +create_backup() { + local path="$1" + local filename="${path##*/}" + local extension="${filename##*.}" + filename="${filename%.*}" + ui_print "-- Searching for $filename.$extension backup..." + if [ -f "/data/adb/modules/NFCScreenOff/${filename}_bak.$extension" ]; then + ui_print "-- ${filename}_bak.$extension found! Copying backup to the module update folder." + cp "/data/adb/modules/NFCScreenOff/${filename}_bak.$extension" "$MODPATH/${filename}_bak.$extension" + else + ui_print "-- ${filename}_bak.$extension not found. Creating backup of original $filename.$extension." + cp "$path" "$MODPATH/${filename}_bak.$extension" + fi +} + ui_print "-- Searching for NFC app in /system/app/ folder..." set 'NfcNci' 'NQNfcNci' 'NxpNfcNci' for name do @@ -26,7 +41,7 @@ ROM="$(my_grep_prop 'build\.version')" [ -z "$MANUFACTURER" ] && MANUFACTURER="$(my_grep_prop 'ro\.product\.vendor\.manufacturer')" [ -z "$MODEL" ] && MODEL="$(my_grep_prop 'ro\.product\.vendor\.model')" [ -z "$DEVICE" ] && DEVICE="$(my_grep_prop 'ro\.product\.vendor\.device')" -printf "%s\n%s\n%s\n%s\n%s\n" "MANUFACTURER=$MANUFACTURER" "MODEL=$MODEL" "DEVICE=$DEVICE" "ROM=$ROM" "APK_NAME=$APK_NAME" > "$MODPATH/.env" +printf "%s\n%s\n%s\n%s\n%s\n" "APK_NAME=$APK_NAME" "MANUFACTURER=$MANUFACTURER" "MODEL=$MODEL" "DEVICE=$DEVICE" "ROM=$ROM" > "$MODPATH/.env" # print device infos ui_print '-- Device info --' @@ -34,20 +49,15 @@ ui_print "$(cat $MODPATH/.env)" ui_print '-----------------' APK_PATH="/system/app/$APK_NAME/$APK_NAME.apk" +APK_DIR="$(dirname $APK_PATH)" REPLACE=" /system/app/$APK_NAME " mkdir "$MODPATH/$APK_NAME" -# create backup -ui_print "-- Searching for $APK_NAME.apk backup..." -if [ -f "/data/adb/modules/NFCScreenOff/${APK_NAME}_bak.apk" ]; then - ui_print "-- ${APK_NAME}_bak.apk found! Copying backup to the module update folder." - cp "/data/adb/modules/NFCScreenOff/${APK_NAME}_bak.apk" "$MODPATH/${APK_NAME}_bak.apk" -else - ui_print "-- ${APK_NAME}_bak.apk not found. Creating backup of original $APK_NAME.apk." - cp "$APK_PATH" "$MODPATH/${APK_NAME}_bak.apk" -fi +create_backup "$APK_PATH" +create_backup "$APK_DIR/oat/arm64/$APK_NAME.odex" +create_backup "$APK_DIR/oat/arm64/$APK_NAME.vdex" # retrieve modded apk ui_print "-- Searching for custom $APK_NAME.apk in extracted files..." @@ -61,11 +71,24 @@ else # prepare files ui_print "-- ${APK_NAME}_align.apk not found." ui_print "-- Zipping $APK_NAME.apk and device's framework ($(which zip))" - cp "$MODPATH/${APK_NAME}_bak.apk" "$TMPDIR/$APK_NAME.apk" - zip -j "$TMPDIR/$APK_NAME.zip" "$MODPATH/.env" "$TMPDIR/$APK_NAME.apk" /system/framework/framework-res.apk + ln -s "$MODPATH/${APK_NAME}_bak.apk" "$TMPDIR/$APK_NAME.apk" + ln -s "$MODPATH/${APK_NAME}_bak.odex" "$TMPDIR/$APK_NAME.odex" + ln -s "$MODPATH/${APK_NAME}_bak.vdex" "$TMPDIR/$APK_NAME.vdex" + ln -s /system/framework/arm64 "$TMPDIR/arm64" + zip -j "$TMPDIR/$APK_NAME" "$MODPATH/.env" "$TMPDIR/$APK_NAME.apk" /system/framework/framework-res.apk # download custom apk - ui_print "-- Uploading device's apks for modding ($(which curl))" - curl --fail -X PUT --upload-file "$TMPDIR/$APK_NAME.zip" -o "$MODPATH/${APK_NAME}_align.apk" https://patcher.lapw.at || abort "!! Could not find a smali folder while disassembling ${APK_NAME}.apk." + ui_print "-- Uploading device's apks for modding ($(which curl)), it may take a while ($(( $( stat -c '%s' $TMPDIR/$APK_NAME.zip) / 1024 / 1024))Mb)" + curl --fail -X PUT --upload-file "$TMPDIR/$APK_NAME.zip" -o "$MODPATH/${APK_NAME}_align.apk" https://patcher.lapw.at + if [ $? -ne 0 ]; then + ui_print "-- Classic modding failed, trying odex strategy" + ui_print "-- Adding whole framework folder and odex/vdex files to archive" + printf "%s\n" "STRATEGY=odex" >> "$MODPATH/.env" + rm "$TMPDIR/$APK_NAME.zip" + zip -j "$TMPDIR/$APK_NAME" "$MODPATH/.env" "$TMPDIR/$APK_NAME.apk" "$TMPDIR/$APK_NAME.odex" "$TMPDIR/$APK_NAME.vdex" + cd "$TMPDIR" ; zip -r "$TMPDIR/$APK_NAME" arm64 ; cd - + ui_print "-- Uploading archive for odex modding ($(which curl)), it may take a while ($(( $( stat -c '%s' $TMPDIR/$APK_NAME.zip) / 1024 / 1024))Mb)" + curl --fail -X PUT --upload-file "$TMPDIR/$APK_NAME.zip" -o "$MODPATH/${APK_NAME}_align.apk" https://patcher.lapw.at || abort "!! Odex strategy failed." + fi ui_print "-- Downloaded custom $APK_NAME.apk from lapwat's servers" fi diff --git a/module.prop b/module.prop index eacf9b3..66a3c76 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=NFCScreenOff name=NFC Screen Off -version=v0.2.1 -versionCode=21 +version=v0.3.0 +versionCode=30 author=lapwat description=Read NFC tags when screen is off. [BETA] Tap to pay when screen is off.