在系统分区写入文件分区、文件、系统

2023-09-06 04:31:29 作者:Borders moved. 境迁。

我试图写一个文件,通过我的应用程序产生的,到系统分区。正如我不能创建在我的应用程序的的FileOutputStream我创造我的应用程序的数据目录中的文件,更正许可权,然后将其移动到系统分区。

目前的code以下错过的/系统的可写再登 - 因为我已通过亚行重新装入执行这一步成功测试目的 - 因此这不应该是问题所在。

该应用程序也得到成功的root权限。

不过,code以下无法正常工作。它只创建文件,但不将其移动到系统分区。什么是我的错?

 的FileOutputStream OUT = openFileOutput(myfile.test,MODE_WORLD_READABLE);
文件f = getFileStreamPath(myfile.test);
writeDataToOutputStream(出);
out.close();
字符串文件名= f.getAbsolutePath();
运行时R =调用Runtime.getRuntime();
r.exec(素);
//这里等待几秒钟没有任何区别
r.exec(新的String [] {CHOWN,root.root,文件名});
r.exec(新的String [] {文件模式,64​​4,文件名});
r.exec(新的String [] {MV,文件名,/system/myfile.test});
 

解决方案

OK,我发现如何执行多个命令的root权限。诀窍是所有命令发送到一个SU过程:

 的FileOutputStream OUT = openFileOutput(myfile.test,MODE_WORLD_READABLE);
文件f = getFileStreamPath(myfile.test);
writeDataToOutputStream(出);
out.close();
字符串文件名= f.getAbsolutePath();
运行时R =调用Runtime.getRuntime();
流程suProcess = r.exec(素);
DataOutputStream类DOS =新DataOutputStream类(suProcess.getOutputStream());
dos.writeBytes(CHOWN 0.0+文件名+\ N);
dos.flush();
dos.writeBytes(搭配chmod 644+文件名+\ N);
dos.flush();
dos.writeBytes(MV+文件名+/system/myfile.test\n);
dos.flush();
 

剩下的唯一的事情(不包括嚣code以上)是使 /系统写。 可能会像一个额外的命令mount -o RW,重新挂载/系统就足够了 - 将测试

如何在 终端下创建新的文件系统 分区

I am trying to write a file, generated by my app, onto the system partition. As I can not create an FileOutputStream inside my app I create the file in the data directory of my app, correct the permissions and then move it to the system partition.

At the moment the code below misses the writable remount of /system - for testing purposes I have performed this step successfully via adb remount - therefore this should not be the problem.

The app also gets successfully root permissions.

But the code below does not work. It only creates the file but does not move it to the system partition. What's my mistake?

FileOutputStream out = openFileOutput("myfile.test", MODE_WORLD_READABLE);
File f = getFileStreamPath("myfile.test");
writeDataToOutputStream(out);
out.close();
String filename = f.getAbsolutePath();
Runtime r = Runtime.getRuntime();
r.exec("su");
// Waiting here some seconds does not make any difference
r.exec(new String[] { "chown", "root.root", filename });
r.exec(new String[] { "chmod", "644", filename });
r.exec(new String[] { "mv", filename, "/system/myfile.test" });

解决方案

OK, I found how to execute multiple commands with root permissions. The trick is to send all commands to the one su process:

FileOutputStream out = openFileOutput("myfile.test", MODE_WORLD_READABLE);
File f = getFileStreamPath("myfile.test");
writeDataToOutputStream(out);
out.close();
String filename = f.getAbsolutePath();
Runtime r = Runtime.getRuntime();
Process suProcess = r.exec("su");
DataOutputStream dos = new DataOutputStream(suProcess.getOutputStream());
dos.writeBytes("chown 0.0 " + filename + "\n");
dos.flush();
dos.writeBytes("chmod 644 " + filename + "\n");
dos.flush();
dos.writeBytes("mv " + filename + " /system/myfile.test\n");
dos.flush();

The only thing left (not include din the code above) is to make /system writable. May be one additional command like mount -o rw,remount /system is sufficient - will test that.