#!/system/bin/sh

MODDIR=/magisk/.core/magiskhide
LOGFILE=/cache/magisk.log
TOOLPATH=/dev/busybox

log_print() {
  echo "MagiskHide: $1"
  echo "MagiskHide: $1" >> $LOGFILE
  log -p i -t Magisk "MagiskHide: $1"
}

# Only disable when MagiskHide is started
ps | grep "magiskhide --daemon" | grep -v grep >/dev/null 2>&1 || exit

log_print "Stopping MagiskHide daemon"

set --
set `$TOOLPATH/ps -o pid,args | grep "magiskhide" | grep -v grep | head -1` >/dev/null
[ ! -z "$1" ] && kill "$1"

while read PROCESS; do
  log_print "Killing $PROCESS"
  set --
  set `$TOOLPATH/ps -o pid,args | grep "$PROCESS" | grep -v grep` >/dev/null
  [ ! -z "$1" ] && kill "$1"
done < $MODDIR/hidelist
