루팅 여부 체크

RootBeer의 간단한 버전


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
}
}
view rawRootChecker.kt hosted with ❤ by GitHub

댓글

이 블로그의 인기 게시물

아이랑스토리 어플리케이션 개인정보처리방침

Jetpack Compose Navigation 정리

Jetpack Compose 기초정리