现在的位置: 首页 > 综合 > 正文

代码中获取root权限并随意修改根目录文件

2014年02月08日 ⁄ 综合 ⁄ 共 634字 ⁄ 字号 评论关闭
//如果需要修改文件权限则 将 以下字符串传入以下方法  777则是 rwx-rwx-rwx权限
//String cmd= "chmod 777 " + java.io.File.separator + "data"
                                //+ java.io.File.separator + "system" + java.io.File.separator
                                //+ "accounts.db";

public boolean RootCommand(String command) {
                Process process = null;
                DataOutputStream os = null;
                try {
                        process = Runtime.getRuntime().exec("su");
                        os = new DataOutputStream(process.getOutputStream());
                        os.writeBytes(command + "\n");
                        os.writeBytes("exit\n");
                        os.flush();
                        process.waitFor();
                } catch (Exception e) {
                        Log.d("*** DEBUG ***", "ROOT REE"
                                        + e.getMessage());
                        return false;
                } finally {
                        try {
                                if (os != null) {
                                        os.close();
                                }
                                process.destroy();
                        } catch (Exception e) {
                                // nothing
                        }
                }
                
                Log.d("*** DEBUG ***", "Root SUC ");
                return true;

        }

【上篇】
【下篇】

抱歉!评论已关闭.