Skip to content

Commit

Permalink
Reworked hiding method to mount real ext4 filesystem instead of bindi…
Browse files Browse the repository at this point in the history
…ng files from a directory. Note: Clear the module environment before updating to releases with this commit included
  • Loading branch information
rmnscnce committed Aug 24, 2020
1 parent a08c3ba commit 36accd2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
94 changes: 88 additions & 6 deletions common/hsu_functions
Expand Up @@ -49,9 +49,61 @@ oobecheck () {
oobeprompt
fi
}

# Environment initializer
# Environment initializer REWORKED
initenv () {
menuheader "Environment initialization"
mkdir -p "$ENVPATH"
if [ -d "$ENVPATH" ] ; then
echo -e "\nEnvironment initialized. Initializing mirror image..."
initenv_img
else
echo -e "\nAn error occured while initializing environment. Exiting...\n"
echo -e "$LINEDIV"
exit 1
fi
}
# Environment initializer - imager
initenv_img () {
mkdir -p $HSUFSPATH/images
dd if=/dev/zero of=$HSUFSPATH/images/sbin.img bs=4096 count=32768
mkfs.ext4 $HSUFSPATH/images/sbin.img
mkdir -p $HSUFSPATH/images/mirrors
tar -ch --exclude=*magisk* --exclude=*su* --exclude=resetprop /sbin/. | tar -x -C $HSUFSPATH/images/mirrors/
if [ "$SESTAT" = 0 ] ; then
mkdir -p $HSUFSPATH/images/mount_sbin
mount -t ext4 -o rw $HSUFSPATH/images/sbin.img $HSUFSPATH/images/sbin_mount
tar -ch -C $HSUFSPATH/images/mirrors/sbin/ . | tar -x -C $HSUFSPATH/images/mount_sbin/
umount $HSUFSPATH/images/mount_sbin
echo -e "\nSuccessfully initialized mirror image. Returning to main menu..."
oobecheck
elif [ "$SESTAT" = 1 ] ; then
setenforce 0
mkdir -p $HSUFSPATH/images/mount_sbin
mount -t ext4 -o rw $HSUFSPATH/images/sbin.img $HSUFSPATH/images/sbin_mount
tar -ch -C $HSUFSPATH/images/mirrors/sbin/ . | tar -x -C $HSUFSPATH/images/mount_sbin/
umount $HSUFSPATH/images/mount_sbin
setenforce 1
echo -e "\nSuccessfully initialized mirror image. Returning to main menu..."
oobecheck
else
echo -e "\nInvalid SELinux status. Exiting..."
exit 1
fi
}

# SELinux status readback
selinux_stat () {
if [ "$(getenforce)" = "Enforcing" ] ; then
SESTAT="1"
elif [ "$(getenforce)" = "Permissive" ] ; then
SESTAT="0"
else
SESTAT="ERROR"
fi
}

# Old Environment initializer
old_initenv () {
menuheader "Environment initialization"
mkdir -p "$ENVPATH"
if [ -d "$ENVPATH" ]; then
Expand All @@ -74,15 +126,15 @@ initenv () {

# Root and magisk hide
hideroot () {
if [ -d $HSUFSPATH/sbin ]; then
if [ -e $HSUFSPATH/images/sbin.img ]; then
hideroot_exec
else
echo -e "Environment not initialized yet! Please do so by starting hsu without any arguments."
echo -e "Environment not initialized (properly) yet! Please do so by starting hsu without any arguments."
exit 1
fi
}
# Execute instructions
hideroot_exec () {
old_hideroot_exec () {
menuheader "Magisk and root hide\n\nThis does disable and hide Magisk and root until interrupted\n$LINEDIV\nWarning! If the shell session got abruptly terminated (which is really rare to happen), you will have to do a reboot to re-enable Magisk and root."
echo -e "\nInitializing Magisk and root hide..."
mount $HSUFSPATH/sbin /sbin
Expand All @@ -95,7 +147,37 @@ hideroot () {
read -rsn 1
oobecheck
}

# Execute instructions REWORK
hideroot_exec () {
menuheader "Magisk and root hide\n\nThis does disable and hide Magisk and root until interrupted\n$LINEDIV\nWarning! If the shell session got abruptly terminated (which is really rare to happen), you will have to do a reboot to re-enable Magisk and root."
echo -e "\nInitializing Magisk and root hide..."
if [ "$SESTAT" = 0 ] ; then
mount -t ext4 -o r $HSUFSPATH/images/sbin.img /sbin
echo -e "\nMagisk and root hide started."
echo -e "\nInput any key to interrupt and stop"
read -rsn 1
umount /sbin
menuheader "Magisk and root hide\n\nThis does disable and hide Magisk and root until interrupted\n$LINEDIV\nWarning! If the shell session got abruptly terminated (which is really rare to happen), you will have to do a reboot to re-enable Magisk and root."
echo -e "\nMagisk and root hide was interrupted and stopped.\n\nInput any key to return to main menu"
read -rsn 1
oobecheck
elif [ "$SESTAT" = 1 ] ; then
setenforce 0
mount -t ext4 -o r $HSUFSPATH/images/sbin.img /sbin
echo -e "\nMagisk and root hide started."
echo -e "\nInput any key to interrupt and stop"
read -rsn 1
umount /sbin
setenforce 1
menuheader "Magisk and root hide\n\nThis does disable and hide Magisk and root until interrupted\n$LINEDIV\nWarning! If the shell session got abruptly terminated (which is really rare to happen), you will have to do a reboot to re-enable Magisk and root."
echo -e "\nMagisk and root hide was interrupted and stopped.\n\nInput any key to return to main menu"
read -rsn 1
oobecheck
else
echo -e "\nInvalid SELinux status. Exiting..."
exit 1
fi
}
# Clear module environment
clearenv () {
menuheader "Clear module environment\n\nThis will clear the environment used by the module to hide Magisk and root. Recommended to do if you just updated this device."
Expand Down
2 changes: 1 addition & 1 deletion module.prop
@@ -1,7 +1,7 @@
id=hsu
name=hsu - Magisk and root hide
version=PRERELEASE
versionCode=17
versionCode=18
author=rmnscnce (xaedoplay@XDA)
description=Hide Magisk and root system-wide to prevent any kinds of detection
#TODO support=
2 changes: 2 additions & 0 deletions system/bin/hsu
Expand Up @@ -76,6 +76,8 @@ oobeprompt () {

# Start the module

selinux_stat # Read initial SELinux status to "SESTAT"

if [ "$(readlink /proc/self/ns/mnt)" != "$(readlink /proc/1/ns/mnt)" ] ; then # Rerun module if not running on global mount namespace mode
exec su -M -c hsu $1 #
elif [ "$1" = "hide" ] ; then # Check if an argument is passed through
Expand Down

0 comments on commit 36accd2

Please sign in to comment.