文件拷贝和替换/带root权限的系统目录? [英] File copy and replacing in /system directory with root permission?

查看:151
本文介绍了文件拷贝和替换/带root权限的系统目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能热情地向我展示了如何从我的应用程序文件夹资产的文件复制到/ system文件夹?我知道如何获得root权限和所有。例如:我想从/assets/lib/libs.so复制文件,并检查该文件已经存在,如果这样做,更换新的/system/lib/libs.so

Can anyone kind enough show me how to copy files from my app assets folder to /system folder? I know how to get root access and all. For example: I want to copy file from "/assets/lib/libs.so" and check if this file already exist, if it does replace it to new "/system/lib/libs.so".

推荐答案

这将检查你的文件存在,删除它,然后复制全部的寄托就是资产。

This will check if your file exists, delete it and then copy everthing that is in assets.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



   File exists = new File("/system/lib/libs.so");
   if(exists.exists()){       
   exists.delete();
   CopyAssets();
   }else{
       CopyAssets();
   }


}


private void CopyAssets() { 
    AssetManager assetManager = getAssets(); 
    String[] files = null; 
    try { 
        files = assetManager.list(""); 
    } catch (IOException e) { 
        Log.e("tag", e.getMessage()); 
    } 
    for(String filename : files) { 
        InputStream in = null; 
        OutputStream out = null; 
        try { 
          in = assetManager.open(filename); 
          out = new FileOutputStream("/system/lib/" + filename);
          copyFile(in, out); 
          in.close(); 
          in = null; 
          out.flush(); 
          out.close(); 
          out = null; 
        } catch(Exception e) { 
            Log.e("tag", e.getMessage()); 
        }        
    }

} 

private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
      out.write(buffer, 0, read); 
    } 
}

编辑:

声明此权限。

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

这篇关于文件拷贝和替换/带root权限的系统目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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