Android 루팅(Rooting) 여부 체크

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 } }


댓글 없음:

댓글 쓰기

Jetpack Compose Composable의 Lifecycle

  이 페이지에서는 컴포저블의 수명 주기에 관해 알아보며 Compose에서 컴포저블에 재구성이 필요한지를 결정하는 방법을 살펴봅니다. 수명 주기 개요 상태 관리 문서 에 설명된 대로 컴포지션은 앱의 UI를 설명하고 컴포저블을 실행하여 생성됩니다. 컴포...