2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-11-07 15:20:36 +00:00
NanoDroid/systest/SysTest

321 lines
8.2 KiB
Plaintext
Raw Normal View History

2018-11-18 09:16:24 +00:00
#!/sbin/sh
##########################################################################################
#
# NanoDroid System Testing Script
# by Nanolx
#
##########################################################################################
TMPDIR=/dev/tmp
2018-11-18 09:16:24 +00:00
LOGFILE=/sdcard/NanoDroid-SysTest.log
rm -f ${LOGFILE}
##########################################################################################
# Generic Functions
##########################################################################################
ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}
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 () {
SLOT=$(grep_cmdline androidboot.slot_suffix)
if [ -z ${SLOT} ]; then
SLOT=_$(grep_cmdline androidboot.slot)
[ "${SLOT}" = "_" ] && SLOT=
fi
DEVICE_AB=FALSE
2018-12-28 21:24:12 +00:00
VENDOR_COMPAT=FALSE
2018-11-18 09:16:24 +00:00
is_mounted /data || mount /data || error "failed to mount /data!"
mount -o bind /dev/urandom /dev/random
! is_mounted /system && mount -o rw /system
if [ ! -f /system/build.prop ]; then
DEVICE_AB=TRUE
SYSTEMBLOCK=$(find /dev/block -iname system${SLOT} | head -n 1)
mount -t ext4 -o rw ${SYSTEMBLOCK} /system
fi
[ -f /system/build.prop ] || is_mounted /system || error "failed to mount /system (unsupported A/B device?)"
if [ -f /system/init ]; then
mkdir /system_root 2>/dev/null
mount --move /system /system_root
mount -o bind /system_root/system /system
fi
[ ! -f /system/build.prop ] && error "failed to mount /system (unsupported A/B device?)"
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
elif [ -d /system/vendor ]; then
### XXX work-around required for some ROMs
2018-12-28 21:24:12 +00:00
VENDOR_COMPAT=TRUE
2018-11-18 09:16:24 +00:00
ln -sf /system/vendor /vendor >/dev/null
fi
}
error () {
ui_print " "
ui_print " !! ${@}"
ui_print " "
exit 1
}
##########################################################################################
# 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"
mkdir -p "${FW_RES_DIR}"
unzip -o /system/framework/framework-res.apk -d "${FW_RES_DIR}"
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-11-18 09:16:24 +00:00
##########################################################################################
# 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
${BOOTMODE} && error " Run from TWRP!"
}
grep_prop() {
[ -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-11-18 09:16:24 +00:00
}
grep_cmdline() {
local REGEX="s/^${1}=//p"
sed -E 's/ +/\n/g' /proc/cmdline | \
sed -n "${REGEX}" 2>/dev/null
}
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 )
BB=${TMPDIR}/busybox.arm
FILE=${TMPDIR}/file.arm
2018-11-18 09:16:24 +00:00
;;
x86 | x86_64 )
BB=${TMPDIR}/busybox.x86
FILE=${TMPDIR}/file.x86
2018-11-18 09:16:24 +00:00
;;
esac
OLD_PATH=${PATH}
mkdir -p ${TMPDIR}/busybox
2018-12-28 21:31:40 +00:00
ln -s ${BB} ${TMPDIR}/busybox/busybox
2018-12-28 21:31:40 +00:00
chmod 0755 ${BB}
${BB} --install -s ${TMPDIR}/busybox/
export PATH="${TMPDIR}/busybox:${PATH}"
2018-11-18 09:16:24 +00:00
chmod 0755 "${FILE}"
DALVIKVM_BIN=$(ls -l /system/bin/dalvikvm | awk '{print $NF}')
DALVIKVM_ARCH=$("${FILE}" -m "${TMPDIR}/magic.mgc" -L /system/bin/dalvikvm)
2018-11-18 09:16:24 +00:00
case ${DALVIKVM_BIN} in
dalvikvm32 )
LD="/system/lib:/vendor/lib:/system/vendor/lib"
;;
dalvikvm64 )
LD="/system/lib64:/vendor/lib64:/system/vendor/lib64"
;;
2018-11-18 09:16:24 +00:00
dalvikvm )
case ${DALVIKVM_ARCH} in
*32-bit* )
LD="/system/lib:/vendor/lib:/system/vendor/lib"
;;
*64-bit* )
LD="/system/lib64:/vendor/lib64:/system/vendor/lib64"
;;
esac
;;
esac
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
2018-11-19 17:49:25 +00:00
}
2018-11-18 09:16:24 +00:00
2018-11-19 17:49:25 +00:00
add_log () {
echo "${@}" >> ${LOGFILE}
}
2018-11-18 09:16:24 +00:00
2018-11-19 17:49:25 +00:00
store_results () {
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}"
2018-12-28 21:24:12 +00:00
add_log "VENDOR_COMPAT=${VENDOR_COMPAT}"
2018-12-28 21:25:39 +00:00
add_log ""
2019-01-12 09:04:51 +00:00
mount | awk '{print $1 " on " $3 " params: " $6}' >> ${LOGFILE}
2018-11-19 17:49:25 +00:00
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}"
2018-11-19 18:00:49 +00:00
add_log "LD_LIBRARY_PATH=${LD}"
2018-11-19 17:49:25 +00:00
add_log "ROM_DEX_STATUS=${ROM_DEX_STATUS}"
add_log ""
add_log "Generic System Properties"
add_log "========================="
add_log ""
2018-11-18 09:16:24 +00:00
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
2018-11-19 17:49:25 +00:00
add_log "${prop}=$(grep_prop ${prop})"
2018-11-18 09:16:24 +00:00
done
add_log ""
add_log "Native SigSpoof?"
add_log "================"
add_log ""
search_fake_package_signature && add_log "NATIVE_SIGSPOOF=TRUE" || add_log "NATIVE_SIGSPOOF=FALSE"
2018-11-19 17:49:25 +00:00
add_log ""
add_log "Magisk installed?"
add_log "================="
add_log ""
[ -f /data/adb/magisk.img -o -f /data/magisk.img ] && add_log "MAGISK=TRUE" || add_log "MAGISK=FALSE"
2018-11-18 09:16:24 +00:00
2018-11-19 17:49:25 +00:00
add_log ""
add_log "Installed Google packages"
add_log "=== packages.list ======="
add_log ""
2018-11-18 09:16:24 +00:00
grep google /data/system/packages.list >> ${LOGFILE}
2018-11-19 17:49:25 +00:00
add_log ""
add_log "=== packages.xml ========"
add_log ""
2018-11-18 09:16:24 +00:00
grep 'package .*google' /data/system/packages.xml >> ${LOGFILE}
2018-11-19 17:49:25 +00:00
add_log ""
add_log "Content of /system/app"
add_log "======================"
add_log ""
2018-11-19 18:03:11 +00:00
find /system/app -type f -name '*.apk' >> ${LOGFILE}
2018-11-19 17:49:25 +00:00
add_log ""
add_log "Content of /system/priv-app"
add_log "======================"
add_log ""
2018-11-19 18:03:11 +00:00
find /system/priv-app -type f -name '*.apk' >> ${LOGFILE}
2018-12-28 21:33:06 +00:00
export PATH=${OLD_PATH}
2018-11-18 09:16:24 +00:00
}