如何将文件保存到Android / system目录? [英] How to save files to Android /system directory?

查看:239
本文介绍了如何将文件保存到Android / system目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写将从资产目录中的文件复制到Android的/ system目录下的应用程序。

I am writing an application that will copy files from its assets directory to the Android's /system directory.

我觉得我越来越接近实现这一点,但我不太有。这里是我试图策略:

I feel that I am getting close to achieving this, but I am not quite there. Here is the strategy that I have attempted:

首先,我试图改变/系统目录的权限:

First, I tried to change the permissions of the /system directory by:

Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("mount -o rw,remount -t yaffs2 /dev/block/mtdblock4");
Runtime.getRuntime().exec("chmod -R 777 /system");

二,我试着写一个文件到/ system目录。

Second, I tried to write a file to the /system directory.

我读通过重新安装的目录,我可以文件写入。的确,这似乎与终端工作。但在应用程序中,我无法弄清楚如何确保每个命令被下一个执行之前完成。

I read that by remounting the directory, I could write files to it. Indeed, this seemed to work with a terminal. But in the application, I couldn't figure out how to make sure each command was completed before execution of the next one.

有没有人有什么建议吗?

Does anyone have any suggestions?

推荐答案

我假设有一个从返回值,你应该检查,请参阅exec()方法如果执行工作的罚款。

I assume there is a return value from the exec() method that you should be checking to see if the execution worked fine.

不过,我想你已经在你尝试执行此一系列的命令得到了几个错误:

But I think you've got several mistakes in your attempts to execute this series of commands:


  • 只能影响其自身进程和子进程。不带参数运行它,所以它什么都不做。接下来的执行exec()方法从头重新开始你的过程,而不是提升权限你所期望的确切权限。

  • 贴装(8)命令看起来不正确:你不是说哪个挂载点操控。 (不要忘记,一个设备可以安装在多个位置。)

  • CHMOD(1)调用也不会运行与特权的的设置权限的方式过于开放。也许你不关心安全设备上,这很好,但可以肯定,那就是你想要的。

  • su can only influence its own process and child processes. You execute it with no arguments, so it does nothing. The next exec() method starts over from scratch with the exact permissions of your process, not the elevated privileges you might expect.
  • Your mount(8) command doesn't seem right: you're not saying which mountpoint to manipulate. (Don't forget that a device may be mounted in multiple locations.)
  • Your chmod(1) call also doesn't run with privileges and sets permissions way too open. Perhaps you don't care about security on your device, that's fine, but be certain that that is what you want.

我相信你的安装命令应该看起来更像是:

I believe your mount command should look more like:

Runtime.getRuntime().exec("su -c \"mount -orw,remount /system\"");

我相信你的搭配chmod 命令应该看起来更像是:

And I believe your chmod command should look more like:

Runtime.getRuntime().exec("su -c \"chmod 777 /system/fonts\"");

再次肯定你明白允许在系统权限的所有用户写入任何文件,其他用户可以执行的后果。

Again, be certain you understand the consequences of allowing all users on the system privileges to write to any file that other users can execute.

这篇关于如何将文件保存到Android / system目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆