编译适用于Android-ARM架构的tcpdump工具

零、准备工作

  1. 安装 Debian 7.8 X86_64
  2. 准备一台有root权限的Android手机
  3. 用root账户登录Debian系统

一、安装交叉编译工具链

1. 安装Emdebian软件仓库的GPG密钥

  1. apt-get install emdebian-archive-keyring

2. 安装Emdebian需要的Squeeze依赖

  1. apt-get install flex
  2. apt-get install byacc
  3. apt-get install make
  4. vi /etc/apt/sources.list

在上述文件最后添加如下内容:

  1. deb http://ftp.us.debian.org/debian/ squeeze main
  2. deb http://security.debian.org/ squeeze/updates main
  3. deb http://www.emdebian.org/debian/ squeeze main

注意:

第一行启用Debian Squeeze的软件仓库,以便于满足Emdebian工具链的依赖;
第二行启用Debian Squeeze的安全更新仓库;
第三行启用Emdebian的软件仓库。

3. 同步Debian软件包的索引文件

  1. apt-get update

4. 安装ARM GNU C++编译器

  1. apt-get install g++-4.4-arm-linux-gnueabi

5. 检查交叉编译器是否安装成功

  1. arm-linux-gnueabi-gcc --version

若上述命令的返回如下所示,则表示安装成功:

二、交叉编译TCPDUMP

1. 下载libpcap和tcpdump的源码包

  1. cd /root/Downloads
  2. wget http://www.tcpdump.org/release/tcpdump-4.7.4.tar.gz
  3. wget http://www.tcpdump.org/release/libpcap-1.7.3.tar.gz

2. 解压缩源码包

  1. tar xvzf libpcap-1.7.3.tar.gz
  2. tar xvzf tcpdump-4.7.4.tar.gz

3. 编译libpcap

  1. cd libpcap-1.7.3
  2. export CC=arm-linux-gnueabi-gcc
  3. ./configure --host=arm-linux --with-pcap=linux
  4. make
  5. cd ..

4. 编译tcpdump

  1. cd tcpdump-4.7.4
  2. export ac_cv_linux_vers=3
  3. export CFLAGS=-static
  4. export CPPFLAGS=-static
  5. export LDFLAGS=-static
  6. ./configure --host=arm-linux --disable-ipv6
  7. make

5. 检查编译是否成功

  1. file tcpdump

若上述命令的输出如下图所示,则表明编译成功:

6. 压缩可执行文件

  1. arm-linux-gnueabi-strip tcpdump

这一步可以将可执行文件的体积减少将近40%

三、安装和执行tcpdump

1. 安装ADB(Android Debug Bridge)软件包

  1. apt-get install android-tools-adb

2. 打开手机的USB调试功能

这个步骤每种手机可能各不相同,请参考对应型号手机的帮助文档
若手机没有完全root,则需要安装adbd.apk应用。

3. 检查手机是否连接成功

  1. adb devices

若上述命令的输出如下图所示,则表明手机已经成功连接:

4. 重新启动ADB后台

  1. adb root
  2. adb remount

注意:

第一条命令会以root账户重新启动ADB后台程序;
第二条命令会将/system分区以/read/write模式重新挂载

5. 检查ADB后台是否成功重新启动

  1. adb shell id

若上述命令的输出如下图所示,则表示ADB后台程序重新启动成功:

6. 上传tcpdump可执行文件

  1. cd /root/Downloads/tcpdump-4.7.4
  2. adb push tcpdump /system/xbin/

7. 检查tcpdump是否安装成功

  1. adb shell tcpdump -h

若上述命令的输出如下图所示,则表示tcpdump已经在手机上安装成功:

Beck – Beautiful Way

Searchlights on the skyline
Just looking for a friend
Who’s gonna love my baby
When she’s gone around the bend
Egyptian bells are ringing
When it’s her birthday
Sweet nothin’, I’m talking about you
There’s a hurricane blowing your way
Ooh such a beautiful way
To break your heart
Ooh such a beautiful way
To break my heart
There’s someone calling your name
It’s driving you insane
You were wearing that stained raincoat
And your umbrella was a tangled mess
You were washed up on the glittering shoals
Looking for another crime to confess
You bribed yourself
Out of a place in the sun
But you had some change to spare
So you said you wanna spend it on me
And shook the blues out of your hair
Ooh such a beautiful way
To break your heart
Ooh such a beautiful way
To break my heart
There’s someone calling her name
You’re gonna miss that train
Ooh such a beautiful way
To break your heart
Ooh such a beautiful way To break my heart
There’s someone calling her name