Skip to content

Instantly share code, notes, and snippets.

@Fuzion24
Last active May 27, 2016 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fuzion24/2623315 to your computer and use it in GitHub Desktop.
Save Fuzion24/2623315 to your computer and use it in GitHub Desktop.
A few different mechanisms to check for root on an Android device
check for timestamp modication differences in /system/
package com.test.rootchecker;
import java.io.File;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.content.pm.ApplicationInfo;
public class RootChecker {
Context ctx;
RootChecker(Context context)
{
ctx = context;
}
Boolean checkForSuperUserAPK()
{
//package:com.noshufou.android.su.elite
//package:com.noshufou.android.su
List<ApplicationInfo> localList = ctx.getPackageManager().getInstalledApplications(0x00);
for (ApplicationInfo info : localList)
{
if(info.packageName.contains("com.noshufou"))
return true;
}
return false;
}
Boolean checkSuBinary()
{
//Iterate through all folders in PATH looking for su
Map<String,String> env = System.getenv();
String path = env.get("PATH");
String [] dirs = path.split(":");
for (String dir : dirs){
String suPath = dir + "/" + "su";
File suFile = new File(suPath);
if (suFile != null && suFile.exists()) {
return true;
}
}
return false;
}
Boolean check_ro_secure()
{
String roSecureProp = System.getProperty("ro.secure");
if (roSecureProp != null && roSecureProp.contains("0"))
return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment