Skip to content

Commit 64533ab

Browse files
Add files
1 parent 82446b0 commit 64533ab

File tree

5 files changed

+986
-1
lines changed

5 files changed

+986
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
# tcpdump-android-builds
1+
# Tcpdump Android Builds
2+
3+
Precompiled Tcpdump binaries for Android are provided for ARM, ARM64, X86, X86-64. Download from [releases](https://github.com/extremecoders-re/tcpdump-android-builds/releases).
4+
5+
```
6+
Tcpdump version: 4.9.2
7+
Libpcap version: 1.9.0
8+
Android API: 23
9+
NDK: android-ndk-r18b
10+
```
11+
12+
## Compilation Steps
13+
14+
1. Download the Android NDK from https://developer.android.com/ndk/downloads/. The latest available at the time of writing is `ndk-r18b`.
15+
Extract the zip to a suitable location.
16+
17+
```
18+
$ wget https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip
19+
```
20+
21+
2. Clone the repository
22+
23+
```
24+
$ git clone https://github.com/extremecoders-re/tcpdump-android-builds.git
25+
$ cd tcpdump-android-builds
26+
```
27+
28+
3. For compiling, set `NDK` to the location of the android sdk directory and run the corresponding build script.
29+
```
30+
$ NDK=/home/ubuntu/workspace/android-ndk-r18b/ ./build_x86.sh
31+
$ NDK=/home/ubuntu/workspace/android-ndk-r18b/ ./build_x86_64.sh
32+
$ NDK=/home/ubuntu/workspace/android-ndk-r18b/ ./build_arm.sh
33+
$ NDK=/home/ubuntu/workspace/android-ndk-r18b/ ./build_arm64.sh
34+
```
35+
36+
4. Compiled binaries will be located in the corresponding `tcpdumpbuild` directory.
37+
38+
## How to use tcpdump?
39+
40+
- https://www.tcpdump.org/manpages/tcpdump.1.html
41+
- https://www.andreafortuna.org/technology/android/how-to-install-and-run-tcpdump-on-android-devices/
42+
43+
## References
44+
45+
- https://github.com/eakteam/tcpdump-android
46+
- https://github.com/chatch/tcpdump-android
47+
- https://github.com/imrivera/build-android-tcpdump
48+
- https://developer.android.com/ndk/guides/standalone_toolchain

build_arm.sh

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
#!/bin/bash
2+
3+
tcpdump_ver=4.9.2
4+
libpcap_ver=1.9.0
5+
android_api_def=23
6+
toolchain_arch=arm
7+
toolchain_dir=toolchain_arm
8+
ndk_dir_def=android-ndk-r18b
9+
10+
#-------------------------------------------------------#
11+
12+
tcpdump_dir=tcpdump-${tcpdump_ver}
13+
libpcap_dir=libpcap-${libpcap_ver}
14+
15+
16+
if [ ${NDK} ]
17+
then
18+
ndk_dir=${NDK}
19+
else
20+
ndk_dir=${ndk_dir_def}
21+
fi
22+
23+
ndk_dir=`readlink -f ${ndk_dir}`
24+
25+
if [ ${ANDROID_API} ]
26+
then
27+
android_api=${ANDROID_API}
28+
else
29+
android_api=${android_api_def}
30+
fi
31+
32+
echo "_______________________"
33+
echo ""
34+
echo "NDK - ${ndk_dir}"
35+
echo "Android API: ${android_api}"
36+
echo "_______________________"
37+
38+
39+
exit_error()
40+
{
41+
echo " _______"
42+
echo "| |"
43+
echo "| ERROR |"
44+
echo "|_______|"
45+
exit 1
46+
}
47+
48+
{
49+
if [ $# -ne 0 ]
50+
then
51+
if [ -d $1 ]
52+
then
53+
cd $1
54+
else
55+
echo directory $1 not found
56+
exit_error
57+
fi
58+
else
59+
mkdir tcpdumpbuild-${toolchain_arch}
60+
cd tcpdumpbuild-${toolchain_arch}
61+
fi
62+
}
63+
64+
65+
66+
{
67+
echo " ____________________"
68+
echo "| |"
69+
echo "| TOOLCHAIN |"
70+
echo "|____________________|"
71+
72+
if [ -d "$toolchain_dir" ]
73+
then
74+
echo Toolchain already exist! Nothing to do.
75+
else
76+
echo Creating toolchain...
77+
mkdir $toolchain_dir
78+
python ${ndk_dir}/build/tools/make_standalone_toolchain.py \
79+
--arch=${toolchain_arch} \
80+
--api=${android_api} \
81+
--install-dir=${toolchain_dir} \
82+
--force
83+
84+
if [ $? -ne 0 ]
85+
then
86+
rm -fr $toolchain_dir
87+
exit_error
88+
fi
89+
fi
90+
91+
export PATH=`pwd`/$toolchain_dir/bin:$PATH
92+
93+
target_host=arm-linux-androideabi
94+
export AR=$target_host-ar
95+
export AS=$target_host-clang
96+
export CC=$target_host-clang
97+
export CXX=$target_host-clang++
98+
export LD=$target_host-ld
99+
export STRIP=$target_host-strip
100+
export RANLIB=$target_host-ranlib
101+
export STRIP=$target_host-strip
102+
export CFLAGS="-static -O2 -fPIE -fPIC -march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=vfpv3-d16 -mfpu=neon"
103+
export LDFLAGS="-pie"
104+
}
105+
106+
# download & untar libpcap + tcpdump
107+
{
108+
echo " _______________________________"
109+
echo "| |"
110+
echo "| DOWNLOADING LIBPCAP & TCPDUMP |"
111+
echo "|_______________________________|"
112+
113+
tcpdump_file=${tcpdump_dir}.tar.gz
114+
libpcap_file=${libpcap_dir}.tar.gz
115+
tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file}
116+
libpcap_link=http://www.tcpdump.org/release/${libpcap_file}
117+
118+
if [ -f ${tcpdump_file} ]
119+
then
120+
echo ${tcpdump_file} already downloaded! Nothing to do.
121+
else
122+
echo Download ${tcpdump_file}...
123+
wget ${tcpdump_link}
124+
if [ ! -f ${tcpdump_file} ]
125+
then
126+
exit_error
127+
fi
128+
fi
129+
130+
if [ -f ${libpcap_file} ]
131+
then
132+
echo ${libpcap_file} already downloaded! Nothing to do.
133+
else
134+
echo Download ${libpcap_file}...
135+
wget ${libpcap_link}
136+
if [ ! -f ${libpcap_file} ]
137+
then
138+
exit_error
139+
fi
140+
fi
141+
142+
if [ -d ${tcpdump_dir} ]
143+
then
144+
echo ${tcpdump_dir} directory already exist! Nothing to do.
145+
else
146+
echo untar ${tcpdump_file}
147+
tar -zxf ${tcpdump_file}
148+
fi
149+
150+
if [ -d ${libpcap_dir} ]
151+
then
152+
echo ${libpcap_dir} directory already exist! Nothing to do.
153+
else
154+
echo untar ${libpcap_file}
155+
tar -zxf ${libpcap_file}
156+
fi
157+
}
158+
159+
# build libpcap
160+
{
161+
cd ${libpcap_dir}
162+
163+
echo " _____________________"
164+
echo "| |"
165+
echo "| CONFIGURING LIBPCAP |"
166+
echo "|_____________________|"
167+
168+
chmod +x configure
169+
./configure --host=arm-linux-androideabi --with-pcap=linux
170+
171+
if [ $? -ne 0 ]
172+
then
173+
exit_error
174+
fi
175+
176+
echo " __________________"
177+
echo "| |"
178+
echo "| BUILDING LIBPCAP |"
179+
echo "|__________________|"
180+
181+
chmod +x runlex.sh
182+
make
183+
184+
if [ $? -ne 0 ]
185+
then
186+
exit_error
187+
fi
188+
189+
cd ..
190+
}
191+
192+
# build tcpdump
193+
{
194+
cd ${tcpdump_dir}
195+
196+
echo " _____________________"
197+
echo "| |"
198+
echo "| CONFIGURING TCPDUMP |"
199+
echo "|_____________________|"
200+
201+
chmod +x configure
202+
./configure --host=arm-linux-androideabi --with-pcap=linux
203+
204+
if [ $? -ne 0 ]
205+
then
206+
exit_error
207+
fi
208+
209+
echo " __________________"
210+
echo "| |"
211+
echo "| BUILDING TCPDUMP |"
212+
echo "|__________________|"
213+
214+
#setprotoent endprotoen not supported on android
215+
sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c
216+
sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c
217+
218+
#NBBY is not defined => FORCE definition
219+
make #CFLAGS=-DNBBY=8 # for tcpdump < 4.2.1 (CFLAGS refefined in Makefile) => just make
220+
221+
if [ $? -ne 0 ]
222+
then
223+
exit_error
224+
fi
225+
226+
cd ..
227+
}
228+
229+
mv ${tcpdump_dir}/tcpdump tcpdump-${toolchain_arch}
230+
chmod +x tcpdump-${toolchain_arch}
231+
232+
echo " __________________"
233+
echo "| |"
234+
echo "| TCPDUMP IS READY |"
235+
echo "|__________________|"
236+
echo `pwd`/tcpdump-${toolchain_arch}

0 commit comments

Comments
 (0)