简体   繁体   English

如何在Android中运行已编译的二进制文件?

[英]How do I run a compiled binary in Android?

I've been trying to run a compiled binary in my android phone, but it just keeps telling me "No such file or directory". 我一直在尝试在Android手机中运行已编译的二进制文件,但它一直告诉我“没有这样的文件或目录”。

To be specific, I compiled wificurse , and as the description has mention to an arm command it's obvious that the source code can be compiled for an arm architecture without making any change to the makefile. 具体来说,我编译了wificurse ,正如描述中提到的arm命令,很明显,可以为arm体系结构编译源代码,而无需对makefile进行任何更改。 And so I did the following: 因此,我做了以下工作:

export CROSS_COMPILE=arm-linux-gnueabi-

make CROSS_COMPILE=arm-linux-gnueabi-

And then with the resulting binary (wificurse) I did the following: 然后,使用生成的二进制文件(wificurse),执行以下操作:

adb push wificurse /data

In a root adb shell I did: 在root adb shell中,我做了:

        root@android:/data # chmod 0777 wificurse

Returns nothing; 不返回任何内容; works. 作品。

        root@android:/data # chmod u+x wificurse

Returns "Bad Mode". 返回“错误模式”。

        root@android:/data # busybox chmod 077 wificurse

Returns nothing; 不返回任何内容; works. 作品。

        root@android:/data # busybox chmod u+x wificurse

Returns nothing; 不返回任何内容; works. 作品。

But when I try to run the binary with 但是当我尝试使用

    root@android:/data # ./wificurse

It returns "/system/bin/sh: ./wificurse: No such file or directory". 它返回“ / system / bin / sh:./wificurse:没有这样的文件或目录”。 Did a ls in the folder and the binary is indeed there. 在文件夹中是否有ls,二进制文件确实存在。

Already tried copying the binary to the internal sdcard, then moving to /data (even tried /system/bin and /system/xbin) and it returns "Access denied", but if I chmod the binary it will return the same error (No such file or directory). 已经尝试将二进制文件复制到内部sdcard,然后移动到/ data(甚至尝试过/ system / bin和/ system / xbin),并且返回“访问被拒绝”,但是如果我chmod二进制文件,它将返回相同的错误(否这样的文件或目录)。 Could someone help me, please? 有人可以帮我吗? I've used the linux shell for 2+ years, though I'm completely a noob when it comes to programming stuff. 我已经使用linux shell超过2年了,尽管在编程方面我完全是个菜鸟。 I guess that I'm missing something like a toolchain, I don't know. 我想我不知道像工具链这样的东西。
I'm running Ubuntu 15.10 x64. 我正在运行Ubuntu 15.10 x64。

Your binary apparently depends on some shared library (.so) that is not visible for dynamic linking. 您的二进制文件显然取决于动态共享不可见的某些共享库(.so)。 You can use readelf from your toolchain and you get something like this: 您可以从工具链中使用readelf ,您将获得如下信息:

tom@pc:~/workspace/test/arm-v7a_android9/release$ ~/toolchains/armeabiv7a_android-9_ndk-r10e_gcc-4.9/bin/arm-linux-androideabi-readelf -d test

Dynamic section at offset 0x445a14 contains 27 entries:
  Tag        Type                         Name/Value
 0x00000003 (PLTGOT)                     0x44fc50
 0x00000002 (PLTRELSZ)                   1864 (bytes)
 0x00000017 (JMPREL)                     0x74d24
 0x00000014 (PLTREL)                     REL
 0x00000011 (REL)                        0x74cd4
 0x00000012 (RELSZ)                      80 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000006 (SYMTAB)                     0x8148
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000005 (STRTAB)                     0x26718
 0x0000000a (STRSZ)                      273460 (bytes)
 0x00000004 (HASH)                       0x6934c
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x0000001a (FINI_ARRAY)                 0x447cb8
 0x0000001c (FINI_ARRAYSZ)               12 (bytes)
 0x00000019 (INIT_ARRAY)                 0x447cc4
 0x0000001b (INIT_ARRAYSZ)               324 (bytes)
 0x00000020 (PREINIT_ARRAY)              0x447e08
 0x00000021 (PREINIT_ARRAYSZ)            0x8
 0x0000001e (FLAGS)                      BIND_NOW
 0x6ffffffb (FLAGS_1)                    Flags: NOW
 0x00000000 (NULL)                       0x0

Check that all libraries with type (NEEDED) are on your Android device and are visible for your binary (you should use export LD_LIBRARY_PATH=<path>[:<another_path>[..]] to make .so available for dynamic linking with your binary). 检查所有类型(NEEDED)库都在您的Android设备上并且对您的二进制文件可见(您应使用export LD_LIBRARY_PATH=<path>[:<another_path>[..]]使.so可用于与您的动态链接二进制)。

If problem isn't still resolved, your application is linked with different version of some system library - try to use an older toolchain. 如果问题仍未解决,则您的应用程序已与某些系统库的不同版本链接-尝试使用较旧的工具链。

Did you try the methods in this thread? 您是否尝试过该线程中的方法? "No such file or directory" trying to execute linux binary on Android device “没有这样的文件或目录”试图在Android设备上执行linux二进制文件

An alternative way to solve this problem would be installing KBOX on Android. 解决此问题的另一种方法是在Android上安装KBOX The author has developed tools like gcc, ssh server for the Android platform. 作者为Android平台开发了gcc,ssh服务器等工具。 Therefore, you can start an ssh server on your phone and do all your work on your PC, which means that you can compile your code directly on the phone :) 因此,您可以在手机上启动ssh服务器并在PC上完成所有工作,这意味着您可以直接在手机上编译代码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM