Proper vendor support

This commit is contained in:
topjohnwu 2017-01-02 17:48:34 +08:00
parent 94a861e318
commit b4cfe6e9c0
2 changed files with 31 additions and 7 deletions

View File

@ -42,7 +42,7 @@ int hideMagisk() {
// First unmount the dummy skeletons and the cache mounts // First unmount the dummy skeletons and the cache mounts
for(i = mount_size - 1; i >= 0; --i) { for(i = mount_size - 1; i >= 0; --i) {
if (strstr(mount_list[i], "tmpfs /system") || strstr(mount_list[i], "tmpfs /vendor/") if (strstr(mount_list[i], "tmpfs /system") || strstr(mount_list[i], "tmpfs /vendor")
|| (strstr(mount_list[i], cache_block) && strstr(mount_list[i], "/system")) ) { || (strstr(mount_list[i], cache_block) && strstr(mount_list[i], "/system")) ) {
sscanf(mount_list[i], "%*s %512s", buffer); sscanf(mount_list[i], "%*s %512s", buffer);
lazy_unmount(buffer); lazy_unmount(buffer);

View File

@ -2,7 +2,8 @@
LOGFILE=/cache/magisk.log LOGFILE=/cache/magisk.log
IMG=/data/magisk.img IMG=/data/magisk.img
BLACKLIST="/system/lib /system/lib64 /system/etc /vendor/lib /vendor/lib64" # BLACKLIST="/system/lib /system/lib64 /system/etc /system/framework /vendor/lib /vendor/lib64"
WHITELIST="/system/app /system/priv-app /system/bin"
MOUNTPOINT=/magisk MOUNTPOINT=/magisk
@ -81,6 +82,9 @@ target_size_check() {
} }
travel() { travel() {
# Ignore /system/vendor, we will handle it differently
[ "$1" = "system/vendor" ] && return
cd $TRAVEL_ROOT/$1 cd $TRAVEL_ROOT/$1
if [ -f .replace ]; then if [ -f .replace ]; then
rm -rf $MOUNTINFO/$1 rm -rf $MOUNTINFO/$1
@ -121,8 +125,8 @@ travel() {
} }
clone_dummy() { clone_dummy() {
LINK=true LINK=false
in_list $1 "$BLACKLIST" && LINK=false in_list $1 "$WHITELIST" && LINK=true
for ITEM in $MIRRDIR$1/* ; do for ITEM in $MIRRDIR$1/* ; do
REAL=${ITEM#$MIRRDIR} REAL=${ITEM#$MIRRDIR}
@ -353,11 +357,23 @@ case $1 in
# Remove crap folder # Remove crap folder
rm -rf $MOUNTPOINT/lost+found rm -rf $MOUNTPOINT/lost+found
# Link vendor if not exist
if [ ! -e /vendor ]; then
mount -o rw,remount rootfs /
ln -s /system/vendor /vendor
mount -o ro,remount rootfs /
fi
# Travel through all mods # Travel through all mods
for MOD in $MOUNTPOINT/* ; do for MOD in $MOUNTPOINT/* ; do
if [ -f $MOD/auto_mount -a -d $MOD/system -a ! -f $MOD/disable ]; then if [ -f $MOD/auto_mount -a -d $MOD/system -a ! -f $MOD/disable ]; then
TRAVEL_ROOT=$MOD TRAVEL_ROOT=$MOD
(travel system) (travel system)
rm -f $MOD/vendor 2>/dev/null
if [ -d $MOD/system/vendor ]; then
ln -s $MOD/system/vendor $MOD/vendor
(travel vendor)
fi
fi fi
done done
@ -384,13 +400,13 @@ case $1 in
ln -s $MIRRDIR/system/vendor $MIRRDIR/vendor ln -s $MIRRDIR/system/vendor $MIRRDIR/vendor
fi fi
# Since mirrors always exist, we load libraries from mirrors # Since mirrors always exist, we load libraries and binaries from mirrors
export LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib export LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib
[ -d /system/lib64 ] && export LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64 [ -d $MIRRDIR/system/lib64 ] && export LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64
# Stage 2 # Stage 2
log_print "* Stage 2: Mount dummy skeletons" log_print "* Stage 2: Mount dummy skeletons"
# Move dummy /system/vendor to /vendor for consistency # Move /system/vendor to /vendor for consistency
mv -f $MOUNTINFO/dummy/system/vendor $MOUNTINFO/dummy/vendor 2>/dev/null mv -f $MOUNTINFO/dummy/system/vendor $MOUNTINFO/dummy/vendor 2>/dev/null
mv -f $DUMMDIR/system/vendor $DUMMDIR/vendor 2>/dev/null mv -f $DUMMDIR/system/vendor $DUMMDIR/vendor 2>/dev/null
find $MOUNTINFO/dummy -type f 2>/dev/null | while read ITEM ; do find $MOUNTINFO/dummy -type f 2>/dev/null | while read ITEM ; do
@ -400,6 +416,9 @@ case $1 in
bind_mount $ORIG $TARGET bind_mount $ORIG $TARGET
done done
# Check if the dummy /system/bin is empty, it shouldn't
[ ! -e $DUMMDIR/system/bin/sh ] && clone_dummy /system/bin
# Stage 3 # Stage 3
log_print "* Stage 3: Mount module items" log_print "* Stage 3: Mount module items"
find $MOUNTINFO/system -type f 2>/dev/null | while read ITEM ; do find $MOUNTINFO/system -type f 2>/dev/null | while read ITEM ; do
@ -407,6 +426,11 @@ case $1 in
ORIG=`cat $ITEM`$TARGET ORIG=`cat $ITEM`$TARGET
bind_mount $ORIG $TARGET bind_mount $ORIG $TARGET
done done
find $MOUNTINFO/vendor -type f 2>/dev/null | while read ITEM ; do
TARGET=${ITEM#$MOUNTINFO}
ORIG=`cat $ITEM`$TARGET
bind_mount $ORIG $TARGET
done
# Stage 4 # Stage 4
log_print "* Stage 4: Execute module scripts" log_print "* Stage 4: Execute module scripts"