Last active
August 29, 2024 19:43
-
-
Save astraube/ed9e482de281e184f887b6c7a9645d1e to your computer and use it in GitHub Desktop.
Android root user checker
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
package com.github.astraube | |
import android.util.Log | |
import java.io.File | |
/** | |
* @author Andre - Created on 13/07/2021 | |
*/ | |
object RootChecker { | |
private val TAG = RootChecker::class.java.simpleName | |
/** | |
* Nome exato do binário que concede os privilégios de root | |
*/ | |
private const val SU_FILE_NAME = "su" | |
/** | |
* Contém todos os locais possíveis para verificação dos binários | |
*/ | |
private val pathList: Array<String> = arrayOf( | |
"/sbin/", | |
"/system/bin/", | |
"/system/xbin/", | |
"/data/local/xbin/", | |
"/data/local/bin/", | |
"/system/sd/xbin/", | |
"/system/bin/failsafe/", | |
"/data/local/" | |
) | |
val isDeviceRooted: Boolean | |
get() = isFileExists(SU_FILE_NAME) | |
/** | |
* Verifica todos os caminhos configurados até encontrá-lo. | |
* | |
* @param fileName o valor deve ser apenas o nome binário | |
* @return se o caminho for encontrado, retorna 'true' imediatamente | |
*/ | |
private fun isFileExists(fileName: String): Boolean { | |
var result = false | |
for (path in pathList) { | |
val file = File("$path/$fileName") | |
result = file.exists() | |
if (result) { | |
Log.d(TAG, "$path exists su binary") | |
break | |
} | |
} | |
return result | |
} | |
/** | |
* Executa comandos caso possua permissao root | |
* | |
* @param command comandos a serem executados | |
*/ | |
fun runCommandRoot(command: String) = TODO("finalizar implementação") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment