2018-03-20 17:52:53 +00:00
|
|
|
#!/sbin/sh
|
|
|
|
##########################################################################################
|
|
|
|
#
|
|
|
|
# NanoDroid Patcher survival script
|
|
|
|
# by Nanolx
|
|
|
|
#
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# Generic Functions
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
setup_environment () {
|
|
|
|
TMPDIR=/dev/tmp/install
|
2018-09-08 17:16:45 +00:00
|
|
|
|
2018-09-08 19:43:28 +00:00
|
|
|
export ANDROID_DATA=${TMPDIR}
|
2018-08-29 15:01:33 +00:00
|
|
|
export PATCHER_ADDOND_DATA=/data/adb/nanodroid_patcher
|
2018-09-08 17:16:45 +00:00
|
|
|
|
2018-12-22 17:46:34 +00:00
|
|
|
if [ -f /data/adb/magisk/util_functions.sh ]; then
|
|
|
|
NVBASE=/data/adb
|
|
|
|
elif [ -f /data/magisk/util_functions.sh ]; then
|
|
|
|
NVBASE=/data
|
|
|
|
fi
|
|
|
|
|
|
|
|
MAGISK_IMG=${NVBASE}/magisk.img
|
2018-03-20 17:52:53 +00:00
|
|
|
MAGISK_PATH=/dev/tmp/magisk_img
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_print() {
|
2018-09-08 19:43:28 +00:00
|
|
|
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
|
|
|
|
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
is_mounted () {
|
|
|
|
if [ ! -z "$2" ]; then
|
|
|
|
cat /proc/mounts | grep $1 | grep $2, >/dev/null
|
|
|
|
else
|
|
|
|
cat /proc/mounts | grep $1 >/dev/null
|
|
|
|
fi
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_image() {
|
|
|
|
if [ ! -d "$2" ]; then
|
|
|
|
mount -o rw,remount rootfs /
|
|
|
|
mkdir -p "$2" 2>/dev/null
|
|
|
|
[ ! -d "$2" ] && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! is_mounted "$2"; then
|
|
|
|
LOOPDEVICE=
|
|
|
|
for LOOP in 0 1 2 3 4 5 6 7; do
|
|
|
|
if ! is_mounted "$2"; then
|
|
|
|
LOOPDEVICE=/dev/block/loop$LOOP
|
|
|
|
[ -e $LOOPDEVICE ] || mknod $LOOPDEVICE b 7 $LOOP 2>/dev/null
|
|
|
|
losetup $LOOPDEVICE "$1" && mount -t ext4 -o loop $LOOPDEVICE "$2"
|
|
|
|
if is_mounted "$2"; then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# taken from Magisk, with minor modifications for NanoDroid
|
|
|
|
mount_partitions () {
|
2018-07-08 17:10:37 +00:00
|
|
|
SLOT=$(grep_cmdline androidboot.slot_suffix)
|
2018-03-20 17:52:53 +00:00
|
|
|
if [ -z ${SLOT} ]; then
|
2018-08-05 11:17:16 +00:00
|
|
|
SLOT=_$(grep_cmdline androidboot.slot)
|
2018-03-20 17:52:53 +00:00
|
|
|
[ "${SLOT}" = "_" ] && SLOT=
|
|
|
|
fi
|
|
|
|
|
2018-09-04 18:07:06 +00:00
|
|
|
is_mounted /data || mount /data || error "failed to mount /data!"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
|
|
|
${BOOTMODE} || mount -o bind /dev/urandom /dev/random
|
|
|
|
|
2018-08-05 11:17:16 +00:00
|
|
|
! is_mounted /system && mount -o rw /system
|
2018-03-20 17:52:53 +00:00
|
|
|
|
|
|
|
if [ ! -f /system/build.prop ]; then
|
|
|
|
SYSTEMBLOCK=$(find /dev/block -iname system${SLOT} | head -n 1)
|
2018-08-05 11:17:16 +00:00
|
|
|
mount -t ext4 -o rw ${SYSTEMBLOCK} /system
|
2018-03-20 17:52:53 +00:00
|
|
|
fi
|
|
|
|
|
2018-08-05 11:17:16 +00:00
|
|
|
[ -f /system/build.prop ] || is_mounted /system || error "failed to mount /system (unsupported A/B device?)"
|
2018-07-08 17:10:37 +00:00
|
|
|
|
|
|
|
if [ -f /system/init ]; then
|
2018-03-20 17:52:53 +00:00
|
|
|
mkdir /system_root 2>/dev/null
|
|
|
|
mount --move /system /system_root
|
|
|
|
mount -o bind /system_root/system /system
|
|
|
|
fi
|
2018-08-05 11:17:16 +00:00
|
|
|
|
|
|
|
[ ! -f /system/build.prop ] && error "failed to mount /system (unsupported A/B device?)"
|
2018-08-27 16:12:17 +00:00
|
|
|
|
2018-08-29 15:01:33 +00:00
|
|
|
if [ -L /system/vendor ]; then
|
|
|
|
! is_mounted /vendor && mount /vendor
|
|
|
|
if ! is_mounted /vendor; then
|
|
|
|
VENDORBLOCK=$(find /dev/block -iname vendor${SLOT} | head -n 1)
|
|
|
|
mount -t ext4 -o ro ${VENDORBLOCK} /vendor
|
|
|
|
fi
|
2018-09-15 21:00:55 +00:00
|
|
|
elif [ -d /system/vendor ]; then
|
2018-08-29 15:01:33 +00:00
|
|
|
### XXX work-around required for some ROMs
|
|
|
|
echo " xxx compat /vendor link created!"
|
2018-09-15 21:00:55 +00:00
|
|
|
ln -sf /system/vendor /vendor >/dev/null
|
2018-08-27 16:12:17 +00:00
|
|
|
fi
|
2018-08-27 19:25:03 +00:00
|
|
|
|
2018-08-29 15:01:33 +00:00
|
|
|
mount | awk '{print $1 " on " $3}'
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error () {
|
2018-09-06 18:27:19 +00:00
|
|
|
ui_print " "
|
|
|
|
ui_print " !! ${@}"
|
|
|
|
ui_print " "
|
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
magisk_cleanup
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# Device Functions
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
detect_outfd () {
|
2018-09-08 18:02:24 +00:00
|
|
|
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
|
|
|
|
# We will have to manually find out OUTFD
|
2018-03-20 17:52:53 +00:00
|
|
|
for FD in `ls /proc/$$/fd`; do
|
2018-09-08 18:02:24 +00:00
|
|
|
if readlink /proc/$$/fd/$FD | grep -q pipe; then
|
|
|
|
if ps | grep -v grep | grep -q " 3 $FD "; then
|
2018-03-20 17:52:53 +00:00
|
|
|
OUTFD=$FD
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_bootmode () {
|
2018-11-09 20:21:27 +00:00
|
|
|
[ -z ${BOOTMODE} ] && BOOTMODE=false
|
|
|
|
${BOOTMODE} || ps | grep zygote | grep -qv grep && BOOTMODE=true
|
2018-09-01 17:14:09 +00:00
|
|
|
${BOOTMODE} || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grep_prop() {
|
2018-12-27 21:11:09 +00:00
|
|
|
[ -f /vendor/build.prop ] && \
|
|
|
|
FILES="/system/build.prop /vendor/build.prop" || \
|
|
|
|
FILES="/system/build.prop"
|
|
|
|
|
|
|
|
sed -n "s/^${1}=//p" ${FILES} | head -n 1
|
2018-08-05 11:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grep_cmdline() {
|
|
|
|
local REGEX="s/^${1}=//p"
|
|
|
|
sed -E 's/ +/\n/g' /proc/cmdline | \
|
|
|
|
sed -n "${REGEX}" 2>/dev/null
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 19:07:23 +00:00
|
|
|
detect_odex () {
|
2018-08-27 18:04:25 +00:00
|
|
|
SERVICES_JAR_DEX=$(unzip -lq /system/framework/services.jar | grep classes.dex)
|
|
|
|
|
2018-08-27 19:46:52 +00:00
|
|
|
if [ -n "$(find '/system/framework/' -name 'services.vdex')" ]; then
|
2018-08-27 19:41:36 +00:00
|
|
|
ROM_DEX_STATUS=VDEX
|
2018-08-27 19:46:52 +00:00
|
|
|
elif [ -n "$(find '/system/framework/' -name 'services.odex')" ]; then
|
2018-08-27 19:41:36 +00:00
|
|
|
ROM_DEX_STATUS=ODEX
|
2018-08-27 19:51:18 +00:00
|
|
|
else ROM_DEX_STATUS=UNKOWN
|
2018-08-24 19:24:01 +00:00
|
|
|
fi
|
2018-08-26 19:08:04 +00:00
|
|
|
|
2018-08-27 19:41:36 +00:00
|
|
|
[ "${SERVICES_JAR_DEX}" ] && ROM_DEX_STATUS=DEODEX
|
|
|
|
|
2018-08-27 19:51:18 +00:00
|
|
|
ui_print " "
|
|
|
|
ui_print " ++"
|
|
|
|
ui_print " ++ services.jar status: ${ROM_DEX_STATUS}"
|
|
|
|
ui_print " ++"
|
2018-09-06 18:44:11 +00:00
|
|
|
|
|
|
|
[ "${SDK_VERSION}" -gt 27 -a "${ROM_DEX_STATUS}" != "DEODEX" ] && \
|
|
|
|
error "Pie is only supported on de-odexed ROMs currently"
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
detect_arch () {
|
|
|
|
ABI=$(grep_prop ro.product.cpu.abi | cut -c-3)
|
|
|
|
ABI2=$(grep_prop ro.product.cpu.abi2 | cut -c-3)
|
|
|
|
ABILONG=$(grep_prop ro.product.cpu.abi)
|
|
|
|
|
|
|
|
ARCH=arm
|
|
|
|
|
|
|
|
[ "$ABI" = "x86" ] && ARCH=x86
|
|
|
|
[ "$ABI2" = "x86" ] && ARCH=x86
|
|
|
|
[ "$ABILONG" = "arm64-v8a" ] && ARCH=arm64
|
|
|
|
[ "$ABILONG" = "x86_64" ] && ARCH=x86_64
|
|
|
|
|
|
|
|
case ${ARCH} in
|
|
|
|
arm | arm64 )
|
|
|
|
ZIPB=${BASEDIR}/zip.arm
|
2018-11-14 21:22:38 +00:00
|
|
|
FILE=${BASEDIR}/file.arm
|
2018-08-26 16:58:59 +00:00
|
|
|
|
|
|
|
if [ -f ${TMPDIR}/busybox.arm ]; then
|
|
|
|
BUSY=${TMPDIR}/busybox.arm
|
|
|
|
else BUSY=${BASEDIR}/busybox.arm
|
|
|
|
fi
|
2018-03-20 17:52:53 +00:00
|
|
|
;;
|
|
|
|
x86 | x86_64 )
|
|
|
|
ZIPB=${BASEDIR}/zip.x86
|
2018-11-14 21:22:38 +00:00
|
|
|
FILE=${BASEDIR}/file.x86
|
2018-08-26 16:58:59 +00:00
|
|
|
|
|
|
|
if [ -f ${TMPDIR}/busybox.x86 ]; then
|
|
|
|
BUSY=${TMPDIR}/busybox.x86
|
|
|
|
else BUSY=${BASEDIR}/busybox.x86
|
|
|
|
fi
|
2018-03-20 17:52:53 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-10-02 21:32:20 +00:00
|
|
|
DALVIKVM_BIN=$(ls -l /system/bin/dalvikvm | awk '{print $NF}')
|
2018-11-14 21:22:38 +00:00
|
|
|
DALVIKVM_ARCH=$("${FILE}" -m "${BASEDIR}/magic.mgc" -L /system/bin/dalvikvm)
|
|
|
|
|
2018-10-02 21:32:20 +00:00
|
|
|
case ${DALVIKVM_BIN} in
|
2018-11-19 21:13:15 +00:00
|
|
|
dalvikvm32 )
|
|
|
|
export LD_LIBRARY_PATH="/system/lib:/vendor/lib:/system/vendor/lib"
|
|
|
|
;;
|
|
|
|
|
|
|
|
dalvikvm64 )
|
|
|
|
export LD_LIBRARY_PATH="/system/lib64:/vendor/lib64:/system/vendor/lib64"
|
|
|
|
;;
|
|
|
|
|
2018-11-14 21:22:38 +00:00
|
|
|
dalvikvm )
|
|
|
|
case ${DALVIKVM_ARCH} in
|
|
|
|
*32-bit* )
|
|
|
|
export LD_LIBRARY_PATH="/system/lib:/vendor/lib:/system/vendor/lib"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*64-bit* )
|
|
|
|
export LD_LIBRARY_PATH="/system/lib64:/vendor/lib64:/system/vendor/lib64"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2018-10-02 21:32:20 +00:00
|
|
|
esac
|
2018-08-26 13:04:23 +00:00
|
|
|
|
2018-09-06 18:48:31 +00:00
|
|
|
export PATH="${BASEDIR}/busybox:/system/bin:/system/xbin"
|
|
|
|
|
2018-09-05 19:31:44 +00:00
|
|
|
V_EX=${BASEDIR}/vdexExtractor.${ARCH}
|
2018-08-26 16:58:59 +00:00
|
|
|
|
|
|
|
chmod 0755 ${BUSY}
|
2018-09-08 19:43:28 +00:00
|
|
|
|
|
|
|
rm -rf ${BASEDIR}/busybox
|
2018-08-26 16:58:59 +00:00
|
|
|
mkdir -p ${BASEDIR}/busybox
|
|
|
|
|
2018-09-08 17:16:45 +00:00
|
|
|
ln -sf ${BUSY} ${BASEDIR}/busybox/busybox
|
2018-08-26 16:58:59 +00:00
|
|
|
${BUSY} --install -s ${BASEDIR}/busybox/
|
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
ui_print " > device architecture: ${ARCH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_sdk () {
|
|
|
|
SDK_VERSION=$(grep_prop ro.build.version.sdk)
|
|
|
|
|
2018-09-06 16:11:41 +00:00
|
|
|
[ "${SDK_VERSION}" -gt 28 ] && \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "Android versions beyond Pie are not yet supported"
|
2018-08-26 17:03:06 +00:00
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
[ "${SDK_VERSION}" -lt 16 ] && \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "Android versions before Jelly Bean are not supported"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-12-27 21:11:09 +00:00
|
|
|
if [ "${SDK_VERSION}" -gt 25 ]; then
|
|
|
|
BAKSMALI="${BASEDIR}/baksmali_26.dex"
|
|
|
|
SMALI="${BASEDIR}/smali_26.dex"
|
|
|
|
elif [ "${SDK_VERSION}" -gt 23 ]; then
|
|
|
|
BAKSMALI="${BASEDIR}/baksmali_25.dex"
|
|
|
|
SMALI="${BASEDIR}/smali_25.dex"
|
|
|
|
else
|
|
|
|
BAKSMALI="${BASEDIR}/baksmali_23.dex"
|
|
|
|
SMALI="${BASEDIR}/smali_23.dex"
|
|
|
|
fi
|
2018-08-27 16:53:57 +00:00
|
|
|
|
2018-09-19 16:42:34 +00:00
|
|
|
PATCH_CORE="${BASEDIR}/core_services.jar.dex"
|
2018-12-25 19:42:11 +00:00
|
|
|
PATCH_UNLP="${BASEDIR}/unifiednlp_services.jar.dex"
|
2018-09-19 16:42:34 +00:00
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
if [ "${SDK_VERSION}" -lt 24 ]; then
|
|
|
|
ui_print " > Android 4.1 - 6.0 (SDK ${SDK_VERSION}) detected"
|
|
|
|
PATCH_HOOK="${BASEDIR}/hook_4.1-6.0_services.jar.dex"
|
|
|
|
else
|
2018-08-24 19:24:01 +00:00
|
|
|
ui_print " > Android 7.0 - 9.0 (SDK ${SDK_VERSION}) detected"
|
|
|
|
PATCH_HOOK="${BASEDIR}/hook_7.0-9.0_services.jar.dex"
|
2018-03-20 17:52:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ "${SDK_VERSION}" -gt 21 ] && DEX_OPTS="--multi-dex-threaded"
|
|
|
|
}
|
|
|
|
|
2018-12-27 21:11:09 +00:00
|
|
|
##########################################################################################
|
|
|
|
# by @ale5000
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
search_fake_package_signature () {
|
|
|
|
PERMISSION=android.permission.FAKE_PACKAGE_SIGNATURE
|
|
|
|
PERMISSION_OD=$(echo -n "${PERMISSION}" | od -A n -t x1 | tr -d '\n' | sed -e 's/^ //g;s/ /00/g')
|
|
|
|
HAS_FAKESIGN=false
|
|
|
|
|
|
|
|
FW_RES_DIR="${TMPDIR}/framework-res"
|
2019-03-09 21:16:47 +00:00
|
|
|
|
|
|
|
if [ ! -f ${FW_RES_DIR}/AndroidManifest.xml ]; then
|
|
|
|
mkdir -p "${FW_RES_DIR}"
|
|
|
|
unzip -o /system/framework/framework-res.apk -d "${FW_RES_DIR}" 2>/dev/null
|
|
|
|
fi
|
2018-12-27 21:11:09 +00:00
|
|
|
|
|
|
|
grep -qF "${PERMISSION}" "${FW_RES_DIR}/AndroidManifest.xml" && HAS_FAKESIGN=true
|
|
|
|
od -A n -t x1 "${FW_RES_DIR}/AndroidManifest.xml" | tr -d ' \n' | grep -qF "${PERMISSION_OD}" && HAS_FAKESIGN=true
|
|
|
|
|
|
|
|
${HAS_FAKESIGN} && return 0 || return 1
|
|
|
|
}
|
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
##########################################################################################
|
|
|
|
# Magisk Functions
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
grow_magisk_img () {
|
|
|
|
request_size_check /tmp/services.jar
|
|
|
|
image_size_check ${MAGISK_IMG}
|
|
|
|
if [ "$reqSizeM" -gt "$curFreeM" ]; then
|
|
|
|
SIZE=$(((reqSizeM + curUsedM) / 32 * 32 + 64))
|
|
|
|
resize2fs -f ${MAGISK_IMG} ${SIZE}M
|
|
|
|
e2fsck -yf ${MAGISK_IMG}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
shrink_magisk_img () {
|
|
|
|
image_size_check ${MAGISK_IMG}
|
|
|
|
NEWDATASIZE=$((curUsedM / 32 * 32 + 32))
|
|
|
|
if [ "$curSizeM" -gt "$NEWDATASIZE" ]; then
|
|
|
|
resize2fs -f ${MAGISK_IMG} ${NEWDATASIZE}M
|
|
|
|
e2fsck -yf ${MAGISK_IMG}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
request_size_check() {
|
|
|
|
reqSizeM=`unzip -l "$1" 2>/dev/null | tail -n 1 | awk '{ print $1 }'`
|
|
|
|
reqSizeM=$((reqSizeM / 1048576 + 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
image_size_check() {
|
|
|
|
e2fsck -yf $1
|
|
|
|
curBlocks=`e2fsck -n $1 2>/dev/null | grep $1 | cut -d, -f3 | cut -d\ -f2`;
|
|
|
|
curUsedM=`echo "$curBlocks" | cut -d/ -f1`
|
|
|
|
curSizeM=`echo "$curBlocks" | cut -d/ -f1`
|
|
|
|
curFreeM=$(((curSizeM - curUsedM) * 4 / 1024))
|
|
|
|
curUsedM=$((curUsedM * 4 / 1024 + 1))
|
|
|
|
curSizeM=$((curSizeM * 4 / 1024))
|
|
|
|
}
|
|
|
|
|
|
|
|
magisk_setup () {
|
|
|
|
if [ -f ${MAGISK_IMG} ]; then
|
|
|
|
grow_magisk_img || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to grow magisk.img"
|
2018-03-20 17:52:53 +00:00
|
|
|
mount_image ${MAGISK_IMG} ${MAGISK_PATH} || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to mount ${MAGISK_PATH}"
|
2018-03-20 17:52:53 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
magisk_cleanup () {
|
|
|
|
if (is_mounted ${MAGISK_PATH}); then
|
|
|
|
umount ${MAGISK_PATH}
|
|
|
|
losetup -d $LOOPDEVICE
|
|
|
|
rmdir ${MAGISK_PATH}
|
|
|
|
shrink_magisk_img || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to shrink magisk.img"
|
2018-03-20 17:52:53 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# Patcher Functions
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
setup_patcher () {
|
|
|
|
ui_print " > preparing environment"
|
|
|
|
|
|
|
|
rm -rf ${TMPDIR}
|
|
|
|
mkdir -p ${TMPDIR}
|
|
|
|
|
2019-03-09 21:16:47 +00:00
|
|
|
unzip -o "${ZIP}" -d ${TMPDIR} 2>/dev/null || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to prepare environment"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-09-08 18:16:54 +00:00
|
|
|
for bin in zip.arm zip.x86 \
|
2018-08-26 16:02:36 +00:00
|
|
|
vdexExtractor.arm vdexExtractor.x86 \
|
2018-11-19 17:26:45 +00:00
|
|
|
vdexExtractor.arm64 vdexExtractor.x86_64 \
|
2018-11-14 21:22:38 +00:00
|
|
|
file.arm file.x86; do
|
2018-03-20 17:52:53 +00:00
|
|
|
chmod 0755 "${BASEDIR}/${bin}" || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to prepare environment"
|
2018-03-20 17:52:53 +00:00
|
|
|
done
|
2018-08-27 18:59:47 +00:00
|
|
|
|
|
|
|
mkdir -p /data/adb/
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 19:31:44 +00:00
|
|
|
call_dalvikvm () {
|
|
|
|
for jar in /system/framework/*.jar ; do
|
|
|
|
BOOTCLASSES=${BOOTCLASSES}:${jar}
|
|
|
|
done
|
|
|
|
|
2018-11-19 18:09:14 +00:00
|
|
|
DALVIKVM_OPTS="-verbose:gc -verbose:jit -verbose:jni \
|
|
|
|
-verbose:class -Xnodex2oat -Xnoimage-dex2oat"
|
2018-09-08 17:21:26 +00:00
|
|
|
|
2018-09-05 19:31:44 +00:00
|
|
|
if [ "${ROM_DEX_STATUS}" = "DEODEX" ]; then
|
|
|
|
/system/bin/dalvikvm \
|
|
|
|
-Xbootclasspath:${BOOTCLASSES} \
|
2018-09-08 17:21:26 +00:00
|
|
|
${DALVIKVM_OPTS} \
|
2018-09-05 19:31:44 +00:00
|
|
|
"${@}"
|
|
|
|
else
|
|
|
|
/system/bin/dalvikvm \
|
2018-09-08 17:21:26 +00:00
|
|
|
${DALVIKVM_OPTS} \
|
2018-09-05 19:31:44 +00:00
|
|
|
"${@}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-10-20 21:56:49 +00:00
|
|
|
deodex_vdex () {
|
|
|
|
ui_print " >> deodexing services.jar [VDEX]"
|
|
|
|
|
|
|
|
cp /system/framework/oat/${ARCH}/services.vdex \
|
|
|
|
${BASEDIR}/services.vdex || \
|
|
|
|
error "failed to copy services.vdex"
|
|
|
|
|
|
|
|
${V_EX} -i ${BASEDIR}/services.vdex \
|
|
|
|
--ignore-crc-error --debug=4 || \
|
|
|
|
error "failed to deodex services.vdex"
|
|
|
|
|
|
|
|
mv ${BASEDIR}/services.apk_classes.dex ${BASEDIR}/classes.dex || \
|
|
|
|
error "failed to deodex services.vdex"
|
|
|
|
|
|
|
|
${ZIPB} -j "${BASEDIR}/services.jar" \
|
|
|
|
"${BASEDIR}/classes.dex" || \
|
|
|
|
error "zip failed"
|
|
|
|
}
|
|
|
|
|
|
|
|
deodex_odex () {
|
|
|
|
ui_print " >> deodexing services.jar [ODEX]"
|
|
|
|
|
|
|
|
cp "/system/framework/oat/${ARCH}/services.odex" "${BASEDIR}"
|
|
|
|
|
|
|
|
# baksmali/smali options switches (version dependent)
|
|
|
|
MAIN=Main
|
|
|
|
DEODEX="x"
|
|
|
|
ASSEMBLE="a"
|
|
|
|
BOOTCLASSPATH="-b"
|
|
|
|
CLASSPATHDIR="-d"
|
|
|
|
|
|
|
|
if [ "${SDK_VERSION}" -lt 24 ]; then
|
|
|
|
MAIN=main
|
|
|
|
DEODEX="-x"
|
|
|
|
ASSEMBLE=
|
|
|
|
BOOTCLASSPATH="-c"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ui_print " [1] baksmali services.odex"
|
|
|
|
|
|
|
|
call_dalvikvm \
|
|
|
|
-classpath "${BAKSMALI}" \
|
|
|
|
org.jf.baksmali.${MAIN} \
|
|
|
|
${DEODEX} \
|
|
|
|
${BOOTCLASSPATH} "/system/framework/${ARCH}/boot.oat" \
|
|
|
|
${CLASSPATHDIR} "/system/framework/${ARCH}" \
|
|
|
|
${CLASSPATHDIR} "/system/framework" \
|
|
|
|
-o "${BASEDIR}/services.jar-deodex" \
|
|
|
|
"${BASEDIR}/services.odex" || \
|
|
|
|
error "failed to deodex services.jar"
|
|
|
|
|
|
|
|
ui_print " [2] smali services.odex"
|
|
|
|
|
|
|
|
call_dalvikvm \
|
|
|
|
-classpath "${SMALI}" \
|
|
|
|
org.jf.smali.${MAIN} \
|
|
|
|
${ASSEMBLE} \
|
|
|
|
-o "${BASEDIR}/services.jar-deodex/classes.dex" \
|
|
|
|
"${BASEDIR}/services.jar-deodex" || \
|
|
|
|
error "failed to rebuild classes.dex"
|
|
|
|
|
|
|
|
${ZIPB} -j "${BASEDIR}/services.jar" \
|
|
|
|
"${BASEDIR}/services.jar-deodex"/classes*.dex || \
|
|
|
|
error "zip failed"
|
|
|
|
|
|
|
|
rm -rf "${BASEDIR}/services.jar-deodex"
|
|
|
|
}
|
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
patch_services () {
|
|
|
|
ui_print " "
|
|
|
|
ui_print " > patching signature spoofing support"
|
|
|
|
ui_print " "
|
|
|
|
|
|
|
|
cp /system/framework/services.jar \
|
|
|
|
${BASEDIR}/services.jar || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to copy services.jar"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-08-25 19:43:43 +00:00
|
|
|
if [ "${ROM_DEX_STATUS}" = "VDEX" ]; then
|
2018-10-20 21:56:49 +00:00
|
|
|
deodex_vdex
|
|
|
|
|
2018-08-25 21:23:26 +00:00
|
|
|
elif [ "${ROM_DEX_STATUS}" = "ODEX" ]; then
|
2018-10-20 21:56:49 +00:00
|
|
|
deodex_odex
|
2018-08-25 19:43:43 +00:00
|
|
|
fi
|
2018-08-24 19:47:56 +00:00
|
|
|
|
|
|
|
mkdir -p "${BASEDIR}/services.jar-mod"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-12-25 19:42:11 +00:00
|
|
|
PATCHES="${PATCH_HOOK} ${PATCH_CORE} ${PATCH_UNLP}"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
|
|
|
ui_print " >> patching services.jar"
|
2018-10-20 21:56:49 +00:00
|
|
|
|
2018-09-05 19:31:44 +00:00
|
|
|
call_dalvikvm \
|
2018-03-20 17:52:53 +00:00
|
|
|
-classpath "${BASEDIR}/dexpatcher.dex" \
|
|
|
|
lanchon.dexpatcher.Main \
|
|
|
|
${DEX_OPTS} --api-level "${SDK_VERSION}" \
|
2018-08-26 16:02:36 +00:00
|
|
|
--verbose --debug --output ${BASEDIR}/services.jar-mod \
|
2018-03-20 17:52:53 +00:00
|
|
|
${BASEDIR}/services.jar ${PATCHES} || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to apply patches"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-08-30 18:06:20 +00:00
|
|
|
${ZIPB} -d "${BASEDIR}/services.jar" \
|
2018-08-26 10:53:17 +00:00
|
|
|
'classes*.dex' || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "zip failed"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-08-30 18:06:20 +00:00
|
|
|
${ZIPB} -j "${BASEDIR}/services.jar" \
|
2018-08-26 10:53:17 +00:00
|
|
|
"${BASEDIR}/services.jar-mod"/classes*.dex || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "zip failed"
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
backup_services_jar () {
|
|
|
|
ui_print " << backing up services.jar to: /sdcard/nanodroid_backups"
|
2018-12-25 19:41:09 +00:00
|
|
|
services_name="services.jar_$(grep_prop ro.build.flavor)_$(grep_prop ro.build.id)"
|
|
|
|
|
2018-03-20 17:52:53 +00:00
|
|
|
mkdir -p /sdcard/nanodroid_backups
|
2018-12-25 19:41:09 +00:00
|
|
|
cp /system/framework/services.jar "/sdcard/nanodroid_backups/${services_name}" || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to backup services.jar"
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_services () {
|
|
|
|
ui_print " "
|
|
|
|
for destination in /dev/tmp/magisk_img/NanoDroid /dev/tmp/magisk_img/NanoDroid_microG \
|
2018-12-22 17:46:34 +00:00
|
|
|
/sbin/.magisk/img/NanoDroid /sbin/.magisk/img/NanoDroid_microG /; do
|
2018-03-20 17:52:53 +00:00
|
|
|
if [ -d ${destination} ]; then
|
|
|
|
install_path="${destination}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${install_path}" = "/" ]; then
|
|
|
|
mount -orw,remount /system || \
|
2018-09-06 18:43:18 +00:00
|
|
|
error "failed to mount /system read-write"
|
2018-03-20 17:52:53 +00:00
|
|
|
backup_services_jar
|
|
|
|
fi
|
|
|
|
|
|
|
|
ui_print " << installing patched files to: ${install_path}"
|
|
|
|
|
|
|
|
mkdir -p "${install_path}/system/framework"
|
|
|
|
cp ${BASEDIR}/services.jar "${install_path}/system/framework" \
|
2018-09-06 18:43:18 +00:00
|
|
|
|| error "failed to install services.jar"
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-08-24 19:24:01 +00:00
|
|
|
touch /data/adb/NanoDroid_Patched
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
##########################################################################################
|
|
|
|
# addon.d
|
|
|
|
##########################################################################################
|
|
|
|
|
|
|
|
install_addond () {
|
|
|
|
ui_print " "
|
|
|
|
ui_print " Installing addon.d restoration setup"
|
|
|
|
|
2018-09-08 18:20:07 +00:00
|
|
|
rm -rf ${PATCHER_ADDOND_DATA}
|
2018-08-29 15:01:33 +00:00
|
|
|
mkdir -p ${PATCHER_ADDOND_DATA}
|
2018-03-20 17:52:53 +00:00
|
|
|
|
|
|
|
[ -d /data/nanomod.patcher ] && rm -rf /data/nanomod.patcher
|
|
|
|
[ -d /data/adb/nanomod_patcher ] && rm -rf /data/nanomod_patcher
|
2018-04-10 19:47:19 +00:00
|
|
|
rm -f /system/addon.d/75-nanomodpatcher.sh \
|
2018-09-17 17:04:45 +00:00
|
|
|
/system/addon.d/75-nanodroidpatcher.sh \
|
|
|
|
/system/addon.d/999-nanodroidpatcher.sh
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-12-25 19:42:11 +00:00
|
|
|
for file in core_services.jar.dex unifiednlp_services.jar.dex dexpatcher.dex \
|
2018-08-24 19:24:01 +00:00
|
|
|
hook_4.1-6.0_services.jar.dex hook_7.0-9.0_services.jar.dex \
|
2018-11-14 21:22:38 +00:00
|
|
|
baksmali_25.dex smali_25.dex baksmali_26.dex smali_26.dex magic.mgc; do
|
2018-08-29 15:01:33 +00:00
|
|
|
cp "${BASEDIR}/${file}" ${PATCHER_ADDOND_DATA}/
|
2018-03-20 17:52:53 +00:00
|
|
|
done
|
|
|
|
|
2018-08-29 15:01:33 +00:00
|
|
|
cp /dev/tmp/CommonPatcher ${PATCHER_ADDOND_DATA}/
|
2018-03-20 17:52:53 +00:00
|
|
|
|
2018-11-14 21:22:38 +00:00
|
|
|
for file in ${ZIPB} ${V_EX} ${BUSY} ${FILE}; do
|
2018-09-08 18:16:54 +00:00
|
|
|
cp ${file} ${PATCHER_ADDOND_DATA}/
|
|
|
|
chmod 0755 ${PATCHER_ADDOND_DATA}/$(basename "${file}")
|
|
|
|
done
|
2018-08-26 16:58:59 +00:00
|
|
|
|
2018-09-04 17:16:04 +00:00
|
|
|
mkdir -p /system/addon.d/
|
2018-09-15 20:05:03 +00:00
|
|
|
cp "${BASEDIR}/70-nanodroidpatcher.sh" /system/addon.d/
|
|
|
|
chmod 0755 /system/addon.d/70-nanodroidpatcher.sh
|
2018-03-20 17:52:53 +00:00
|
|
|
}
|
|
|
|
|