From 68142c7e35302a07e4c8dc854e89d8f21df3c17b Mon Sep 17 00:00:00 2001 From: Vlatko Kosturjak Date: Tue, 28 Jun 2016 22:41:12 +0200 Subject: [PATCH] Support for nmap 7.12 and new android NDK 12b Also includes support for 64 bit --- android/Makefile | 30 ++++++++++------ android/multiarch.sh | 56 ++++++++++++++++++++++++++++-- android/patches/60-fix-time-h.diff | 56 ++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 14 deletions(-) create mode 100644 android/patches/60-fix-time-h.diff diff --git a/android/Makefile b/android/Makefile index d1b1ce7..bf287a0 100644 --- a/android/Makefile +++ b/android/Makefile @@ -6,13 +6,16 @@ HOSTPARM?="--host=arm-linux-androideabi" #PREFIXT="i686-linux-android" PREFIXT?="arm-linux-androideabi" # edit line below if you have NDK to reflect the path where NDK is installed -NDK?=/tmp/android-ndk-r10d +NDK?=/tmp/android-ndk-r12b NDKDEST?=/tmp/ndk-$(HOSTARCH) -NDKPLATFORM?=android-9 -ANDROIDDEST?=/sdcard/opt/nmap-6.47 +NDKLEVEL?=9 +NDKPLATFORM?=android-$(NDKLEVEL) +ANDROIDDEST?=/sdcard/opt/nmap-7.12 +OPENSSLPLATFORM?=dist +OPENSSLLDFLAGS?="-static" ifdef OPENSSL -OPENSSLVER?=openssl-1.0.2d +OPENSSLVER?=openssl-1.0.2h OPENSSLURL?="https://openssl.org/source/$(OPENSSLVER).tar.gz" OPENSSLDIR?=/sdcard/opt-$(HOSTARCH)/$(OPENSSLVER) OPENSSLOPT?="--with-openssl=$(OPENSSLDIR)" @@ -24,27 +27,29 @@ endif TMPNDK=/tmp/ndk.tar.bz2 TMPDIREXTRACT=/tmp -NDKCP=bash $(NDK)/build/tools/make-standalone-toolchain.sh --platform=$(NDKPLATFORM) --install-dir=$(NDKDEST) --arch=$(HOSTARCH) -NDKURL="http://dl.google.com/android/ndk/android-ndk32-r10-linux-x86_64.tar.bz2" +NDKCP=$(NDK)/build/tools/make_standalone_toolchain.py --arch $(HOSTARCH) --api $(NDKLEVEL) --stl libc++ --force --install-dir=$(NDKDEST) +NDKURL="https://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip" all: @echo "Type 'make doit' to automatically download Android NDK and build" - @echo "Type 'make havendk' to build automatically if you have NDK (edit Makefile!)" + @echo "Type 'make havendk' to build automatically if you have NDK (check Makefile!)" + @echo "For example: make havendk NDK=/data/opt/android-ndk-r12" doit: | getndk havendk @echo "Type 'doit' successfuly built" getndk: - wget $(NDKURL) -O $(TMPNDK) && cd $(TMPDIREXTRACT) && tar xvjf $(TMPNDK) + wget $(NDKURL) -O $(TMPNDK) && cd $(TMPDIREXTRACT) && unzip $(TMPNDK) cpndk: $(NDKCP) openssl: cd ../.. && wget -nc $(OPENSSLURL) && tar xvzf $(OPENSSLVER).tar.gz - cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) CC=$(PREFIXT)-gcc AR="$(PREFIXT)-ar r" RANLIB=$(PREFIXT)-ranlib LDFLAGS="-static" ./Configure dist --prefix=$(OPENSSLDIR) + # cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) CC=$(PREFIXT)-gcc AR="$(PREFIXT)-ar r" RANLIB=$(PREFIXT)-ranlib LDFLAGS="-static" ./Configure $(OPENSSLPLATFORM) --prefix=$(OPENSSLDIR) + cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) CC=$(PREFIXT)-gcc AR="$(PREFIXT)-ar r" RANLIB=$(PREFIXT)-ranlib LDFLAGS=$(OPENSSLLDFLAGS) ./Configure $(OPENSSLPLATFORM) --prefix=$(OPENSSLDIR) cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) make clean - cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) make CC=$(PREFIXT)-gcc AR="$(PREFIXT)-ar r" RANLIB=$(PREFIXT)-ranlib LDFLAGS="-static" + cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) make CC=$(PREFIXT)-gcc AR="$(PREFIXT)-ar r" RANLIB=$(PREFIXT)-ranlib LDFLAGS=$(OPENSSLLDFLAGS) cd ../../$(OPENSSLVER) && PATH=$(NDKDEST)/bin:$(PATH) make install patch: @@ -56,11 +61,14 @@ unpatch: havendk: | cpndk patch build @echo "Type 'havendk' successfuly built" +havendk: | cpndk patch build + @echo "Type 'havendk' successfuly built" + build: | configure compile @echo "Type 'build' successfuly built" configure: - cd .. && PATH=$(NDKDEST)/bin:$(PATH) LUA_CFLAGS="-DLUA_USE_POSIX -fvisibility=default -fPIE" ac_cv_linux_vers=2 CC=$(PREFIXT)-gcc CXX=$(PREFIXT)-g++ LD=$(PREFIXT)-ld RANLIB=$(PREFIXT)-ranlib AR=$(PREFIXT)-ar STRIP=$(PREFIXT)-strip CFLAGS="-fvisibility=default -fPIE" CXXFLAGS="-fvisibility=default -fPIE" LDFLAGS="-rdynamic -pie" ./configure $(HOSTPARM) --without-zenmap --with-liblua=included --with-libpcap=internal --with-pcap=linux --enable-static --prefix=$(ANDROIDDEST) $(OPENSSLOPT) + cd .. && PATH=$(NDKDEST)/bin:$(PATH) LUA_CFLAGS="-DLUA_USE_POSIX -fvisibility=default -fPIE" ac_cv_linux_vers=2 CC=$(PREFIXT)-gcc CXX=$(PREFIXT)-g++ LD=$(PREFIXT)-ld RANLIB=$(PREFIXT)-ranlib AR=$(PREFIXT)-ar STRIP=$(PREFIXT)-strip CFLAGS="-fvisibility=default -fPIE" CXXFLAGS="-fvisibility=default -fPIE" LDFLAGS="-rdynamic -pie -static-libstdc++" ./configure $(HOSTPARM) --without-zenmap --with-liblua=included --with-libpcap=internal --with-pcap=linux --enable-static --prefix=$(ANDROIDDEST) $(OPENSSLOPT) install: cd .. && PATH=$(NDKDEST)/bin:$(PATH) make install diff --git a/android/multiarch.sh b/android/multiarch.sh index 6e41652..10c590f 100755 --- a/android/multiarch.sh +++ b/android/multiarch.sh @@ -3,42 +3,92 @@ set -x ANDROIDDIR=/sdcard/opt -ANDROIDNMAP=nmap-6.49BETA4 +ANDROIDNMAP=nmap-7.12 NDKARCHPPREFIX=/data/opt/ndk +NDKPATH=/data/opt/android-ndk-r12b CURDIR=`pwd` +NDK32LEVEL=9 +NDK64LEVEL=21 echo "Patching..." # make patch echo "Starting Building for each arch" -for arch in arm mipsel i686 +#for arch in arm +#for arch in arm mipsel i686 +for arch in arm mipsel i686 aarch64 mips64el x86_64 do echo "Building for $arch" + OPENSSLPLATFORM=dist + OPENSSLLDFLAGS="-static" + NDKLEVEL=$NDK32LEVEL + NDKPLATFORM=$arch if [ "$arch" = "arm" ] then THOSTPARM="--host=$arch-linux-androideabi" TPREFIXT="$arch-linux-androideabi" ARCHZIP="armeabi" + elif [ "$arch" = "aarch64" ] + then + THOSTPARM="--host=$arch-linux-android" + TPREFIXT="$arch-linux-android" + ARCHZIP="aarch64" + NDKPLATFORM=arm64 + NDKLEVEL=$NDK64LEVEL elif [ "$arch" = "mipsel" ] then THOSTPARM="--host=$arch-linux-android" TPREFIXT="$arch-linux-android" ARCHZIP="mips" + NDKPLATFORM=mips + elif [ "$arch" = "mips64el" ] + then + THOSTPARM="--host=$arch-linux-android" + TPREFIXT="$arch-linux-android" + ARCHZIP="mips64el" + NDKPLATFORM=mips64 + NDKLEVEL=$NDK64LEVEL elif [ "$arch" = "i686" ] then THOSTPARM="--host=$arch-linux-android" TPREFIXT="$arch-linux-android" ARCHZIP="x86" + NDKPLATFORM=x86 + elif [ "$arch" = "x86_64" ] + then + THOSTPARM="--host=$arch-linux-android" + TPREFIXT="$arch-linux-android" + ARCHZIP="x86_64" + OPENSSLPLATFORM=linux-x86_64 + OPENSSLLDFLAGS= + NDKLEVEL=$NDK64LEVEL else THOSTPARM="--host=$arch-linux-android" TPREFIXT="$arch-linux-android" ARCHZIP="dunno" fi + NDKARCHPATH=$NDKARCHPPREFIX-$arch - PATH=$NDKARCHPATH/bin:$PATH NDKDEST=$NDKARCHPATH ANDROIDDEST=$ANDROIDDIR/$ANDROIDNMAP HOSTARCH=$arch HOSTPARM=$THOSTPARM PREFIXT=$TPREFIXT OPENSSL=1 make openssl build install strip + $NDKPATH/build/tools/make_standalone_toolchain.py --arch $NDKPLATFORM --api $NDKLEVEL --stl libc++ --force --install-dir $NDKARCHPATH + if [ $? -eq 0 ]; then + echo "[i] Successful copying of standalone toolchain" + else + echo "[!] Error copying of standalone toolchain" + exit 1 + fi + NDK=$NDKPATH PATH=$NDKARCHPATH/bin:$PATH NDKDEST=$NDKARCHPATH ANDROIDDEST=$ANDROIDDIR/$ANDROIDNMAP HOSTARCH=$arch HOSTPARM=$THOSTPARM PREFIXT=$TPREFIXT OPENSSL=1 OPENSSLPLATFORM=$OPENSSLPLATFORM OPENSSLLDFLAGS= make openssl build install strip + if [ $? -eq 0 ]; then + echo "[i] Successful compilation of $arch" + else + echo "[!] Error compilation of $arch" + exit 1 + fi + echo "Copying data" cd $ANDROIDDIR/$ANDROIDNMAP + + cp -a bin/ /tmp/$ANDROIDNMAP-$arch # PATH=$NDKARCHPATH/bin:$PATH $TPREFIXT-strip bin/* cd bin zip -9 ../../$ANDROIDNMAP-binaries-$ARCHZIP.zip * diff --git a/android/patches/60-fix-time-h.diff b/android/patches/60-fix-time-h.diff new file mode 100644 index 0000000..69725e7 --- /dev/null +++ b/android/patches/60-fix-time-h.diff @@ -0,0 +1,56 @@ +diff -ur nmap-7.12/nmap_error.cc nmap-7.12.mod/nmap_error.cc +--- nmap-7.12/nmap_error.cc 2015-07-01 23:25:39.000000000 +0200 ++++ nmap-7.12.mod/nmap_error.cc 2016-06-26 22:00:07.154850539 +0200 +@@ -128,6 +128,7 @@ + #include "xml.h" + + #include ++#include + + extern NmapOps o; + +diff -ur nmap-7.12/nping/EchoServer.cc nmap-7.12.mod/nping/EchoServer.cc +--- nmap-7.12/nping/EchoServer.cc 2015-06-27 10:21:53.000000000 +0200 ++++ nmap-7.12.mod/nping/EchoServer.cc 2016-06-26 22:06:11.570843103 +0200 +@@ -130,6 +130,7 @@ + #include "NpingOps.h" + #include "ProbeMode.h" + #include ++#include + + extern NpingOps o; + extern EchoServer es; +diff -ur nmap-7.12/osscan2.cc nmap-7.12.mod/osscan2.cc +--- nmap-7.12/osscan2.cc 2016-01-13 21:53:39.000000000 +0100 ++++ nmap-7.12.mod/osscan2.cc 2016-06-26 22:01:30.438848840 +0200 +@@ -138,6 +138,7 @@ + + #include + #include ++#include + + extern NmapOps o; + +diff -ur nmap-7.12/osscan.cc nmap-7.12.mod/osscan.cc +--- nmap-7.12/osscan.cc 2015-11-05 21:41:05.000000000 +0100 ++++ nmap-7.12.mod/osscan.cc 2016-06-26 22:05:09.634844367 +0200 +@@ -135,6 +135,7 @@ + + #include + #include ++# include + #if TIME_WITH_SYS_TIME + # include + # include +diff -ur nmap-7.12/service_scan.cc nmap-7.12.mod/service_scan.cc +--- nmap-7.12/service_scan.cc 2016-03-05 00:04:01.000000000 +0100 ++++ nmap-7.12.mod/service_scan.cc 2016-06-28 10:39:14.971841468 +0200 +@@ -159,6 +159,8 @@ + # endif + #endif + ++#include ++ + #include + #include +