Android 无法从 adb shell 运行可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12722157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:32:38  来源:igfitidea点击:

Not able to run executable file from adb shell

androidshelladbtcpdump

提问by Harshal Kshatriya

I've added tcpdump binary file to my android device using this command

我已使用此命令将 tcpdump 二进制文件添加到我的 android 设备

./adb push ~/tcpdump-4.2.1/tcpdump /data/local

The binary is added to the android device successfully. But, when I try to execute the tcpdump file from the adb shell, using following commands

二进制文件已成功添加到 android 设备。但是,当我尝试从 adb shell 执行 tcpdump 文件时,使用以下命令

./adb shell
cd data/local
./tcpdump

It gives me this error

它给了我这个错误

/system/bin/sh: ./tcpdump: not executable: magic 7F45

I've also tried changing permissions using chmod 777 tcpdumpbut in vain. How do I overcome this issue? Thanks.

我也尝试过使用更改权限chmod 777 tcpdump但徒劳无功。我如何克服这个问题?谢谢。

采纳答案by Alex Cohn

You can find an Android version of tcpdump here. This build is somewhat outdated, and only relevant for ARM devices. You should follow these instructionsto build the binary from official source.

您可以在此处找到 tcpdump 的 Android 版本。此版本有些过时,仅与 ARM 设备相关。您应该按照这些说明官方来源构建二进制文件。

There are detailed instructionsre how to run tcpdumpon Android. Note that you need a rooted device to begin with.

关于如何在 Android上运行tcpdump 的详细说明。请注意,您需要一个有根的设备才能开始。

回答by Pepelac

You should compile binary files via GCCfrom Android NDK

你应该通过编译的二进制文件GCCAndroid的NDK

回答by G M Ramesh

try the following command:

尝试以下命令:

enter this command c:\ProgramFiles\Android\android-sdk\platform-tools\adb shell tcpdump

输入这个命令 c:\ProgramFiles\Android\android-sdk\platform-tools\adb shell tcpdump

for linux:

对于Linux:

   adb shell chmod 6755 /data/local/tmp/tcpdump

and also go through this link for better understanding:

并通过此链接更好地理解:

http://www.kandroid.org/online-pdk/guide/tcpdump.html

http://www.kandroid.org/online-pdk/guide/tcpdump.html

回答by gguich4rd

I got the same error trying to run another binary into the android emulator. Error came from the compilation.

我在尝试将另一个二进制文件运行到 android 模拟器时遇到了同样的错误。错误来自编译。

You have to cross-compile for an ARM target which means you need a specific toolchain like for example arm-linux-androideabi.

您必须针对 ARM 目标进行交叉编译,这意味着您需要一个特定的工具链,例如 arm-linux-androideabi。

To do so, you need to

为此,您需要

  • export CROSS_COMPILE=arm-linux-androideabi- (your toolchain ending by '-' without gcc)
  • export ARCH=arm
  • add the toolchain to your PATH
  • export CROSS_COMPILE=arm-linux-androideabi-(你的工具链以'-'结尾,没有gcc)
  • 出口 ARCH=臂
  • 将工具链添加到您的 PATH

Then you can run make command. You might want to add -static to the LDFLAGS before building.

然后你可以运行 make 命令。您可能希望在构建之前将 -static 添加到 LDFLAGS。

Finally check your binary has been well compiled by using the file command. You should look for ARM in the printed result.

最后使用 file 命令检查您的二进制文件是否编译良好。您应该在打印结果中查找 ARM。

In case the Makefile doesn't handle CROSS_COMPILE var you can try to make with parameters CC and AR manually set with "$CROSS-COMPILE"gcc and "$CROSS-COMPILE"ar

如果 Makefile 不处理 CROSS_COMPILE var,您可以尝试使用参数 CC 和 AR 手动设置“$CROSS-COMPILE”gcc 和“$CROSS-COMPILE”ar

further details here: http://source.android.com/source/index.html

更多详情:http: //source.android.com/source/index.html