Android设备的根目录检查

Android设备的根目录检查,android,Android,这是一个老生常谈的问题,很多人都在问和回答,但我又来了。。我想检查设备是否为根设备。我不希望我的应用程序安装在根设备上。现在,我看了很多答案,得出了一个结论,没有确定的方法来识别根,如果我错了,请纠正我。 现在我的问题是,我们可以检查设备是否为正品,而不是检查是否为正品? 是否有任何应用程序可以测试我已签名的APK的代码签名、ssl固定、代码公开和许多其他功能?检查此链接: 找到一些方法来检查设备是否为root。它工作得很好 DemoActivity.class if (isDeviceRoot

这是一个老生常谈的问题,很多人都在问和回答,但我又来了。。我想检查设备是否为根设备。我不希望我的应用程序安装在根设备上。现在,我看了很多答案,得出了一个结论,没有确定的方法来识别根,如果我错了,请纠正我。 现在我的问题是,我们可以检查设备是否为正品,而不是检查是否为正品? 是否有任何应用程序可以测试我已签名的APK的代码签名、ssl固定、代码公开和许多其他功能?

检查此链接:

找到一些方法来检查设备是否为root。它工作得很好

DemoActivity.class

if (isDeviceRooted()) {
            DialogFactory.getInstance().showAlertDialog(this, null, 0, "This application can't run on Rooted android phone", "Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finishAffinity();
                }
            }, false);
        }
        else {
/* Do your code */
}

public static boolean isDeviceRooted() {
        return Utils.checkRootMethod1() || Utils.checkRootMethod2() || Utils.checkRootMethod3();
    }
public static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

public static boolean checkRootMethod2() {
    String[] paths = {"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
            "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

public static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}
Utils.class

if (isDeviceRooted()) {
            DialogFactory.getInstance().showAlertDialog(this, null, 0, "This application can't run on Rooted android phone", "Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finishAffinity();
                }
            }, false);
        }
        else {
/* Do your code */
}

public static boolean isDeviceRooted() {
        return Utils.checkRootMethod1() || Utils.checkRootMethod2() || Utils.checkRootMethod3();
    }
public static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

public static boolean checkRootMethod2() {
    String[] paths = {"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
            "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

public static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}
检查此链接:

找到一些方法来检查设备是否为root。它工作得很好

DemoActivity.class

if (isDeviceRooted()) {
            DialogFactory.getInstance().showAlertDialog(this, null, 0, "This application can't run on Rooted android phone", "Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finishAffinity();
                }
            }, false);
        }
        else {
/* Do your code */
}

public static boolean isDeviceRooted() {
        return Utils.checkRootMethod1() || Utils.checkRootMethod2() || Utils.checkRootMethod3();
    }
public static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

public static boolean checkRootMethod2() {
    String[] paths = {"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
            "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

public static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}
Utils.class

if (isDeviceRooted()) {
            DialogFactory.getInstance().showAlertDialog(this, null, 0, "This application can't run on Rooted android phone", "Exit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finishAffinity();
                }
            }, false);
        }
        else {
/* Do your code */
}

public static boolean isDeviceRooted() {
        return Utils.checkRootMethod1() || Utils.checkRootMethod2() || Utils.checkRootMethod3();
    }
public static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

public static boolean checkRootMethod2() {
    String[] paths = {"/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
            "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

public static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}

下面是我用于根检查的实用程序类。这里是我使用的字符串常量。这对我有用

public static final String[] knownRootAppsPackages = {
            "com.noshufou.android.su",
            "com.noshufou.android.su.elite",
            "eu.chainfire.supersu",
            "com.koushikdutta.superuser",
            "com.thirdparty.superuser",
            "com.yellowes.su",
            "com.zachspong.temprootremovejb",
            "com.ramdroid.appquarantine",
            "eu.chainfire.supersu"

    };

    public static final String[] knownDangerousAppsPackages = {
            "com.koushikdutta.rommanager",
            "com.koushikdutta.rommanager.license",
            "com.dimonvideo.luckypatcher",
            "com.chelpus.lackypatch",
            "com.ramdroid.appquarantine",
            "com.ramdroid.appquarantinepro"
    };

    public static final String[] knownRootCloakingPackages = {
            "com.devadvance.rootcloak",
            "com.devadvance.rootcloakplus",
            "de.robv.android.xposed.installer",
            "com.saurik.substrate",
            "com.zachspong.temprootremovejb",
            "com.amphoras.hidemyroot",
            "com.amphoras.hidemyrootadfree",
            "com.formyhm.hiderootPremium",
            "com.formyhm.hideroot"
    };

    public static final String[] suPaths ={
            "/data/local/",
            "/data/local/bin/",
            "/data/local/xbin/",
            "/sbin/",
            "/su/bin/",
            "/system/bin/",
            "/system/bin/.ext/",
            "/system/bin/failsafe/",
            "/system/sd/xbin/",
            "/system/usr/we-need-root/",
            "/system/xbin/"
    };


    public static final String[] pathsThatShouldNotBeWrtiable = {
            "/system",
            "/system/bin",
            "/system/sbin",
            "/system/xbin",
            "/vendor/bin",
            //"/sys",
            "/sbin",
            "/etc",
            //"/proc",
            //"/dev"
    }
)

公共类RootUtil{
公共静态布尔值isDeviceRooted(){
返回detectRootManagementApps()| | detectPotentiallyDangerousApps()| | checkForBinary(“su”)
||checkForBinary(“busybox”)| | CheckForDangerProps()| | CheckForrWpath()
||detectTestKeys()| | ChecksExists();
}
公共静态布尔detectTestKeys(){
String buildTags=android.os.Build.TAGS;
字符串buildFinger=Build.FINGERPRINT;
字符串product=Build.product;
字符串hardware=Build.hardware;
字符串显示=Build.display;
return(buildTags!=null)和&(buildTags.contains(“测试键”)| | buildFinger.contains(“genric.*测试键”)| | product.contains(“generic”)| | product.contains(“sdk”)| hardware.contains(“goldfish”)| display.contains(“测试键”);
}
公共静态布尔DetectroutManagementApps(){
返回DetectroutManagementApps(空);
}
公共静态布尔DetectoreTManagementApps(字符串[]additionalRootManagementApps){
ArrayList packages=新的ArrayList();
packages.addAll(Arrays.asList(Constants.knownrootapspackages));
if(additionalRootManagementApps!=null&&additionalRootManagementApps.length>0){
packages.addAll(Arrays.asList(additionalRootManagementApps));
}
返回isAnyPackageFromListInstalled(软件包);
}
公共静态布尔检测潜在危险应用程序(){
返回DetectPotentialLangerousApps(null);
}
公共静态布尔检测潜在危险应用程序(字符串[]其他危险应用程序){
ArrayList packages=新的ArrayList();
packages.addAll(Arrays.asList(Constants.knowndagerousappspackages));
if(additionalDangerousApps!=null&&additionalDangerousApps.length>0){
packages.addAll(Arrays.asList(additionalDangerousApps));
}
返回isAnyPackageFromListInstalled(软件包);
}
公共布尔值DetectrootLoakingApps(){
返回DetectrootLoakingApps(空);
}
公共布尔DetectrootLoakingApps(字符串[]AdditionalRoot隐身Apps){
ArrayList packages=新的ArrayList();
addAll(Arrays.asList(Constants.knownRootCloakingPackages));
if(AdditionalRootClothingApps!=null&&AdditionalRootClothingApps.length>0){
packages.addAll(Arrays.asList(AdditionalRootCoveringApps));
}
返回isAnyPackageFromListInstalled(软件包);
}
公共布尔checkForSuBinary(){
返回checkForBinary(“su”);
}
public boolean checkForBusyBoxBinary(){
返回checkForBinary(“busybox”);
}
公共静态布尔checkForBinary(字符串文件名){
String[]pathsArray=Constants.suPaths;
布尔结果=假;
用于(字符串路径:pathsArray){
字符串completePath=路径+文件名;
文件f=新文件(completePath);
布尔fileExists=f.exists();
如果(文件存在){
结果=真;
}
}
返回结果;
}
私有静态字符串[]propsReader(){
InputStream InputStream=null;
试一试{
inputstream=Runtime.getRuntime().exec(“getprop”).getInputStream();
}捕获(IOE异常){
e、 printStackTrace();
}
字符串propval=“”;
试一试{
propval=新扫描仪(inputstream)。使用分隔符(\\A”).next();
}捕获(无接触元素例外e){
}
返回按比例拆分(“\n”);
}
私有静态字符串[]mountReader(){
InputStream InputStream=null;
试一试{
inputstream=Runtime.getRuntime().exec(“mount”).getInputStream();
}捕获(IOE异常){
e、 printStackTrace();
}
if(inputstream==null)返回null;
字符串propval=“”;
试一试{
propval=新扫描仪(inputstream)。使用分隔符(\\A”).next();
}捕获(无接触元素例外e){
e、 printStackTrace();
}
返回按比例拆分(“\n”);
}
私有静态布尔值isAnyPackageFromListInstalled(列出包){
布尔结果=假;
PackageManager pm=MobileTechnicianApp.getAppContext().getPackageManager();
用于(字符串packageName:packages){
试一试{
pm.getPackageInfo(packageName,0);
结果=真;
}捕获(PackageManager.NameNotFounde异常){
}
}
返回结果;
}
公共静态布尔checkforDangeruprops(){
final Map dangerousProps=new HashMap();
危险道具放置(“ro.可调试”,“1”);
危险道具。放置(“旋转安全”,“0”);
布尔结果=假;
字符串[]行=propsReader();
用于(字符串行:行){
用于(字符串键:dangerousPro