Code to check whether device is rooted or not
Utility methods to check whether device is rooted? or contains magisk and exposed modules etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
class a { | |
static final String[] f56685a = {"com.noshufou.android.su", "com.noshufou.android.su.elite", "eu.chainfire.supersu", "com.koushikdutta.superuser", "com.thirdparty.superuser", "com.yellowes.su", "com.topjohnwu.magisk", "com.kingroot.kinguser", "com.kingo.root", "com.smedialink.oneclickroot", "com.zhiqupk.root.global", "com.alephzain.framaroot"}; | |
public static final String[] f56686b = {"com.koushikdutta.rommanager", "com.koushikdutta.rommanager.license", "com.dimonvideo.luckypatcher", "com.chelpus.lackypatch", "com.ramdroid.appquarantine", "com.ramdroid.appquarantinepro", "com.android.vending.billing.InAppBillingService.COIN", "com.android.vending.billing.InAppBillingService.LUCK", "com.chelpus.luckypatcher", "com.blackmartalpha", "org.blackmart.market", "com.allinone.free", "com.repodroid.app", "org.creeplays.hack", "com.baseappfull.fwd", "com.zmapp", "com.dv.marketmod.installer", "org.mobilism.android", "com.android.wp.net.log", "com.android.camera.update", "cc.madkite.freedom", "com.solohsu.android.edxp.manager", "org.meowcat.edxposed.manager", "com.xmodgame", "com.cih.game_cih", "com.charles.lpoqasert", "catch_.me_.if_.you_.can_"}; | |
public static final String[] f56687c = {"com.devadvance.rootcloak", "com.devadvance.rootcloakplus", "de.robv.android.xposed.installer", "com.saurik.substrate", "com.zachspong.temprootremovejb", "com.amphoras.hidemyroot", "com.amphoras.hidemyrootadfree", "com.formyhm.hiderootPremium", "com.formyhm.hideroot"}; | |
private static final String[] f56688d = {"/data/local/", "/data/local/bin/", "/data/local/xbin/", "/sbin/", "/su/bin/", "/system/bin/", "/system/bin/.ext/", "/system/bin/failsafe/", "/system/sd/xbin/", "/system/usr/we-need-root/", "/system/xbin/", "/cache/", "/data/", "/dev/"}; | |
static final String[] f56689e = {"/system", "/system/bin", "/system/sbin", "/system/xbin", "/vendor/bin", "/sbin", "/etc"}; | |
public static String[] a() { | |
ArrayList arrayList = new ArrayList(Arrays.asList(f56688d)); | |
String str = System.getenv("PATH"); | |
if (str == null || "".equals(str)) { | |
return (String[]) arrayList.toArray(new String[0]); | |
} | |
String[] split = str.split(":"); | |
int length = split.length; | |
for (int i11 = 0; i11 < length; i11++) { | |
String str2 = split[i11]; | |
if (!str2.endsWith("/")) { | |
str2 = str2 + '/'; | |
} | |
if (!arrayList.contains(str2)) { | |
arrayList.add(str2); | |
} | |
} | |
return (String[]) arrayList.toArray(new String[0]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.pm.PackageManager; | |
import android.os.Build; | |
import com.google.android.exoplayer2.metadata.icy.IcyHeaders; | |
import com.scottyab.rootbeer.RootBeerNative; | |
import android.content.Context; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.NoSuchElementException; | |
import java.util.Scanner; | |
public class b { | |
private final Context f56690a; | |
private boolean f56691b = true; | |
public b(Context context) { | |
this.f56690a = context; | |
} | |
private boolean m(List<String> list) { | |
PackageManager packageManager = this.f56690a.getPackageManager(); | |
boolean z11 = false; | |
for (String str : list) { | |
try { | |
packageManager.getPackageInfo(str, 0); | |
c.b(str + " ROOT management app detected!"); | |
z11 = true; | |
} catch (PackageManager.NameNotFoundException unused) { | |
} | |
} | |
return z11; | |
} | |
private String[] p() { | |
try { | |
InputStream inputStream = Runtime.getRuntime().exec("mount").getInputStream(); | |
if (inputStream == null) { | |
return null; | |
} | |
return new Scanner(inputStream).useDelimiter("\\A").next().split("\n"); | |
} catch (IOException | NoSuchElementException e11) { | |
c.a(e11); | |
return null; | |
} | |
} | |
private String[] q() { | |
try { | |
InputStream inputStream = Runtime.getRuntime().exec("getprop").getInputStream(); | |
if (inputStream == null) { | |
return null; | |
} | |
return new Scanner(inputStream).useDelimiter("\\A").next().split("\n"); | |
} catch (IOException | NoSuchElementException e11) { | |
//az.a.a(e11); | |
c.e(); | |
return null; | |
} | |
} | |
public boolean a() { | |
//return new RootBeerNative().a(); | |
return false; | |
} | |
public boolean b(String str) { | |
String[] a11; | |
boolean z11 = false; | |
for (String str2 : a.a()) { | |
String str3 = str2 + str; | |
if (new File(str2, str).exists()) { | |
//az.a.f(str3 + " binary detected!"); | |
c.f(str3 + " binary detected!"); | |
z11 = true; | |
} | |
} | |
return z11; | |
} | |
public boolean c() { | |
HashMap hashMap = new HashMap(); | |
hashMap.put("ro.debuggable", IcyHeaders.REQUEST_HEADER_ENABLE_METADATA_VALUE); | |
// hashMap.put("ro.secure", SessionDescription.SUPPORTED_SDP_VERSION); | |
// hashMap.put("ro.secure", SessionDescription.SUPPORTED_SDP_VERSION); | |
String[] q11 = q(); | |
if (q11 == null) { | |
return false; | |
} | |
boolean z11 = false; | |
for (String str : q11) { | |
for (Object str2 : hashMap.keySet()) { | |
if (str.contains((CharSequence) str2)) { | |
String str3 = "[" + ((String) hashMap.get(str2)) + "]"; | |
if (str.contains(str3)) { | |
//az.a.f(str2 + " = " + str3 + " detected!"); | |
c.f(str2 + " = " + str3 + " detected!"); | |
z11 = true; | |
} | |
} | |
} | |
} | |
return z11; | |
} | |
public boolean d() { | |
return b("magisk"); | |
} | |
public boolean e() { | |
String[] p11 = p(); | |
int i11 = 0; | |
if (p11 == null) { | |
return false; | |
} | |
int length = p11.length; | |
int i12 = 0; | |
boolean z11 = false; | |
while (i12 < length) { | |
String str = p11[i12]; | |
String[] split = str.split(" "); | |
if (split.length < 6) { | |
//az.a.b("Error formatting mount line: " + str); | |
c.b("Error formatting mount line: " + str); | |
} else { | |
String str2 = split[2]; | |
String str3 = split[5]; | |
String[] strArr = a.f56689e; | |
int length2 = strArr.length; | |
int i13 = i11; | |
while (i13 < length2) { | |
String str4 = strArr[i13]; | |
if (str2.equalsIgnoreCase(str4)) { | |
str3 = str3.replace("(", "").replace(")", ""); | |
String[] split2 = str3.split(","); | |
int length3 = split2.length; | |
int i14 = i11; | |
while (true) { | |
if (i14 >= length3) { | |
break; | |
} else if (split2[i14].equalsIgnoreCase("rw")) { | |
c.f(str4 + " path is mounted with rw permissions! " + str); | |
z11 = true; | |
break; | |
} else { | |
i14++; | |
} | |
} | |
} | |
i13++; | |
i11 = 0; | |
} | |
} | |
i12++; | |
i11 = 0; | |
} | |
return z11; | |
} | |
public boolean f() { | |
String[] a11 = new String[0]; | |
if (!a()) { | |
// az.a.b("We could not load the native library to test for root"); | |
c.b("We could not load the native library to test for root"); | |
return false; | |
} | |
int length = a.a().length; | |
String[] strArr = new String[length]; | |
for (int i11 = 0; i11 < length; i11++) { | |
strArr[i11] = a11[i11] + "su"; | |
} | |
RootBeerNative rootBeerNative = new RootBeerNative(); | |
try { | |
rootBeerNative.setLogDebugMessages(this.f56691b); | |
return rootBeerNative.checkForRoot(strArr) > 0; | |
} catch (UnsatisfiedLinkError unused) { | |
return false; | |
} | |
} | |
public boolean g() { | |
Process process = null; | |
try { | |
process = Runtime.getRuntime().exec(new String[]{"which", "su"}); | |
boolean z11 = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine() != null; | |
process.destroy(); | |
return z11; | |
} catch (Throwable unused) { | |
if (process != null) { | |
process.destroy(); | |
} | |
return false; | |
} | |
} | |
public boolean h() { | |
return i(null); | |
} | |
public boolean i(String[] strArr) { | |
ArrayList arrayList = new ArrayList(); | |
arrayList.addAll(Arrays.asList(a.f56686b)); | |
if (strArr != null && strArr.length > 0) { | |
arrayList.addAll(Arrays.asList(strArr)); | |
} | |
return m(arrayList); | |
} | |
public boolean j() { | |
return k(null); | |
} | |
public boolean k(String[] strArr) { | |
ArrayList arrayList = new ArrayList(Arrays.asList(a.f56685a)); | |
if (strArr != null && strArr.length > 0) { | |
arrayList.addAll(Arrays.asList(strArr)); | |
} | |
return m(arrayList); | |
} | |
public boolean l() { | |
String str = Build.TAGS; | |
return str != null && str.contains("test-keys"); | |
} | |
public boolean n() { | |
return j() || h() || b("su") || c() || e() || l() || g() || f() || d(); | |
} | |
@Deprecated | |
public boolean o() { | |
return n(); | |
} | |
public void r(boolean z11) { | |
this.f56691b = z11; | |
c.f6954a = z11 ? 5 : 0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
public class c { | |
public static int f6954a = 5; | |
public static void a(Exception exc) { | |
if (d()) { | |
exc.printStackTrace(); | |
} | |
} | |
public static void b(Object obj) { | |
if (d()) { | |
Log.e("RootBeer", c() + String.valueOf(obj)); | |
Log.e("QLog", c() + String.valueOf(obj)); | |
} | |
} | |
private static String c() { | |
StackTraceElement[] stackTrace = new Throwable().getStackTrace(); | |
String methodName = stackTrace[2].getMethodName(); | |
String className = stackTrace[2].getClassName(); | |
int lineNumber = stackTrace[2].getLineNumber(); | |
String substring = className.substring(className.lastIndexOf(46) + 1); | |
return substring + ": " + methodName + "() [" + lineNumber + "] - "; | |
} | |
public static boolean d() { | |
return f6954a > 0; | |
} | |
public static boolean e() { | |
return f6954a > 4; | |
} | |
public static void f(Object obj) { | |
if (e()) { | |
Log.v("RootBeer", c() + String.valueOf(obj)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.ObjectAnimator | |
import android.animation.PropertyValuesHolder | |
import android.content.Context | |
import android.content.Intent | |
import android.content.pm.PackageManager | |
import android.os.Build | |
import android.util.Log | |
import android.view.View | |
import android.view.animation.AccelerateDecelerateInterpolator | |
import com.prepladder.medical.prepladder.model.DataItem | |
import com.scottyab.rootbeer.RootBeer | |
import java.io.BufferedReader | |
import java.io.File | |
import java.io.InputStreamReader | |
import java.util.* | |
object RootUtil { | |
val isDeviceRooted: Boolean | |
get() { | |
Log.d("RootUtil=", "1 " + checkRootMethod1()) | |
Log.d("RootUtil=", "2 " + checkRootMethod2()) | |
Log.d("RootUtil=", "3 " + checkRootMethod3()) | |
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3() | |
} | |
private fun checkRootMethod1(): Boolean { | |
val buildTags = Build.TAGS | |
return buildTags != null && buildTags.contains("test-keys") | |
} | |
/** | |
* Using this method to check the root device using root beer library. | |
* | |
* @return true if device is rooted else false | |
*/ | |
fun checkRootByRootBeer(context: Context?): Boolean { | |
val rootBeer = RootBeer(context) | |
return (rootBeer.detectRootManagementApps() | |
|| rootBeer.detectPotentiallyDangerousApps() | |
|| rootBeer.detectRootCloakingApps() | |
|| rootBeer.detectTestKeys() | |
|| rootBeer.checkForBusyBoxBinary() | |
|| rootBeer.checkForSuBinary() | |
|| rootBeer.checkSuExists() | |
|| rootBeer.checkForRWPaths() | |
|| rootBeer.checkForDangerousProps() | |
|| rootBeer.checkForRootNative() | |
|| rootBeer.checkForMagiskBinary()) | |
} | |
fun checkRootMethod2(): Boolean { | |
val paths = arrayOf( | |
"/xposed.prop", | |
"/system/bin/app_process.orig", | |
"/system/lib/libxposed_art.so", | |
"/system/lib64/libxposed_art.so", | |
"/system/bin/app_process32_xposed", | |
"/system/bin/app_process64_xposed" /*, | |
"/data/data/de.robv.android.xposed.installer", | |
"/data/user/0/de.robv.android.xposed.installer", | |
"/data/user_de/0/de.robv.android.xposed.installer", | |
"/data/data/org.meowcat.edxposed.manager", | |
"/data/data/moe.riru.manager", | |
"/data/data/com.varuns2002.disable_flag_secure"*/ | |
) | |
for (path in paths) { | |
if (File(path).exists()) { | |
return true | |
} | |
} | |
return false | |
} | |
fun checkUnauthorizedPackagesExist(data: List<DataItem?>?): ArrayList<String> { | |
val packagesFoundList = ArrayList<String>() | |
val packagesList = ArrayList<String>() | |
val blackListedMountPaths = arrayOf( | |
"/sbin/.magisk/", | |
"/sbin/.core/mirror", | |
"/sbin/.core/img", | |
"/sbin/.core/db-0/magisk.db", | |
"/data/local/su", | |
"/data/local/bin/su", | |
"/data/local/xbin/su", | |
"/sbin/su", | |
"/su/bin/su", | |
"/system/bin/su", | |
"/system/bin/.ext/su", | |
"/system/bin/failsafe/su", | |
"/system/sd/xbin/su", | |
"/system/usr/we-need-root/su", | |
"/system/xbin/su", | |
"/cache/su", | |
"/data/su", | |
"/dev/su", | |
"/data/data/moe.shizuku.redirectstorage", | |
"/data/adb/modules/riru_momohider/config/isolated", | |
"/data/adb/modules/riru_momohider/config/setns", | |
"/data/adb/modules/riru_momohider/config/app_zygote_magic", | |
"/data/adb/modules/riru_momohider/config/initrc", | |
"data/adb/modules/riru-unshare", | |
"/data/adb/lspd", | |
"/data/adb/magisk", | |
"/data/adb/riru", | |
"/data/adb/shamiko", | |
"/data/adb/storage-isolation", | |
"/data/adb/modules/liboemcryptodisabler", | |
"/data/adb/modules/MagiskHidePropsConf", | |
"/data/adb/modules/riru-core", | |
"/data/adb/modules/riru_lsposed", | |
"/data/adb/modules/riru_storage_redirect", | |
"/data/adb/modules/zygisk_lsposed", | |
"/data/adb/modules/zygisk_shamiko" | |
) | |
// packagesList.addAll(Arrays.asList(blackListedMountPaths)); | |
for (i in blackListedMountPaths.indices) { | |
packagesList.add(blackListedMountPaths[i]) | |
} | |
if (data != null) { | |
for (i in packagesList.indices) { | |
val exist = File(Objects.requireNonNull(packagesList[i])).exists() | |
val isDirectory = File(Objects.requireNonNull(packagesList[i])).isDirectory | |
//Log.d("test_test_e", "" + exist); | |
//Log.d("test_test_d", "" + isDirectory + "|" + packagesList.get(i)); | |
if (File(Objects.requireNonNull<String>(packagesList[i])).exists() || File( | |
Objects.requireNonNull<String>( | |
packagesList[i] | |
) | |
).isDirectory | |
) { | |
packagesFoundList.add(packagesList[i]) | |
} | |
} | |
} | |
return packagesFoundList | |
} | |
private fun checkRootMethod3(): Boolean { | |
var process: Process? = null | |
return try { | |
process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su")) | |
val `in` = BufferedReader(InputStreamReader(process.inputStream)) | |
if (`in`.readLine() != null) true else false | |
} catch (t: Throwable) { | |
false | |
} finally { | |
process?.destroy() | |
} | |
} | |
fun setHeartBeatAnimationOnClick(iv: View?) { | |
val scaleDown = ObjectAnimator.ofPropertyValuesHolder( | |
iv, | |
PropertyValuesHolder.ofFloat("scaleX", 0.80f), | |
PropertyValuesHolder.ofFloat("scaleY", 0.80f) | |
) | |
scaleDown.duration = 400 | |
scaleDown.repeatCount = 1 | |
scaleDown.interpolator = AccelerateDecelerateInterpolator() | |
scaleDown.repeatMode = ObjectAnimator.REVERSE | |
scaleDown.start() | |
} | |
fun findExposedModules(context: Context): MutableList<String> { | |
val pm = context.packageManager | |
val intent = Intent(Intent.ACTION_MAIN) | |
val detectedList = mutableListOf<String>() | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
for (pkg in pm.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(PackageManager.GET_META_DATA.toLong()))) { | |
val aInfo = pkg.activityInfo.applicationInfo | |
if (aInfo.metaData?.get("xposedminversion") != null) { | |
val label = pm.getApplicationLabel(aInfo) as String | |
detectedList.add(label) | |
} | |
} | |
} else { | |
for (pkg in pm.queryIntentActivities(intent, PackageManager.GET_META_DATA)) { | |
val aInfo = pkg.activityInfo.applicationInfo | |
if (aInfo.metaData?.get("xposedminversion") != null) { | |
val label = pm.getApplicationLabel(aInfo) as String | |
detectedList.add(label) | |
} | |
} | |
} | |
return detectedList | |
} | |
} |
No comments :
Post a Comment