确定Android设备是否以编程方式为根?

Pen*_*m10 37 android

可能重复:
确定是否在root设备上运行

如何(以编程方式)确定Android设备是否:rooted运行软件或ROM的破解副本.

我的数据库中有一些敏感信息,我希望在手机被root用户时加密,即用户可以访问数据库.我怎么检测到?

pec*_*eps 37

生根检测是一种猫捉老鼠游戏,很难进行生根检测,适用于所有情况下的所有设备.

请参阅Android Root Beer https://github.com/scottyab/rootbeer以获取高级根检测,该检测还使用编译到.so本机库中的JNI和本机CPP代码.

如果您需要一些简单和基本的生根检测,请检查以下代码:

  /**
   * Checks if the device is rooted.
   *
   * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
   */
  public static boolean isRooted() {

    // get from build info
    String buildTags = android.os.Build.TAGS;
    if (buildTags != null && buildTags.contains("test-keys")) {
      return true;
    }

    // check if /system/app/Superuser.apk is present
    try {
      File file = new File("/system/app/Superuser.apk");
      if (file.exists()) {
        return true;
      }
    } catch (Exception e1) {
      // ignore
    }

    // try executing commands
    return canExecuteCommand("/system/xbin/which su")
        || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
  }

  // executes a command on the system
  private static boolean canExecuteCommand(String command) {
    boolean executedSuccesfully;
    try {
      Runtime.getRuntime().exec(command);
      executedSuccesfully = true;
    } catch (Exception e) {
      executedSuccesfully = false;
    }

    return executedSuccesfully;
  }
Run Code Online (Sandbox Code Playgroud)

可能并不总是正确的.2014年测试了~10台设备.

  • 你的意思是根据添加Superuser.apk的特定工具扎根?由于大多数检查都可以被规避,因此无法保证以编程方式确定设备是否已植根. (5认同)

oli*_*oli 5

如果信息是敏感的,您应该只为所有用户加密.否则,用户可以在没有根据的情况下安装您的应用程序,然后在数据写入后root并读取您的数据库.