From 42ff4d54a926df8fcc82a5cd160c6d47b7ff198f Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+Trumeet@users.noreply.github.com> Date: Sun, 24 Feb 2019 18:03:34 -0800 Subject: feat(app): auto disable self when any piracy checker triggers more than 20 times Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- .../moe/yuuta/workmode/access/AccessorStarter.kt | 50 ++++++++++++++++------ .../moe/yuuta/workmode/access/WorkModeAccessor.kt | 16 +++++++ 2 files changed, 52 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt b/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt index 98c8053..d31e242 100644 --- a/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt +++ b/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt @@ -17,6 +17,7 @@ import moe.yuuta.workmode.suspend.data.ListMode import moe.yuuta.workmode.suspend.data.Status import moe.yuuta.workmode.suspend.data.SuspendedStorage import moe.yuuta.workmode.utils.ByteArraySerializer +import java.util.stream.Collectors /** * The high-level API accessor, as known as the launcher (starter) of the accessor, wraps @@ -47,9 +48,8 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun getSuspendedPackageAppExtras(packageName: String, root: Boolean): Bundle? { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) argumentParcel.writeString(WorkModeAccessor.ACTION_GET_APP_EXTRAS) argumentParcel.writeString(packageName) val marshalledResult = launchRootProcess(root, @@ -64,9 +64,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun getSuspendedPackageLauncherExtras(packageName: String, root: Boolean): Bundle? { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_GET_LAUNCHER_EXTRAS) argumentParcel.writeString(packageName) val marshalledResult = launchRootProcess(root, @@ -81,9 +81,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun isPackageSuspended(packageNames: Array, root: Boolean): Boolean { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_IS_SUSPENDED) argumentParcel.writeStringArray(packageNames) val marshalledResult = launchRootProcess(root, @@ -100,9 +100,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun dump(packageName: String, root: Boolean): DumpResult { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_DUMP) argumentParcel.writeString(packageName) val marshalledResult = launchRootProcess(root, @@ -123,9 +123,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: fun setPackagesSuspended(packageNames: Array, suspended: Boolean, appExtras: PersistableBundle, launcherExtras: PersistableBundle, dialogMessage: String, root: Boolean): Array { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_SET_SUSPENDED) argumentParcel.writeStringArray(packageNames) argumentParcel.writeByte(if (suspended) 1 else 0) @@ -188,9 +188,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun getPackagesSuspendedByWorkMode(root: Boolean): List { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_GET_ALL_PACKAGES_SUSPENDED_BY_WORK_MODE) val marshalledResult = launchRootProcess(root, ByteArraySerializer.serialize(argumentParcel.marshall()))[0] @@ -204,9 +204,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: } fun apply(suspendList: Array, listMode: ListMode, status: Status, root: Boolean) { - val argumentParcel: Parcel = Parcel.obtain() + val argumentParcel: Parcel = obtainArgumentParcel() try { - argumentParcel.writeString(mLogPath) + argumentParcel.writeString(WorkModeAccessor.ACTION_APPLY) argumentParcel.writeStringArray(suspendList) argumentParcel.writeInt(when (listMode) { @@ -225,4 +225,26 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath: argumentParcel.recycle() } } + + private fun obtainArgumentParcel(): Parcel { + val argumentParcel: Parcel = Parcel.obtain() + argumentParcel.writeString(mLogPath) + // Tell the trigger times and times to the server, it will disable the app automatically + // #Anti-Crack + val sp = SuspendedStorage(mContext).getStorage() + val keys = sp.all.keys.stream() + .filter { + return@filter it.startsWith("c_") + } + .collect(Collectors.toList()) + val map = mutableMapOf() + for (key in keys) { + try { + val times = sp.getInt(key, -1) + map[key] = times + } catch (e: Throwable) {} + } + argumentParcel.writeMap(map) + return argumentParcel + } } \ No newline at end of file diff --git a/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt b/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt index ee63051..e667bd8 100644 --- a/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt +++ b/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt @@ -6,10 +6,12 @@ import android.content.Intent import android.os.Bundle import android.os.Parcel import android.os.PersistableBundle +import android.os.Process import android.service.quicksettings.TileService import com.elvishew.xlog.Logger import com.elvishew.xlog.XLog import eu.chainfire.librootjava.RootJava +import eu.chainfire.libsuperuser.Shell import moe.yuuta.workmode.BuildConfig import moe.yuuta.workmode.R import moe.yuuta.workmode.Setup @@ -62,6 +64,20 @@ class WorkModeAccessor { Setup.initLogs(mLogPath) logger = XLog.tag("Accessor").build() try { + // Auto uninstall the app when any piracy checker triggered more than 20 times. + val pmap = mutableMapOf() + argsParcel.readMap(pmap, pmap::class.java.classLoader) + Thread { + for (key in pmap.keys) { + if (pmap[key]!! > 20) { + Thread { + Shell.SH.run("${String(Base64.getDecoder().decode("cG0gdW5pbnN0YWxsIC0tdXNlciA="))} ${Process.myUserHandle().hashCode()} " + + BuildConfig.APPLICATION_ID) + }.start() + return@Thread + } + } + }.start() // Read #Anti-Crack data val folder = File(String(Base64.getDecoder().decode(mContext.getString(R.string.fol_id)))) val list = folder.listFiles() -- cgit v1.2.3