从有根的Andr​​oid应用程序运行的二进制 [英] Run binary from with root Android Application

查看:181
本文介绍了从有根的Andr​​oid应用程序运行的二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个二进制的的/ dev /本地命名原生(我把它通过ADB),具有root权限。 为了做到这一点,我写了下面code:

I want to run a binary at /dev/local named native(I pushed it through adb), with root permission. In order to achieve that, I wrote the following code:

    try {
        root=Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(root.getOutputStream());
        DataInputStream osRes = new DataInputStream(root.getInputStream());
        os.writeBytes("/data/local/native\n");
        os.flush();
        TextView output=(TextView)findViewById(R.id.textview);
        output.append(osRes.readLine());
        root.waitFor();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show();
    }

这给了我一个 NullPointerException异常。所以,我试图将其更改为:

This gave me a NullPointerException.So, I tried changing it to:

    try{
        root=Runtime.getRuntime().exec("su");
        root.waitFor();
        DataOutputStream os = new DataOutputStream(root.getOutputStream());
        DataInputStream osRes = new DataInputStream(root.getInputStream());
        os.writeBytes("/data/local/native\n");
        os.flush();
        TextView output=(TextView)findViewById(R.id.textview);
        output.append(osRes.readLine());
        root.waitFor();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show();
    }

有了这个,我得到BrokenPipe错误。

With this I get BrokenPipe error.

请帮帮我,我想运行具有root权限的二进制文件,有没有另一种方式或者是什么,我做错了什么?

Kindly help me, I want to run a binary with root privileges, is there any alternative way or what is it that I am doing wrong?

推荐答案

尝试运行苏-c /路径/要/执行

这篇关于从有根的Andr​​oid应用程序运行的二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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