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,630
  • 11
  • 44
  • 60
  • what error does chmod gives you? you could push it to sdcard, chmod it there, then move it (i suppose). are you root? – njzk2 Oct 04 '12 at 07:25
  • I use android terminal emulator. It comes with busybox which has tcpdump – Sharun Oct 04 '12 at 07:45
  • @Pepelac I compiled it on my ubuntu desktop using these commands ./configure, make, sudo make install. Then I pushed the tcpdump file on the android device. – Harshal Kshatriya Oct 04 '12 at 08:52
  • @njzk2 chmod on my desktop and on the adb shell does not give me any error. It executes well. – Harshal Kshatriya Oct 04 '12 at 08:53
  • 1
    @HarshalKshatriya Yep and it's not helps. Because you can't run on android files that was compiled with standart GCC. You should use it from NDK to compile 32bit ELF file... – Laser Oct 04 '12 at 09:29
  • @Pepelac I've tried to build binary for tcpdump using cross compiler provided by ndk but still in vain. I used these commands ./configure CC=path/to/arm-gcc , but it fails. Your help would be appreciated. – Harshal Kshatriya Oct 04 '12 at 14:32
  • Right now using the binary from this blog as a quick fix. http://nerdjusttyped.blogspot.in/2009/03/android-binary-solo.html – Harshal Kshatriya Oct 04 '12 at 15:52
  • related: http://stackoverflow.com/questions/9868309/how-can-i-run-c-binary-executable-file-in-android-from-android-shell – Ciro Santilli OurBigBook.com Feb 28 '16 at 13:22

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
  • 56,089
  • 9
  • 113
  • 307
  • 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,652
  • 8
  • 54
  • 85
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,420
  • 9
  • 37
  • 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