Skip to content

Commit

Permalink
Support for nmap 7.12 and new android NDK 12b
Browse files Browse the repository at this point in the history
Also includes support for 64 bit
  • Loading branch information
kost committed Jun 28, 2016
1 parent 5ce464e commit 68142c7
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 14 deletions.
30 changes: 19 additions & 11 deletions android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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:
Expand All @@ -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
Expand Down
56 changes: 53 additions & 3 deletions android/multiarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
56 changes: 56 additions & 0 deletions android/patches/60-fix-time-h.diff
Original file line number Diff line number Diff line change
@@ -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 <errno.h>
+#include <time.h>

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 <signal.h>
+#include <time.h>

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 <list>
#include <math.h>
+#include <time.h>

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 <errno.h>
#include <stdarg.h>
+# include <time.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
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 <time.h>
+
#include <algorithm>
#include <list>

0 comments on commit 68142c7

Please sign in to comment.