如何在我的应用程序中编辑/system/目录中的文件?
我必须使系统读/写可访问吗?
我试过了:
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount,rw /system\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();还有许多其他的方法,但都没有成功。
如果有人能帮助我,我将不胜感激!:)
另外,如果我最终做到了,它会在所有的根手机上工作吗?还是有些手机不一样?
发布于 2011-11-17 07:51:32
我使用:
os.writeBytes("mount -o remount rw /system/\n");
//instead of a comma, I have a space.
//When I tried it with a comma, mine didn't work either.这让我可以成功地挂载。
如果您在此之后立即退出,它当然不会工作。您必须保持在相同的进程中,并使用linux命令编辑该文件。
我不知道如何编辑这些文件,但我建议谷歌一下如何在linux终端上做事情,然后把适当的代码放在os.writeBytes("CODE_HERE");中。
不过,就挂载过程而言,我不知道该命令是否适用于所有人。幸运的是,它可以在我的设备上运行。
编辑:
我现在使用RootTools:http://code.google.com/p/roottools/downloads/list
这是Wiki的页面:
http://code.google.com/p/roottools/w/list
但我现在使用的是:
RootTools.remount(file, mountType);
//For example:
RootTools.remount("/system/", "rw");我相信这是普遍存在的
发布于 2011-08-20 20:53:47
编辑:以下所有版本的代码都不会将系统挂载为RW。*请阅读下面的注释以了解原因。这个问题的解决方案不是一个简单的命令。
Edit1:我在超级用户apk、设置选项卡上点击了最后一项,更新了su二进制文件。有了这个更新,下面的所有东西都不工作了。
Edit2:在这里和我自己开始了一段完整的对话。针对当前最新二进制文件的修复位于文章的底部
==================================================================================
我知道怎么做了!第二天努力,终于找到了!尝试了几种方法,答案是一个简单的更改模式,
我所做的:
第一版本代码:(不起作用)
String[] mountRW = { "su", "-c",
"chmod 777 /system/etc/build.prop"};
String[] mountRO = {"su", "-c",
"chmod 755 /system/etc/build.prop"};
//TODO REMOVE testing purposes
File file2 = new File("/system/build.prop");
//Make file Read-Write
process = Runtime.getRuntime().exec(mountRW);
process.waitFor();
//TODO REMOVE testing purposes
Log.d("MOUNT RW?", "RW WRITABLE? "+ file2.canWrite());
///////////////////////
// process the file
//////////////////////
// After editing finish,
//make Read Only file again
process = Runtime.getRuntime().exec(mountRO);
process.waitFor();
//TODO REMOVE
Log.d("MOUNT RO?", "RO WRITABLE? "+ file2.canWrite());我没有粘贴一些尝试捕获的案例。我还有另一个问题..我在版本2中解决了这个问题。THe的小问题是,我为su命令请求一个特定的命令,而用户必须接受用于RO的SU cmd和用于RW的SU cmd。另一次是我的程序中的其他内容。在第二个版本中,我使用的是一般的su命令,所以用户只需要接受SU特权一次,而我使用的是output stream。
代码版本2(推荐)(不起作用)
String mountRW = "chmod 777 /system/build.prop";
String mountRO = "chmod 755 /system/build.prop";
//TODO REMOVE
File file2 = new File("/system/build.prop");
//Make file Read-Write
process = Runtime.getRuntime().exec("su"); //Generic SU Command
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(mountRW + " \n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
//TODO REMOVE
Log.d("MOUNT RW?", " RW WRITABLE? "+ file2.canWrite());
////////////////////////////
/// mod the file
///////////////////////////
// After editing finish, make Read Only file again
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(mountRO + " \n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
//TODO REMOVE
Log.d("MOUNT RO?", "RO WRITABLE? "+ file2.canWrite());在您的device.
产生任何影响
仅装载built.prop RW,然后将其装载回RO。虽然如果你改变它,你可能会砖你的设备!多保重!
https://stackoverflow.com/questions/7129144
复制相似问题