5

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

./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

./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 tcpdump but in vain. How do I overcome this issue? Thanks.

Harshal Kshatriya
  • 5,290
  • 9
  • 42
  • 58

4 Answers4

4

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

There are detailed instructions re how to run tcpdump on Android. Note that you need a rooted device to begin with.

Alex Cohn
  • 54,176
  • 9
  • 103
  • 290
  • 1
    Also, check this link. Part of it explains how to build binary for arm device using the source. Great help. http://codeseekah.com/2012/08/07/port-forwarding-an-android-local-port/ – Harshal Kshatriya Oct 05 '12 at 04:03
  • 1
    The linked build of tcpdump is version 4.0 which is a bit old. You can download an ARM build of version 4.3 here: http://omappedia.org/wiki/File:Tcpdump-4.3.0-arm.tar.gz – georgiecasey Jun 20 '13 at 02:31
1

You should compile binary files via GCC from Android NDK

Laser
  • 6,291
  • 7
  • 49
  • 78
1

try the following command:

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

for 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

G M Ramesh
  • 3,382
  • 9
  • 35
  • 53
0

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

You have to cross-compile for an ARM target which means you need a specific toolchain like for example 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

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

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

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

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