Advertisement
po4yka

Root Check

Dec 1st, 2022
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.32 KB | Software | 0 0
  1. object RootUtil {
  2.     val isDeviceRooted: Boolean
  3.         get() = checkRootMethod1() || checkRootMethod2() || checkRootMethod3()
  4.  
  5.     private fun checkRootMethod1(): Boolean {
  6.         val buildTags = Build.TAGS
  7.         return buildTags != null && buildTags.contains("test-keys")
  8.     }
  9.  
  10.     private fun checkRootMethod2(): Boolean {
  11.         val paths = arrayOf(
  12.             "/system/app/Superuser.apk",
  13.             "/sbin/su",
  14.             "/system/bin/su",
  15.             "/system/xbin/su",
  16.             "/data/local/xbin/su",
  17.             "/data/local/bin/su",
  18.             "/system/sd/xbin/su",
  19.             "/system/bin/failsafe/su",
  20.             "/data/local/su",
  21.             "/su/bin/su"
  22.         )
  23.         for (path in paths) {
  24.             if (File(path).exists()) return true
  25.         }
  26.         return false
  27.     }
  28.  
  29.     @Suppress("SwallowedException", "TooGenericExceptionCaught")
  30.     private fun checkRootMethod3(): Boolean {
  31.         var process: Process? = null
  32.         return try {
  33.             process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
  34.             val inputReader = BufferedReader(InputStreamReader(process.inputStream))
  35.             inputReader.readLine() != null
  36.         } catch (t: Throwable) {
  37.             false
  38.         } finally {
  39.             process?.destroy()
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement