#!/bin/bash
[ $(id -u) != 0 ] && exit 1
exec 2>/dev/null
SO=/data/local/tmp/libMoBai.so
INJ=/data/local/tmp/inject
PKG=com.tencent.tiyan.KiHan
[ ! -f "$SO" ] || [ ! -f "$INJ" ] && exit 1
chmod 755 "$SO"; chmod 777 "$INJ"
pidof $PKG >/dev/null || su -c "monkey -p $PKG -c android.intent.category.LAUNCHER 1" >/dev/null 2>&1
until pidof $PKG >/dev/null; do sleep 1; done
PID=$(pidof $PKG)
while ! su -c "cat /proc/$PID/maps" | grep -q "$SO"; do
  su -c "$INJ -p $PID -so $SO" >/dev/null 2>&1
  sleep 2
done
while true; do
  PID=$(pidof $PKG)
  [ -z "$PID" ] && break
  su -c "cat /proc/$PID/maps" | grep -q "$SO" || su -c "$INJ -p $PID -so $SO" >/dev/null 2>&1
  sleep 3
done