【问题标题】:Accesing root level system folder Android访问根级系统文件夹 Android
【发布时间】:2016-08-02 11:34:46
【问题描述】:

我有 root 权限,我正在为我的应用测试一项新功能,该功能涉及访问和编辑 Android 的系统文件夹。

但是我的代码似乎没有改变任何东西。我在Marshmallow CM 13.

Process p;
    try {
        // Preform su to get root privileges
        p = Runtime.getRuntime().exec("su");

        // Attempt to write a file to a root-only
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("echo \"Do I have root?\" >/system/etc/temporary.txt\n");

        // Close the terminal
        os.writeBytes("exit\n");
        os.flush();
        try {
            p.waitFor();
            if (p.exitValue() != 255) {
                // TODO Code to run on success
                toastMessage("root");
            }
            else {
                // TODO Code to run on unsuccessful
                toastMessage("not root");
            }
        } catch (InterruptedException e) {
            // TODO Code to run in interrupted exception
            toastMessage("not root");
        }
    } catch (IOException e) {
        // TODO Code to run in input/output exception
        toastMessage("not root");
    }

【问题讨论】:

  • 而是先尝试打印权限
  • @Shriram 通过 adb shell?

标签: java android su


【解决方案1】:

/system 挂载点默认挂载为 RO。即使具有根级别权限,写入它的唯一方法是将其重新挂载为 RW。此外,您可能仍会遇到 SE Android (SE Linux for Android) 的一些问题,该问题自 Lollipop 以来一直存在并处于完全强制执行模式。平台中可能内置了 SE Android 安全策略,该策略将限制对文件系统某些部分的访问,即使是 root。

【讨论】:

    猜你喜欢
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多