├── .gitignore ├── LICENSE ├── README.md ├── build_arm.sh ├── build_arm64.sh ├── build_libpcap_all.sh ├── build_x86.sh └── build_x86_64.sh /.gitignore: -------------------------------------------------------------------------------- 1 | tcpdumpbuild*/** 2 | libpcap_all_targets/** 3 | venv/** 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 | Default android API: 23 9 | ``` 10 | 11 | ## Compilation Steps 12 | 13 | 1. Download the Android NDK from https://developer.android.com/ndk/downloads/. 14 | Extract the zip to a suitable location. 15 | 16 | ``` 17 | $ wget https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip 18 | ``` 19 | 20 | 2. Clone the repository 21 | 22 | ``` 23 | $ git clone https://github.com/extremecoders-re/tcpdump-android-builds.git 24 | $ cd tcpdump-android-builds 25 | ``` 26 | 27 | 3. For compiling, set `NDK` to the location of the android sdk directory and run the corresponding build script. 28 | ``` 29 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_x86.sh 30 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_x86_64.sh 31 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_arm.sh 32 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_arm64.sh 33 | ``` 34 | 35 | 4. Compiled binaries will be located in the corresponding `tcpdumpbuild` directory. 36 | 37 | 38 | ## Compile libpcap for multiple targets and API versions 39 | 40 | You can use the `build_libpcap_all.sh` script to run the scripts mentioned above for multiple targets and Android API versions. 41 | This can be useful if you need to buid libpcap for multiple targets / API versions. 42 | 43 | 1. Run the script `build_libpcap_all.sh` and set `NDK` to the location of the android sdk directory. 44 | 45 | 2. You can also specify the following parameters: 46 | 47 | - `OUTPUT_DIR` for the output directory. The default is `libpcap_all_targets`. 48 | - `TARGETS` one or more targets from this list: `arm arm64 x86 x86_64`. The default is all of them. 49 | - `API_MIN` min API version. The default is 21. 50 | - `API_MAX` max API version. The default is 30. 51 | 52 | 3. Examples: 53 | ``` 54 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ ./build_libpcap_all.sh 55 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ OUTPUT_DIR=my_dir ./build_libpcap_all.sh 56 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ TARGETS="x86 x86_64" ./build_libpcap_all.sh 57 | $ NDK=/home/ubuntu/workspace/android-ndk-rxxx/ API_MIN=21 API_MAX=30 /build_libpcap_all.sh 58 | ``` 59 | 60 | ## How to use tcpdump? 61 | 62 | - https://www.tcpdump.org/manpages/tcpdump.1.html 63 | - https://www.andreafortuna.org/technology/android/how-to-install-and-run-tcpdump-on-android-devices/ 64 | 65 | ## References 66 | 67 | - https://github.com/eakteam/tcpdump-android 68 | - https://github.com/chatch/tcpdump-android 69 | - https://github.com/imrivera/build-android-tcpdump 70 | - https://developer.android.com/ndk/guides/standalone_toolchain -------------------------------------------------------------------------------- /build_arm.sh: -------------------------------------------------------------------------------- 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_armv7a 8 | 9 | #-------------------------------------------------------# 10 | 11 | tcpdump_dir=tcpdump-${tcpdump_ver} 12 | libpcap_dir=libpcap-${libpcap_ver} 13 | 14 | 15 | exit_error() 16 | { 17 | echo " _______" 18 | echo "| |" 19 | echo "| ERROR |" 20 | echo "|_______|" 21 | exit 1 22 | } 23 | 24 | if [ ${NDK} ] 25 | then 26 | ndk_dir=${NDK} 27 | else 28 | echo Please specify NDK path 29 | exit_error 30 | fi 31 | 32 | ndk_dir=`readlink -f ${ndk_dir}` 33 | 34 | if [ ${ANDROID_API} ] 35 | then 36 | android_api=${ANDROID_API} 37 | else 38 | android_api=${android_api_def} 39 | fi 40 | 41 | echo "_______________________" 42 | echo "" 43 | echo "NDK - ${ndk_dir}" 44 | echo "Android API: ${android_api}" 45 | echo "_______________________" 46 | 47 | { 48 | if [ $# -ne 0 ] 49 | then 50 | if [ -d $1 ] 51 | then 52 | cd $1 53 | else 54 | echo directory $1 not found 55 | exit_error 56 | fi 57 | else 58 | mkdir tcpdumpbuild-${toolchain_arch} 59 | cd tcpdumpbuild-${toolchain_arch} 60 | fi 61 | } 62 | 63 | 64 | 65 | { 66 | echo " ____________________" 67 | echo "| |" 68 | echo "| TOOLCHAIN |" 69 | echo "|____________________|" 70 | 71 | toolchain_dir=$ndk_dir/toolchains/llvm/prebuilt/linux-x86_64 72 | export sysroot=$toolchain_dir/sysroot 73 | export PATH=$toolchain_dir/bin:$PATH 74 | 75 | target_host=armv7a-linux-androideabi 76 | target_host_with_api=$target_host$android_api 77 | export AR=llvm-ar 78 | export AS=$target_host_with_api-clang 79 | export CC=$target_host_with_api-clang 80 | export CXX=$target_host_with_api-clang++ 81 | export LD=$target_host-ld 82 | export STRIP=$target_host-strip 83 | export RANLIB=arm-linux-androideabi-ranlib 84 | export STRIP=$target_host-strip 85 | export CFLAGS="-static -O2 -fPIE -fPIC -march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=vfpv3-d16 -mfpu=neon --sysroot=$sysroot" 86 | export LDFLAGS="-pie --sysroot=$sysroot" 87 | } 88 | 89 | # download & untar libpcap + tcpdump 90 | { 91 | echo " _______________________________" 92 | echo "| |" 93 | echo "| DOWNLOADING LIBPCAP & TCPDUMP |" 94 | echo "|_______________________________|" 95 | 96 | tcpdump_file=${tcpdump_dir}.tar.gz 97 | libpcap_file=${libpcap_dir}.tar.gz 98 | tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file} 99 | libpcap_link=http://www.tcpdump.org/release/${libpcap_file} 100 | 101 | if [ -f ${tcpdump_file} ] 102 | then 103 | echo ${tcpdump_file} already downloaded! Nothing to do. 104 | else 105 | echo Download ${tcpdump_file}... 106 | wget ${tcpdump_link} 107 | if [ ! -f ${tcpdump_file} ] 108 | then 109 | exit_error 110 | fi 111 | fi 112 | 113 | if [ -f ${libpcap_file} ] 114 | then 115 | echo ${libpcap_file} already downloaded! Nothing to do. 116 | else 117 | echo Download ${libpcap_file}... 118 | wget ${libpcap_link} 119 | if [ ! -f ${libpcap_file} ] 120 | then 121 | exit_error 122 | fi 123 | fi 124 | 125 | if [ -d ${tcpdump_dir} ] 126 | then 127 | echo ${tcpdump_dir} directory already exist! Nothing to do. 128 | else 129 | echo untar ${tcpdump_file} 130 | tar -zxf ${tcpdump_file} 131 | fi 132 | 133 | if [ -d ${libpcap_dir} ] 134 | then 135 | echo ${libpcap_dir} directory already exist! Nothing to do. 136 | else 137 | echo untar ${libpcap_file} 138 | tar -zxf ${libpcap_file} 139 | fi 140 | } 141 | 142 | # build libpcap 143 | { 144 | cd ${libpcap_dir} 145 | 146 | echo " _____________________" 147 | echo "| |" 148 | echo "| CONFIGURING LIBPCAP |" 149 | echo "|_____________________|" 150 | 151 | chmod +x configure 152 | ./configure --host=armv7a-linux-androideabi --with-pcap=linux 153 | 154 | if [ $? -ne 0 ] 155 | then 156 | exit_error 157 | fi 158 | 159 | echo " __________________" 160 | echo "| |" 161 | echo "| BUILDING LIBPCAP |" 162 | echo "|__________________|" 163 | 164 | chmod +x runlex.sh 165 | make 166 | 167 | if [ $? -ne 0 ] 168 | then 169 | exit_error 170 | fi 171 | 172 | cd .. 173 | } 174 | 175 | # build tcpdump 176 | { 177 | cd ${tcpdump_dir} 178 | 179 | echo " _____________________" 180 | echo "| |" 181 | echo "| CONFIGURING TCPDUMP |" 182 | echo "|_____________________|" 183 | 184 | chmod +x configure 185 | ./configure --host=armv7a-linux-androideabi --with-pcap=linux 186 | 187 | if [ $? -ne 0 ] 188 | then 189 | exit_error 190 | fi 191 | 192 | echo " __________________" 193 | echo "| |" 194 | echo "| BUILDING TCPDUMP |" 195 | echo "|__________________|" 196 | 197 | #setprotoent endprotoen not supported on android 198 | sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c 199 | sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c 200 | 201 | #NBBY is not defined => FORCE definition 202 | make #CFLAGS=-DNBBY=8 # for tcpdump < 4.2.1 (CFLAGS refefined in Makefile) => just make 203 | 204 | if [ $? -ne 0 ] 205 | then 206 | exit_error 207 | fi 208 | 209 | cd .. 210 | } 211 | 212 | mv ${tcpdump_dir}/tcpdump tcpdump-${toolchain_arch} 213 | chmod +x tcpdump-${toolchain_arch} 214 | 215 | echo " __________________" 216 | echo "| |" 217 | echo "| TCPDUMP IS READY |" 218 | echo "|__________________|" 219 | echo `pwd`/tcpdump-${toolchain_arch} 220 | -------------------------------------------------------------------------------- /build_arm64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tcpdump_ver=4.9.2 4 | libpcap_ver=1.9.0 5 | android_api_def=23 6 | toolchain_arch=arm64 7 | toolchain_dir=toolchain_arm64 8 | 9 | #-------------------------------------------------------# 10 | 11 | tcpdump_dir=tcpdump-${tcpdump_ver} 12 | libpcap_dir=libpcap-${libpcap_ver} 13 | 14 | 15 | exit_error() 16 | { 17 | echo " _______" 18 | echo "| |" 19 | echo "| ERROR |" 20 | echo "|_______|" 21 | exit 1 22 | } 23 | 24 | if [ ${NDK} ] 25 | then 26 | ndk_dir=${NDK} 27 | else 28 | echo Please specify NDK path 29 | exit_error 30 | fi 31 | 32 | ndk_dir=`readlink -f ${ndk_dir}` 33 | 34 | if [ ${ANDROID_API} ] 35 | then 36 | android_api=${ANDROID_API} 37 | else 38 | android_api=${android_api_def} 39 | fi 40 | 41 | echo "_______________________" 42 | echo "" 43 | echo "NDK - ${ndk_dir}" 44 | echo "Android API: ${android_api}" 45 | echo "_______________________" 46 | 47 | { 48 | if [ $# -ne 0 ] 49 | then 50 | if [ -d $1 ] 51 | then 52 | cd $1 53 | else 54 | echo directory $1 not found 55 | exit_error 56 | fi 57 | else 58 | mkdir tcpdumpbuild-${toolchain_arch} 59 | cd tcpdumpbuild-${toolchain_arch} 60 | fi 61 | } 62 | 63 | 64 | 65 | { 66 | echo " ____________________" 67 | echo "| |" 68 | echo "| TOOLCHAIN |" 69 | echo "|____________________|" 70 | 71 | toolchain_dir=$ndk_dir/toolchains/llvm/prebuilt/linux-x86_64 72 | export sysroot=$toolchain_dir/sysroot 73 | export PATH=$toolchain_dir/bin:$PATH 74 | 75 | target_host=aarch64-linux-android 76 | target_host_with_api=$target_host$android_api 77 | export AR=llvm-ar 78 | export AS=$target_host_with_api-clang 79 | export CC=$target_host_with_api-clang 80 | export CXX=$target_host_with_api-clang++ 81 | export LD=$target_host-ld 82 | export STRIP=$target_host-strip 83 | export RANLIB=$target_host-ranlib 84 | export STRIP=$target_host-strip 85 | export CFLAGS="-static -O2 -fPIE -fPIC -march=armv8-a --sysroot=$sysroot" 86 | export LDFLAGS="-pie --sysroot=$sysroot" 87 | } 88 | 89 | # download & untar libpcap + tcpdump 90 | { 91 | echo " _______________________________" 92 | echo "| |" 93 | echo "| DOWNLOADING LIBPCAP & TCPDUMP |" 94 | echo "|_______________________________|" 95 | 96 | tcpdump_file=${tcpdump_dir}.tar.gz 97 | libpcap_file=${libpcap_dir}.tar.gz 98 | tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file} 99 | libpcap_link=http://www.tcpdump.org/release/${libpcap_file} 100 | 101 | if [ -f ${tcpdump_file} ] 102 | then 103 | echo ${tcpdump_file} already downloaded! Nothing to do. 104 | else 105 | echo Download ${tcpdump_file}... 106 | wget ${tcpdump_link} 107 | if [ ! -f ${tcpdump_file} ] 108 | then 109 | exit_error 110 | fi 111 | fi 112 | 113 | if [ -f ${libpcap_file} ] 114 | then 115 | echo ${libpcap_file} already downloaded! Nothing to do. 116 | else 117 | echo Download ${libpcap_file}... 118 | wget ${libpcap_link} 119 | if [ ! -f ${libpcap_file} ] 120 | then 121 | exit_error 122 | fi 123 | fi 124 | 125 | if [ -d ${tcpdump_dir} ] 126 | then 127 | echo ${tcpdump_dir} directory already exist! Nothing to do. 128 | else 129 | echo untar ${tcpdump_file} 130 | tar -zxf ${tcpdump_file} 131 | fi 132 | 133 | if [ -d ${libpcap_dir} ] 134 | then 135 | echo ${libpcap_dir} directory already exist! Nothing to do. 136 | else 137 | echo untar ${libpcap_file} 138 | tar -zxf ${libpcap_file} 139 | fi 140 | } 141 | 142 | # build libpcap 143 | { 144 | cd ${libpcap_dir} 145 | 146 | echo " _____________________" 147 | echo "| |" 148 | echo "| CONFIGURING LIBPCAP |" 149 | echo "|_____________________|" 150 | 151 | chmod +x configure 152 | ./configure --host=aarch64-linux-android --with-pcap=linux 153 | 154 | if [ $? -ne 0 ] 155 | then 156 | exit_error 157 | fi 158 | 159 | echo " __________________" 160 | echo "| |" 161 | echo "| BUILDING LIBPCAP |" 162 | echo "|__________________|" 163 | 164 | chmod +x runlex.sh 165 | make 166 | 167 | if [ $? -ne 0 ] 168 | then 169 | exit_error 170 | fi 171 | 172 | cd .. 173 | } 174 | 175 | # build tcpdump 176 | { 177 | cd ${tcpdump_dir} 178 | 179 | echo " _____________________" 180 | echo "| |" 181 | echo "| CONFIGURING TCPDUMP |" 182 | echo "|_____________________|" 183 | 184 | chmod +x configure 185 | ./configure --host=aarch64-linux-android --with-pcap=linux 186 | 187 | if [ $? -ne 0 ] 188 | then 189 | exit_error 190 | fi 191 | 192 | echo " __________________" 193 | echo "| |" 194 | echo "| BUILDING TCPDUMP |" 195 | echo "|__________________|" 196 | 197 | sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c 198 | sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c 199 | 200 | make 201 | 202 | if [ $? -ne 0 ] 203 | then 204 | exit_error 205 | fi 206 | 207 | cd .. 208 | } 209 | 210 | mv ${tcpdump_dir}/tcpdump tcpdump-${toolchain_arch} 211 | chmod +x tcpdump-${toolchain_arch} 212 | 213 | echo " __________________" 214 | echo "| |" 215 | echo "| TCPDUMP IS READY |" 216 | echo "|__________________|" 217 | echo `pwd`/tcpdump-${toolchain_arch} 218 | -------------------------------------------------------------------------------- /build_libpcap_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | output_dir=libpcap_all_targets 4 | android_targets="arm arm64 x86 x86_64" 5 | android_api_min=21 6 | android_api_max=30 7 | 8 | if [ ${OUTPUT_DIR} ] 9 | then 10 | output_dir=${OUTPUT_DIR} 11 | fi 12 | 13 | if [ ${TARGETS} ] 14 | then 15 | android_targets=${TARGETS} 16 | fi 17 | 18 | if [ ${API_MIN} ] 19 | then 20 | android_api_min=${API_MIN} 21 | fi 22 | 23 | if [ ${API_MAX} ] 24 | then 25 | android_api_max=${API_MAX} 26 | fi 27 | 28 | echo "________________________________________" 29 | echo "" 30 | echo "Output dir : ${output_dir}" 31 | echo "Targets : ${android_targets}" 32 | echo "Android API: ${android_api_min}..${android_api_max}" 33 | echo "________________________________________" 34 | 35 | read -p "Press enter to start or ctrl+c to abort" 36 | 37 | rm -rf ${output_dir} 38 | 39 | for android_target in ${android_targets} 40 | do 41 | for android_api in $(eval echo {${android_api_min}..${android_api_max}}) 42 | do 43 | rm -rf tcpdumpbuild-${android_target}/ 44 | ANDROID_API=${android_api} ./build_${android_target}.sh || continue 45 | dest_dir=${output_dir}/${android_target}/${android_api} 46 | mkdir -p ${dest_dir} 47 | cp tcpdumpbuild-${android_target}/libpcap-1.9.0/libpcap.a ${dest_dir} 48 | echo "**** DONE ${dest_dir} ****" 49 | done 50 | done 51 | -------------------------------------------------------------------------------- /build_x86.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tcpdump_ver=4.9.2 4 | libpcap_ver=1.9.0 5 | android_api_def=23 6 | toolchain_arch=x86 7 | toolchain_dir=toolchain_x86 8 | 9 | #-------------------------------------------------------# 10 | 11 | tcpdump_dir=tcpdump-${tcpdump_ver} 12 | libpcap_dir=libpcap-${libpcap_ver} 13 | 14 | 15 | exit_error() 16 | { 17 | echo " _______" 18 | echo "| |" 19 | echo "| ERROR |" 20 | echo "|_______|" 21 | exit 1 22 | } 23 | 24 | if [ ${NDK} ] 25 | then 26 | ndk_dir=${NDK} 27 | else 28 | echo Please specify NDK path 29 | exit_error 30 | fi 31 | 32 | ndk_dir=`readlink -f ${ndk_dir}` 33 | 34 | if [ ${ANDROID_API} ] 35 | then 36 | android_api=${ANDROID_API} 37 | else 38 | android_api=${android_api_def} 39 | fi 40 | 41 | echo "_______________________" 42 | echo "" 43 | echo "NDK - ${ndk_dir}" 44 | echo "Android API: ${android_api}" 45 | echo "_______________________" 46 | 47 | { 48 | if [ $# -ne 0 ] 49 | then 50 | if [ -d $1 ] 51 | then 52 | cd $1 53 | else 54 | echo directory $1 not found 55 | exit_error 56 | fi 57 | else 58 | mkdir tcpdumpbuild-${toolchain_arch} 59 | cd tcpdumpbuild-${toolchain_arch} 60 | fi 61 | } 62 | 63 | 64 | 65 | { 66 | echo " ____________________" 67 | echo "| |" 68 | echo "| TOOLCHAIN |" 69 | echo "|____________________|" 70 | 71 | toolchain_dir=$ndk_dir/toolchains/llvm/prebuilt/linux-x86_64 72 | export sysroot=$toolchain_dir/sysroot 73 | export PATH=$toolchain_dir/bin:$PATH 74 | 75 | target_host=i686-linux-android 76 | target_host_with_api=$target_host$android_api 77 | export AR=llvm-ar 78 | export AS=$target_host_with_api-clang 79 | export CC=$target_host_with_api-clang 80 | export CXX=$target_host_with_api-clang++ 81 | export LD=$target_host-ld 82 | export STRIP=$target_host-strip 83 | export RANLIB=$target_host-ranlib 84 | export STRIP=$target_host-strip 85 | export CFLAGS="-static -O2 -fPIE -fPIC --sysroot=$sysroot" 86 | export LDFLAGS="-pie --sysroot=$sysroot" 87 | } 88 | 89 | # download & untar libpcap + tcpdump 90 | { 91 | echo " _______________________________" 92 | echo "| |" 93 | echo "| DOWNLOADING LIBPCAP & TCPDUMP |" 94 | echo "|_______________________________|" 95 | 96 | tcpdump_file=${tcpdump_dir}.tar.gz 97 | libpcap_file=${libpcap_dir}.tar.gz 98 | tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file} 99 | libpcap_link=http://www.tcpdump.org/release/${libpcap_file} 100 | 101 | if [ -f ${tcpdump_file} ] 102 | then 103 | echo ${tcpdump_file} already downloaded! Nothing to do. 104 | else 105 | echo Download ${tcpdump_file}... 106 | wget ${tcpdump_link} 107 | if [ ! -f ${tcpdump_file} ] 108 | then 109 | exit_error 110 | fi 111 | fi 112 | 113 | if [ -f ${libpcap_file} ] 114 | then 115 | echo ${libpcap_file} already downloaded! Nothing to do. 116 | else 117 | echo Download ${libpcap_file}... 118 | wget ${libpcap_link} 119 | if [ ! -f ${libpcap_file} ] 120 | then 121 | exit_error 122 | fi 123 | fi 124 | 125 | if [ -d ${tcpdump_dir} ] 126 | then 127 | echo ${tcpdump_dir} directory already exist! Nothing to do. 128 | else 129 | echo untar ${tcpdump_file} 130 | tar -zxf ${tcpdump_file} 131 | fi 132 | 133 | if [ -d ${libpcap_dir} ] 134 | then 135 | echo ${libpcap_dir} directory already exist! Nothing to do. 136 | else 137 | echo untar ${libpcap_file} 138 | tar -zxf ${libpcap_file} 139 | fi 140 | } 141 | 142 | # build libpcap 143 | { 144 | cd ${libpcap_dir} 145 | 146 | echo " _____________________" 147 | echo "| |" 148 | echo "| CONFIGURING LIBPCAP |" 149 | echo "|_____________________|" 150 | 151 | chmod +x configure 152 | ./configure --host=i686-linux-android --with-pcap=linux 153 | 154 | if [ $? -ne 0 ] 155 | then 156 | exit_error 157 | fi 158 | 159 | echo " __________________" 160 | echo "| |" 161 | echo "| BUILDING LIBPCAP |" 162 | echo "|__________________|" 163 | 164 | chmod +x runlex.sh 165 | make 166 | 167 | if [ $? -ne 0 ] 168 | then 169 | exit_error 170 | fi 171 | 172 | cd .. 173 | } 174 | 175 | # build tcpdump 176 | { 177 | cd ${tcpdump_dir} 178 | 179 | echo " _____________________" 180 | echo "| |" 181 | echo "| CONFIGURING TCPDUMP |" 182 | echo "|_____________________|" 183 | 184 | chmod +x configure 185 | ./configure --host=i686-linux-android --with-pcap=linux 186 | 187 | if [ $? -ne 0 ] 188 | then 189 | exit_error 190 | fi 191 | 192 | echo " __________________" 193 | echo "| |" 194 | echo "| BUILDING TCPDUMP |" 195 | echo "|__________________|" 196 | 197 | sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c 198 | sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c 199 | 200 | make 201 | 202 | if [ $? -ne 0 ] 203 | then 204 | exit_error 205 | fi 206 | 207 | cd .. 208 | } 209 | 210 | mv ${tcpdump_dir}/tcpdump tcpdump-${toolchain_arch} 211 | chmod +x tcpdump-${toolchain_arch} 212 | 213 | echo " __________________" 214 | echo "| |" 215 | echo "| TCPDUMP IS READY |" 216 | echo "|__________________|" 217 | echo `pwd`/tcpdump-${toolchain_arch} 218 | -------------------------------------------------------------------------------- /build_x86_64.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | tcpdump_ver=4.9.2 4 | libpcap_ver=1.9.0 5 | android_api_def=23 6 | toolchain_arch=x86_64 7 | toolchain_dir=toolchain_x86_64 8 | 9 | #-------------------------------------------------------# 10 | 11 | tcpdump_dir=tcpdump-${tcpdump_ver} 12 | libpcap_dir=libpcap-${libpcap_ver} 13 | 14 | 15 | exit_error() 16 | { 17 | echo " _______" 18 | echo "| |" 19 | echo "| ERROR |" 20 | echo "|_______|" 21 | exit 1 22 | } 23 | 24 | if [ ${NDK} ] 25 | then 26 | ndk_dir=${NDK} 27 | else 28 | echo Please specify NDK path 29 | exit_error 30 | fi 31 | 32 | ndk_dir=`readlink -f ${ndk_dir}` 33 | 34 | if [ ${ANDROID_API} ] 35 | then 36 | android_api=${ANDROID_API} 37 | else 38 | android_api=${android_api_def} 39 | fi 40 | 41 | echo "_______________________" 42 | echo "" 43 | echo "NDK - ${ndk_dir}" 44 | echo "Android API: ${android_api}" 45 | echo "_______________________" 46 | 47 | { 48 | if [ $# -ne 0 ] 49 | then 50 | if [ -d $1 ] 51 | then 52 | cd $1 53 | else 54 | echo directory $1 not found 55 | exit_error 56 | fi 57 | else 58 | mkdir tcpdumpbuild-${toolchain_arch} 59 | cd tcpdumpbuild-${toolchain_arch} 60 | fi 61 | } 62 | 63 | 64 | 65 | { 66 | echo " ____________________" 67 | echo "| |" 68 | echo "| TOOLCHAIN |" 69 | echo "|____________________|" 70 | 71 | toolchain_dir=$ndk_dir/toolchains/llvm/prebuilt/linux-x86_64 72 | export sysroot=$toolchain_dir/sysroot 73 | export PATH=$toolchain_dir/bin:$PATH 74 | 75 | target_host=x86_64-linux-android 76 | target_host_with_api=$target_host$android_api 77 | export AR=llvm-ar 78 | export AS=$target_host_with_api-clang 79 | export CC=$target_host_with_api-clang 80 | export CXX=$target_host_with_api-clang++ 81 | export LD=$target_host-ld 82 | export STRIP=$target_host-strip 83 | export RANLIB=$target_host-ranlib 84 | export STRIP=$target_host-strip 85 | export CFLAGS="-static -O2 -fPIE -fPIC --sysroot=$sysroot" 86 | export LDFLAGS="-pie --sysroot=$sysroot" 87 | } 88 | 89 | # download & untar libpcap + tcpdump 90 | { 91 | echo " _______________________________" 92 | echo "| |" 93 | echo "| DOWNLOADING LIBPCAP & TCPDUMP |" 94 | echo "|_______________________________|" 95 | 96 | tcpdump_file=${tcpdump_dir}.tar.gz 97 | libpcap_file=${libpcap_dir}.tar.gz 98 | tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file} 99 | libpcap_link=http://www.tcpdump.org/release/${libpcap_file} 100 | 101 | if [ -f ${tcpdump_file} ] 102 | then 103 | echo ${tcpdump_file} already downloaded! Nothing to do. 104 | else 105 | echo Download ${tcpdump_file}... 106 | wget ${tcpdump_link} 107 | if [ ! -f ${tcpdump_file} ] 108 | then 109 | exit_error 110 | fi 111 | fi 112 | 113 | if [ -f ${libpcap_file} ] 114 | then 115 | echo ${libpcap_file} already downloaded! Nothing to do. 116 | else 117 | echo Download ${libpcap_file}... 118 | wget ${libpcap_link} 119 | if [ ! -f ${libpcap_file} ] 120 | then 121 | exit_error 122 | fi 123 | fi 124 | 125 | if [ -d ${tcpdump_dir} ] 126 | then 127 | echo ${tcpdump_dir} directory already exist! Nothing to do. 128 | else 129 | echo untar ${tcpdump_file} 130 | tar -zxf ${tcpdump_file} 131 | fi 132 | 133 | if [ -d ${libpcap_dir} ] 134 | then 135 | echo ${libpcap_dir} directory already exist! Nothing to do. 136 | else 137 | echo untar ${libpcap_file} 138 | tar -zxf ${libpcap_file} 139 | fi 140 | } 141 | 142 | # build libpcap 143 | { 144 | cd ${libpcap_dir} 145 | 146 | echo " _____________________" 147 | echo "| |" 148 | echo "| CONFIGURING LIBPCAP |" 149 | echo "|_____________________|" 150 | 151 | chmod +x configure 152 | ./configure --host=x86_64-linux-android --with-pcap=linux 153 | 154 | if [ $? -ne 0 ] 155 | then 156 | exit_error 157 | fi 158 | 159 | echo " __________________" 160 | echo "| |" 161 | echo "| BUILDING LIBPCAP |" 162 | echo "|__________________|" 163 | 164 | chmod +x runlex.sh 165 | make 166 | 167 | if [ $? -ne 0 ] 168 | then 169 | exit_error 170 | fi 171 | 172 | cd .. 173 | } 174 | 175 | # build tcpdump 176 | { 177 | cd ${tcpdump_dir} 178 | 179 | echo " _____________________" 180 | echo "| |" 181 | echo "| CONFIGURING TCPDUMP |" 182 | echo "|_____________________|" 183 | 184 | chmod +x configure 185 | ./configure --host=x86_64-linux-android --with-pcap=linux 186 | 187 | if [ $? -ne 0 ] 188 | then 189 | exit_error 190 | fi 191 | 192 | echo " __________________" 193 | echo "| |" 194 | echo "| BUILDING TCPDUMP |" 195 | echo "|__________________|" 196 | 197 | sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c 198 | sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c 199 | 200 | make 201 | 202 | if [ $? -ne 0 ] 203 | then 204 | exit_error 205 | fi 206 | 207 | cd .. 208 | } 209 | 210 | mv ${tcpdump_dir}/tcpdump tcpdump-${toolchain_arch} 211 | chmod +x tcpdump-${toolchain_arch} 212 | 213 | echo " __________________" 214 | echo "| |" 215 | echo "| TCPDUMP IS READY |" 216 | echo "|__________________|" 217 | echo `pwd`/tcpdump-${toolchain_arch} 218 | --------------------------------------------------------------------------------