Created
April 17, 2021 12:46
-
-
Save gold24park/979241275ec2d488ccfc8201cd35b585 to your computer and use it in GitHub Desktop.
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
class RootChecker( | |
private val context: Context | |
) { | |
private val rootFiles = arrayOf( | |
"/system/app/Superuser.apk", | |
"/sbin/su", | |
"/system/bin/su", | |
"/system/xbin/su", | |
"/system/usr/we-need-root/", | |
"/data/local/xbin/su", | |
"/data/local/bin/su", | |
"/system/sd/xbin/su", | |
"/system/bin/failsafe/su", | |
"/data/local/su", | |
"/su/bin/su", | |
"/su/bin", | |
"/system/xbin/daemonsu" | |
) | |
private val rootPackages = arrayOf( | |
"com.devadvance.rootcloak", | |
"com.devadvance.rootcloakplus", | |
"com.koushikdutta.superuser", | |
"com.thirdparty.superuser", | |
"eu.chainfire.supersu", | |
"de.robv.android.xposed.installer", | |
"com.saurik.substrate", | |
"com.zachspong.temprootremovejb", | |
"com.amphoras.hidemyroot", | |
"com.amphoras.hidemyrootadfree", | |
"com.formyhm.hiderootPremium", | |
"com.formyhm.hideroot", | |
"com.noshufou.android.su", | |
"com.noshufou.android.su.elite", | |
"com.yellowes.su", | |
"com.topjohnwu.magisk", | |
"com.kingroot.kinguser", | |
"com.kingo.root", | |
"com.smedialink.oneclickroot", | |
"com.zhiqupk.root.global", | |
"com.alephzain.framaroot" | |
) | |
private val runtime by lazy { | |
Runtime.getRuntime() | |
} | |
fun isDeviceRooted(): Boolean { | |
return checkRootFiles() || checkSUExist() || checkRootPackages() | |
} | |
private fun checkRootFiles(): Boolean { | |
for (path in rootFiles) { | |
try { | |
if (File(path).exists()) { | |
return true | |
} | |
} catch (e: RuntimeException) { | |
} | |
} | |
return false | |
} | |
private fun checkSUExist(): Boolean { | |
var process: Process? = null | |
val su = arrayOf("/system/xbin/which", "su") | |
try { | |
process = runtime.exec(su) | |
BufferedReader( | |
InputStreamReader( | |
process.inputStream, | |
Charset.forName("UTF-8") | |
) | |
).use { reader -> return reader.readLine() != null } | |
} catch (e: IOException) { | |
} catch (e: Exception) { | |
} finally { | |
process?.destroy() | |
} | |
return false | |
} | |
private fun checkRootPackages(): Boolean { | |
val pm = context.packageManager | |
if (pm != null) { | |
for (pkg in rootPackages) { | |
try { | |
pm.getPackageInfo(pkg, 0) | |
return true | |
} catch (ignored: PackageManager.NameNotFoundException) { | |
// fine, package doesn't exist. | |
} | |
} | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment