在Android应用程序中安装R/W系统以编辑只读文件

发布于 2024-11-30 07:22:34 字数 407 浏览 1 评论 0原文

如何在我的应用程序中编辑 /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();

以及许多其他方法,但没有成功。

如果有人可以帮助我,我将不胜感激! :)

另外,如果我最终成功了,它适用于所有 root 的手机吗?或者有些手机有什么不同?

How can I, within my application, edit a file in the /system/ directory?

Do I have to make the system R/W accessible?

I ve tried:

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();

and many other ways, without success.

If anybody can help me, I'd greatly appreciated it! :)

Also, if i finally made it, will it worked with all rooted phones? Or is it different with some phones?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看春风乍起 2024-12-07 07:22:34

我使用:

    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/列表
这是 Wiki 页面:
http://code.google.com/p/roottools/w/list

但我现在正在使用:

RootTools.remount(file, mountType);
//For example:
RootTools.remount("/system/", "rw");

我相信这是普遍的

I use:

    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.

And that allows me to successfully mount.

If you exit right after that, of course it will not work. You have to stay within the same process and use the linux commands to edit the file.

I have no idea how to edit the files, but I suggest googling how to do things in linux terminal, and then putting the proper code in os.writeBytes("CODE_HERE");

Though, as far as the mounting process is concerned, I don't know if that command will work universally. It may just fortunately work on my device.

EDIT:
I now use RootTools: http://code.google.com/p/roottools/downloads/list
And here is the Wiki page:
http://code.google.com/p/roottools/w/list

But I now am using:

RootTools.remount(file, mountType);
//For example:
RootTools.remount("/system/", "rw");

I believe that is universal

本宫微胖 2024-12-07 07:22:34

编辑:以下代码的所有版本都不会将系统安装为 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());

我没有粘贴一些 try catch 案例。
我还遇到了另一个问题..我在版本2中解决了它。小问题是,我要求一个特定的su命令,而用户必须接受RO的SU cmd,RW的SU cmd。 。还有时间讨论我的程序中的其他内容。
在第二个版本中,我使用通用 su 命令,因此用户必须仅接受一次 SU 权限,并且我使用输出流。

代码版本 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());
  • 这两个代码都需要您设备上的 Root 权限。
  • 这两个版本都不包含捕获案例。 (Eclpise 会为您找到它们)
  • 检查您的 logcat(adb logcat),看看它确实有效!
  • 使用最新的 su 二进制文件,此代码略有更改。更改模式命令需要 4 位数字。 0777 代表 rw 权限,0755 代表 ro 权限!
  • 这段代码是它自己的,它对你的设备没有任何作用。

只是它挂载了built.prop RW,然后挂载它回到RO。
但如果你改变它,你的设备可能会变砖!保重!

Edit: All version of codes below DOES NOT mount system as RW.
*Read comments below to see why.
Solution of this is not a simple command.

Edit1: I went on Super User apk, Settings tab, and "tapped" at the last item, to update the su binary. With that update, everything below isnt working.

Edit2: started a whole conversation with my self here. Fix for the current latest binary is at the bottom of the post

==================================================================================

Found out how to do it! Second day of efforts, and finally found it!!!!!
Tried several things, and answer was to a simple change mode,

what i have done:

First Version Code:(doesnt work)

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());

I didnt paste some try catch cases.
Also i got another problem.. And i solved it in Version 2. THe little problem was, that, i was asking for a specific for a su command, and the user, had to accept SU cmd for RO, SU cmd for RW.. and another time for other stuff in my program.
In 2nd version i m using the generic su command, so user has to accept SU privileges only ONE time, and i m using output stream.

Code Version 2(Recomended) (doesnt work):

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());
  • Both codes require Root on your device.
  • Both versions doesnt include catch cases. (Eclpise will found them for you)
  • Check out your logcat(adb logcat), to see that indeed it works!
  • With latest su binary, this code changes slightly. The change mode command requires 4 digits. 0777 for rw permissions, and 0755 for ro permissions!
  • This code by its own, it does nothing to your device.

Only it mounts built.prop RW, and then mounts it back to RO.
Although if you change it, you may brick your device! Take care!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文