gpt4 book ai didi

java - 访问根级系统文件夹Android

转载 作者:行者123 更新时间:2023-12-02 03:26:56 24 4
gpt4 key购买 nike

我拥有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");
}

最佳答案

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

关于java - 访问根级系统文件夹Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38719321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com