Skip to content

Commit

Permalink
odex strategy, create_backup function
Browse files Browse the repository at this point in the history
  • Loading branch information
scality-q committed Jun 22, 2020
1 parent 8fa40ec commit f82ad3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
51 changes: 37 additions & 14 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,28 +41,23 @@ 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 --'
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..."
Expand All @@ -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
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f82ad3a

Please sign in to comment.