是否有可能运行在一个无根的Andr​​oid手机本机臂二进制? [英] Is it possible to run a native arm binary on a non-rooted android phone?

查看:151
本文介绍了是否有可能运行在一个无根的Andr​​oid手机本机臂二进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我一直在跳水低级别的Andr​​oid编程(原生C / C ++使用codeSourcery工具链)的浑水。我尝试了模拟器上的可执行文件和它的工作。我想尝试一下真正的设备上。所以,我插在我的关系,并推到文件系统中的文件。然后我试图执行二进制,我得到了一个权限错误。这确实不是不管我如何安装它,或者我把它,我不是根源,这不是让我执行它。请问有什么办法可以在一个无根的手机运行的程序是这样?

Well, I've been diving in the murky waters of low-level Android programming (native C/C++ using the CodeSourcery toolchain). I tried out the executable on an emulator and it worked. I'd like to try it out on a real device. So I plugged in my nexus and pushed the files on to the filesystem. Then I tried to execute the binary, and I got a permission error. It really doesn't matter how I mount it, or where I send it, I'm not root and it's not letting me execute it. Is there any way to run a program like this on a non-rooted phone?

推荐答案

使用包含在Android NDK工具链来编译的二进制文件后,就可以将它们与典型的Andr​​oid应用程序包,并让它们产卵子进程。

After using the toolchain included in the Android NDK to compile your binaries, it is possible to package them with a typical Android app and have them spawn as subprocesses.

您将必须包括在您的应用程序的资产文件夹中所有必要的文件。为了运行它们,你必须有程序从资产文件夹将它们复制到一个可运行的位置,如:/data/data/com.yourdomain.yourapp/nativeFolder

You'll have to include all the necessary files within the assets folder of your application. In order to run them, you have to have the program copy them from the assets folder to a runnable location like: /data/data/com.yourdomain.yourapp/nativeFolder

您可以做到这一点,像这样:

You can do this like so:

private static void copyFile(String assetPath, String localPath, Context context) {
    try {
        InputStream in = context.getAssets().open(assetPath);
        FileOutputStream out = new FileOutputStream(localPath);
        int read;
        byte[] buffer = new byte[4096];
        while ((read = in.read(buffer)) > 0) {
            out.write(buffer, 0, read);
        }
        out.close();
        in.close();

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

请记住,assetPath不是绝对的,但相对于资产/.

Keep in mind that the assetPath is not absolute but in respect to assets/.

IE:资产/ nativeFolder只是nativeFolder

IE: "assets/nativeFolder" is just "nativeFolder"

要那么运行应用程序并读取它的输出,你可以做这样的事情:

To then run your application and read its output you could do something like this:

  Process nativeApp = Runtime.getRuntime().exec("/data/data/com.yourdomain.yourapp/nativeFolder/application");


            BufferedReader reader = new BufferedReader(new InputStreamReader(nativeApp.getInputStream()));
            int read;
            char[] buffer = new char[4096];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
            }
            reader.close();

            // Waits for the command to finish.
            nativeApp.waitFor();

            String nativeOutput =  output.toString();

这篇关于是否有可能运行在一个无根的Andr​​oid手机本机臂二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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