mirror of
https://gitlab.com/Nanolx/NanoDroid
synced 2024-10-31 09:20:23 +00:00
527 lines
14 KiB
Bash
527 lines
14 KiB
Bash
#!/sbin/sh
|
|
##########################################################################################
|
|
#
|
|
# NanoDroid System Testing Script
|
|
# by Nanolx
|
|
#
|
|
##########################################################################################
|
|
|
|
VERSION=23.2.99999999
|
|
TMPDIR=/dev/tmp
|
|
LOGFILE="/data/media/0/nanodroid_logs/NanoDroid-SysTest-$(date +%Y%m%d-%H.%M.%S).log"
|
|
|
|
##########################################################################################
|
|
# Generic Functions
|
|
##########################################################################################
|
|
|
|
show_banner () {
|
|
ui_print " "
|
|
ui_print "*******************"
|
|
ui_print " NanoDroid SysTest "
|
|
ui_print " ${VERSION} "
|
|
ui_print "*******************"
|
|
ui_print " "
|
|
}
|
|
|
|
ui_print() {
|
|
${BOOTMODE} && echo "${1}" || \
|
|
echo -e "ui_print ${1}\nui_print" >> /proc/self/fd/${OUTFD}
|
|
}
|
|
|
|
is_mounted () {
|
|
grep -q " $(readlink -f ${1}) " /proc/mounts 2>/dev/null
|
|
return $?
|
|
}
|
|
|
|
# taken from Magisk, with modifications for NanoDroid
|
|
mount_apex_loop () {
|
|
local number=0
|
|
local minorx=1
|
|
local loop
|
|
|
|
[ -e /dev/block/loop1 ] && minorx=$(stat -Lc '%T' /dev/block/loop1)
|
|
|
|
apex_mount="${1}"
|
|
|
|
while [ ${number} -lt 64 ]; do
|
|
loop=/dev/block/loop${number}
|
|
[ -e ${loop} ] || mknod ${loop} b 7 $((number * minorx))
|
|
|
|
if losetup "${loop}" /apex/apex_payload.img 2>/dev/null; then
|
|
if mount -text4 -oro,noatime "${loop}" "${apex_mount}"; then
|
|
rm -f /apex/apex_payload.img
|
|
break
|
|
fi
|
|
fi
|
|
|
|
number=$((number + 1))
|
|
done
|
|
}
|
|
|
|
# taken from Magisk, with modifications for NanoDroid
|
|
mount_apex () {
|
|
mkdir -p /apex
|
|
|
|
for apex in /system/apex/*; do
|
|
apex_mount="/apex/$(basename ${apex} .apex)"
|
|
apex_loop="/dev/loop_apex_$(basename ${apex} .apex)"
|
|
|
|
[ "${apex_mount}" == /apex/com.android.runtime.release ] && apex_mount=/apex/com.android.runtime
|
|
[ "${apex_mount}" == /apex/com.android.runtime.debug ] && apex_mount=/apex/com.android.runtime
|
|
[ "${apex_mount}" == /apex/com.android.art.release ] && apex_mount=/apex/com.android.art
|
|
[ "${apex_mount}" == /apex/com.android.art.debug ] && apex_mount=/apex/com.android.art
|
|
|
|
mkdir -p "${apex_mount}"
|
|
|
|
APEX_LD="${apex_mount}/lib:${APEX_LD}"
|
|
APEX_LD_64="${apex_mount}/lib64:${APEX_LD_64}"
|
|
|
|
if [ -f "${apex}" ]; then
|
|
unzip -oq "${apex}" apex_payload.img -d /apex
|
|
mount_apex_loop "${apex_mount}" || error "APEX loop setup failed!"
|
|
elif [ -d "${apex}" ]; then
|
|
mount -o bind "${apex}" "${apex_mount}"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# taken from Magisk, with modifications for NanoDroid
|
|
toupper() {
|
|
echo "$@" | tr '[:lower:]' '[:upper:]'
|
|
}
|
|
|
|
find_block () {
|
|
local block partname devname device
|
|
|
|
for block in "${@}"; do
|
|
block=${block}${SLOT}
|
|
device=$(find /dev/block \( -type b -o -type c -o -type l \) -name ${block} | head -n 1)
|
|
|
|
if [ -n "$device" ]; then
|
|
readlink -f "$device"
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
for block in "${@}"; do
|
|
block=${block}${SLOT}
|
|
for uevent in /sys/dev/block/*/uevent; do
|
|
partname=$(awk -F= '/PARTNAME/{print $2}' ${uevent})
|
|
devname=$(awk -F= '/DEVNAME/{print $2}' ${uevent})
|
|
if [ "$(toupper ${block})" = "$(toupper ${partname})" ]; then
|
|
echo /dev/block/${devname}
|
|
return 0
|
|
fi
|
|
done
|
|
done
|
|
|
|
for block in "${@}"; do
|
|
block=${block}${SLOT}
|
|
device=$(find /dev \( -type b -o -type c -o -type l \) -maxdepth 1 -iname ${block} | head -n 1)
|
|
if [ -n "$device" ]; then
|
|
readlink -f "$device"
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
mount_partitions () {
|
|
DEVICE_AB=FALSE
|
|
VENDOR_COMPAT=FALSE
|
|
SYSTEM_AS_ROOT=FALSE
|
|
|
|
SLOT=$(grep_cmdline androidboot.slot_suffix)
|
|
if [ -z ${SLOT} ]; then
|
|
SLOT=$(grep_cmdline androidboot.slot)
|
|
[ -z ${SLOT} ] || SLOT=_${SLOT}
|
|
fi
|
|
[ -z ${SLOT} ] && DEVICE_AB=FALSE || DEVICE_AB=TR
|
|
|
|
SYSTEM_BLOCK=$(find_block system app)
|
|
VENDOR_BLOCK=$(find_block vendor vnr)
|
|
|
|
if ${BOOTMODE}; then
|
|
if [[ ! $(is_mounted /vendor) && -a /system/vendor ]]; then
|
|
VENDOR_COMPAT=TRUE
|
|
fi
|
|
|
|
SYSTEM_AS_ROOT=$(grep_prop ro.build.system_root_image)
|
|
else
|
|
is_mounted /data || mount /data || echo "failed to mount /data!"
|
|
|
|
mount -o bind /dev/urandom /dev/random
|
|
|
|
if is_mounted /system_root; then
|
|
umount /system 2&>/dev/null
|
|
umount /system_root 2&>/dev/null
|
|
fi
|
|
|
|
mkdir -p /system /system_root
|
|
mount -o rw ${SYSTEM_BLOCK} /system
|
|
|
|
if [ -f /system/build.prop ]; then
|
|
SYSTEM=/system
|
|
elif [ -f /system/system/build.prop -o -f /system/init -o -L /system/init ]; then
|
|
SYSTEM_AS_ROOT=true
|
|
SYSTEM=/system/system
|
|
if ! mount --move /system /system_root; then
|
|
umount /system
|
|
umount -l /system
|
|
mount -o rw ${SYSTEM_BLOCK} /system_root
|
|
fi
|
|
mount -o bind /system_root/system /system
|
|
fi
|
|
|
|
! is_mounted /vendor && mount -o ro /vendor
|
|
! is_mounted /vendor && mount -o ro ${VENDOR_BLOCK} /vendor
|
|
|
|
if [[ ! $(is_mounted /vendor) && -d /system/vendor ]]; then
|
|
### XXX work-around required for some devices
|
|
VENDOR_COMPAT=TRUE
|
|
ln -sf /system/vendor /vendor >/dev/null
|
|
fi
|
|
|
|
[ -d /system/apex ] && mount_apex
|
|
fi
|
|
|
|
[ ! -f /system/build.prop ] && error "failed to mount /system (unsupported A/B device?)"
|
|
|
|
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
|
|
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
|
|
export ANDROID_ART_ROOT=/apex/com.android.art
|
|
export ANDROID_I18N_ROOT=/apex/com.android.i18n
|
|
}
|
|
|
|
umount_partitions () {
|
|
umount -l /system_root 2>/dev/null
|
|
umount -l /system 2>/dev/null
|
|
umount -l /vendor 2>/dev/null
|
|
umount -l /dev/random 2>/dev/null
|
|
|
|
mount | awk '/ \/apex/{print $1 " " $3}' | while read apex_loop apex_mount; do
|
|
umount -l "${apex_mount}" 2>/dev/null
|
|
losetup -d "${apex_loop}" 2>/dev/null
|
|
done
|
|
|
|
rm -rf /apex
|
|
|
|
unset ANDROID_RUNTIME_ROOT
|
|
unset ANDROID_TZDATA_ROOT
|
|
unset ANDROID_ART_ROOT
|
|
unset ANDROID_I18N_ROOT
|
|
}
|
|
|
|
error () {
|
|
ui_print " "
|
|
ui_print " !! ${@}"
|
|
ui_print " "
|
|
|
|
${BOOTMODE} || umount_partitions
|
|
|
|
exit 1
|
|
}
|
|
|
|
##########################################################################################
|
|
# check if ROM has native fake signature spoofing support
|
|
# origingally by @ale5000 - revised by me
|
|
##########################################################################################
|
|
|
|
check_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')
|
|
PATCH_TYPE=""
|
|
FRAMEWORKRES_PATCH=false
|
|
SERVICESJAR_PATCH=false
|
|
|
|
mkdir -p ${TMPDIR}/sigcheck
|
|
|
|
# natively patched ROM: only framework-res.apk patched (old)
|
|
# natively patched ROM: both framework-res.apk and services.jar patched (new)
|
|
# self patched ROM: only services.jar patched
|
|
|
|
# check framework-res.apk for the patch
|
|
unzip -oq /system/framework/framework-res.apk -d "${TMPDIR}/sigcheck" \
|
|
|| error "failed to unpack framework-res.apk"
|
|
|
|
grep -qF "${PERMISSION}" "${TMPDIR}"/sigcheck/AndroidManifest.xml && FRAMEWORKRES_PATCH=true
|
|
od -A n -t x1 "${TMPDIR}"/sigcheck/AndroidManifest.xml | tr -d ' \n' | grep -qF "${PERMISSION_OD}" && FRAMEWORKRES_PATCH=true
|
|
|
|
# check services.jar for the patch
|
|
unzip -oq /system/framework/services.jar -d "${TMPDIR}/sigcheck" \
|
|
|| error "failed to unpack services.jar"
|
|
|
|
grep -qF "${PERMISSION}" "${TMPDIR}"/sigcheck/*.dex && SERVICESJAR_PATCH=true
|
|
od -A n -t x1 "${TMPDIR}"/sigcheck/*.dex | tr -d ' \n' | grep -qF "${PERMISSION_OD}" && SERVICESJAR_PATCH=true
|
|
|
|
# we don't use this anywhere (except in SysTest log),
|
|
# but may still come in hand in the future
|
|
if ${FRAMEWORKRES_PATCH} && ! ${SERVICESJAR_PATCH}; then
|
|
PATCH_TYPE="native_old"
|
|
elif ${FRAMEWORKRES_PATCH} && ${SERVICESJAR_PATCH}; then
|
|
PATCH_TYPE="native_new"
|
|
elif ! ${FRAMEWORKRES_PATCH} && ${SERVICESJAR_PATCH}; then
|
|
PATCH_TYPE="self_patched"
|
|
fi
|
|
|
|
[ -n "${PATCH_TYPE}" ] && return 0 || return 1
|
|
}
|
|
|
|
##########################################################################################
|
|
# Device Functions
|
|
##########################################################################################
|
|
|
|
detect_outfd () {
|
|
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
|
|
# We will have to manually find out OUTFD
|
|
for FD in `ls /proc/$$/fd`; do
|
|
if readlink /proc/$$/fd/$FD | grep -q pipe; then
|
|
if ps | grep -v grep | grep -q " 3 $FD "; then
|
|
OUTFD=$FD
|
|
break
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
detect_bootmode () {
|
|
[ -z ${BOOTMODE} ] && BOOTMODE=false
|
|
${BOOTMODE} || ps | grep zygote | grep -qv grep && BOOTMODE=true
|
|
${BOOTMODE} || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
|
|
}
|
|
|
|
grep_prop () {
|
|
sed -n "s/^${1}=//p" /system/build.prop ${2} | head -n 1
|
|
}
|
|
|
|
grep_cmdline() {
|
|
local REGEX="s/^${1}=//p"
|
|
sed -E 's/ +/\n/g' /proc/cmdline | \
|
|
sed -n "${REGEX}" 2>/dev/null
|
|
}
|
|
|
|
setup_busybox () {
|
|
case $(uname -m) in
|
|
arm* | aarch* ) local bb_arch=arm ;;
|
|
x86* ) local bb_arch=x86 ;;
|
|
* ) error "arch \"$(uname -m)\" is not supported"
|
|
esac
|
|
|
|
mkdir -p ${TMPDIR}/busybox
|
|
ln -s ${TMPDIR}/busybox.${bb_arch} ${TMPDIR}/busybox/busybox
|
|
|
|
chmod 0755 ${TMPDIR}/busybox.${bb_arch}
|
|
${TMPDIR}/busybox.${bb_arch} --install -s ${TMPDIR}/busybox/
|
|
|
|
OLD_PATH=${PATH}
|
|
export PATH=${TMPDIR}/busybox:/system/bin:/vendor/bin
|
|
}
|
|
|
|
system_test () {
|
|
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 )
|
|
FILE=${TMPDIR}/file.arm
|
|
AAPT=${TMPDIR}/aapt.arm
|
|
;;
|
|
x86 | x86_64 )
|
|
FILE=${TMPDIR}/file.x86
|
|
AAPT=${TMPDIR}/aapt.x86
|
|
;;
|
|
esac
|
|
|
|
chmod 0755 "${FILE}" "${AAPT}"
|
|
|
|
DALVIKVM_ARCH=$("${FILE}" -m "${BASEDIR}/magic.mgc" -L /system/bin/dalvikvm)
|
|
|
|
case ${DALVIKVM_ARCH} in
|
|
*32-bit* )
|
|
export LD_LIBRARY_PATH="/system/lib:/vendor/lib:/system/vendor/lib:/product/lib:/system/product/lib:${APEX_LD}"
|
|
;;
|
|
|
|
*64-bit* )
|
|
export LD_LIBRARY_PATH="/system/lib64:/vendor/lib64:/system/vendor/lib64:/product/lib64:/system/product/lib64:${APEX_LD_64}"
|
|
;;
|
|
esac
|
|
|
|
if [ -f ${ANDROID_RUNTIME_ROOT}/etc/ld.config.txt ]; then
|
|
export LD_CONFIG_FILE="${ANDROID_RUNTIME_ROOT}/etc/ld.config.txt"
|
|
elif [ -f ${ANDROID_RUNTIME_ROOT}/etc/ld.config.${SDK_VERSION}.txt ]; then
|
|
export LD_CONFIG_FILE="${ANDROID_RUNTIME_ROOT}/etc/ld.config.${SDK_VERSION}.txt"
|
|
fi
|
|
|
|
SERVICES_JAR_DEX=$(unzip -lq /system/framework/services.jar | grep classes.dex)
|
|
|
|
if [ -n "$(find '/system/framework/' -name 'services.vdex')" ]; then
|
|
ROM_DEX_STATUS=VDEX
|
|
elif [ -n "$(find '/system/framework/' -name 'services.odex')" ]; then
|
|
ROM_DEX_STATUS=ODEX
|
|
else ROM_DEX_STATUS=UNKOWN
|
|
fi
|
|
|
|
[ "${SERVICES_JAR_DEX}" ] && ROM_DEX_STATUS=DEODEX
|
|
}
|
|
|
|
add_log () {
|
|
echo "${@}" >> ${LOGFILE}
|
|
}
|
|
|
|
store_results () {
|
|
mkdir -p "$(dirname "${LOGFILE}")"
|
|
|
|
add_log "NanoDroid System Test Results"
|
|
add_log "============================="
|
|
add_log ""
|
|
|
|
add_log "CPU and ABI details"
|
|
add_log "==================="
|
|
add_log ""
|
|
add_log "ARCH=${ARCH}"
|
|
add_log "ABI=${ABI}"
|
|
add_log "ABI2=${ABI2}"
|
|
add_log "ABILONG=${ABILONG}"
|
|
|
|
add_log ""
|
|
add_log "Mounted Partitions"
|
|
add_log "=================="
|
|
add_log ""
|
|
add_log "DEVICE_AB=${DEVICE_AB}"
|
|
add_log "VENDOR_COMPAT=${VENDOR_COMPAT}"
|
|
add_log "SYSTEM_AS_ROOT=${SYSTEM_AS_ROOT}"
|
|
add_log "SYSTEM_BLOCK=${SYSTEM_BLOCK}"
|
|
add_log "VENDOR_BLOCK=${VENDOR_BLOCK}"
|
|
add_log "SLOT=${SLOT}"
|
|
add_log ""
|
|
mount | sed '/magisk/d' | awk '{print $1 " on " $3 " params: " $6}' >> ${LOGFILE}
|
|
|
|
if [ ! ${BOOTMODE} ]; then
|
|
add_log ""
|
|
add_log "TWRP usuable space for Installer"
|
|
add_log "================================"
|
|
add_log ""
|
|
add_log $(df /dev 2>/dev/null | awk '/tmpfs/{print $4}')
|
|
fi
|
|
|
|
add_log ""
|
|
add_log "DalvikVM, LD_LIBRARY_PATH and DEX status"
|
|
add_log "========================================"
|
|
add_log ""
|
|
add_log "DALVIKVM_BIN=${DALVIKVM_BIN}"
|
|
add_log "DALVIKVM_ARCH=${DALVIKVM_ARCH}"
|
|
add_log "LD_LIBRARY_PATH=${LD}"
|
|
add_log "LD_CONFIG_FILE=${LD_FILE}"
|
|
add_log "ROM_DEX_STATUS=${ROM_DEX_STATUS}"
|
|
|
|
if [ -d /system/apex ]; then
|
|
add_log ""
|
|
add_log "Loaded APEX modules"
|
|
add_log "==================="
|
|
add_log ""
|
|
|
|
i=0
|
|
|
|
for apex in /system/apex/*; do
|
|
i=$((i + 1))
|
|
add_log "[${i}] $(basename ${apex} .apex)"
|
|
done
|
|
fi
|
|
|
|
add_log ""
|
|
add_log "Generic System Properties"
|
|
add_log "========================="
|
|
add_log ""
|
|
add_log "build.prop files"
|
|
add_log ""
|
|
|
|
i=0
|
|
for prop in $(find /system /system_root /vendor -type f -name build.prop); do
|
|
i=$((i + 1))
|
|
add_log "[${i}] ${prop}"
|
|
done
|
|
|
|
add_log ""
|
|
add_log "system properties"
|
|
add_log ""
|
|
|
|
i=0
|
|
for prop in ro.build.description ro.build.display.id ro.build.flavor ro.build.product \
|
|
ro.build.tags ro.build.type ro.build.version.sdk ro.build.version.security_patch \
|
|
ro.product.cpu.abi ro.product.cpu.abilist ro.product.cpu.abilist32 \
|
|
ro.product.cpu.abilist64 ro.product.model ro.product.vendor.device; do
|
|
i=$((i + 1))
|
|
add_log "[${i}] ${prop}=$(grep_prop ${prop})"
|
|
done
|
|
|
|
add_log ""
|
|
add_log "Native Signature Spoofing support"
|
|
add_log "================================="
|
|
add_log ""
|
|
if check_fake_package_signature; then
|
|
add_log "NATIVE_SIGSPOOF=TRUE"
|
|
add_log "PATCH_TYPE=${PATCH_TYPE}"
|
|
else
|
|
add_log "NATIVE_SIGSPOOF=FALSE"
|
|
fi
|
|
|
|
add_log ""
|
|
add_log "Magisk installation status"
|
|
add_log "=========================="
|
|
add_log ""
|
|
if [ -f /data/adb/magisk/util_functions.sh ]; then
|
|
add_log "MAGISK=TRUE"
|
|
|
|
. /data/adb/magisk/util_functions.sh
|
|
add_log "MAGISK_VERSION=${MAGISK_VER_CODE}"
|
|
|
|
if [ ${MAGISK_VER_CODE} -gt 18100 ]; then
|
|
add_log "MAGISK_IMAGELESS=TRUE"
|
|
else add_log "MAGISK_IMAGELESS=FALSE"
|
|
fi
|
|
else
|
|
add_log "MAGISK=FALSE"
|
|
add_Log "MAGISK_VERSION=NONE"
|
|
add_log "MAGISK_IMAGELESS=FALSE"
|
|
fi
|
|
|
|
add_log ""
|
|
add_log "Installed Google packages"
|
|
add_log "=== packages.list ======="
|
|
add_log ""
|
|
grep google /data/system/packages.list | sort >> ${LOGFILE}
|
|
|
|
add_log ""
|
|
add_log "=== packages.xml ========"
|
|
add_log ""
|
|
grep 'package .*google' /data/system/packages.xml | sort >> ${LOGFILE}
|
|
|
|
add_log ""
|
|
add_log "Content of /system/app"
|
|
add_log "======================"
|
|
add_log ""
|
|
find /system/app -type f -name '*.apk' | sort >> ${LOGFILE}
|
|
|
|
add_log ""
|
|
add_log "Content of /system/priv-app"
|
|
add_log "==========================="
|
|
add_log ""
|
|
find /system/priv-app -type f -name '*.apk' | sort >> ${LOGFILE}
|
|
|
|
chown root:sdcard_rw ${LOGFILE}
|
|
chmod 0644 ${LOGFILE}
|
|
|
|
export PATH=${OLD_PATH}
|
|
}
|
|
|