From c269a003449d9d1fce873df64e29983b0eaf68a4 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 5 Aug 2015 19:33:50 +0200 Subject: [PATCH] Add support for Android L Build position-indepent executables, required for Android L (5.0+) They also work with kitkat. Add new maketarget "cross-android-old" that builds without PIE for older versions. Include both new and old versions in latest-android.zip. Add arm64. Hopefully solves github PR #14. --- Makefile | 21 +++++++++++++++++++-- README-android.txt | 14 +++++++++----- src/Android.mk | 9 +++++++++ src/android_dns.h | 5 +++++ src/client.c | 2 +- src/dns.c | 6 +++--- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a63a603..6f869b3 100644 --- a/Makefile +++ b/Makefile @@ -56,15 +56,32 @@ iodine-latest: @for i in README.md CHANGELOG TODO; do cp $$i iodine-latest/$$i.txt; done @unix2dos iodine-latest/* +#non-PIE build for old android +cross-android-old: + @(cd src; $(MAKE) base64u.c base64u.h) + @(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk MY_PLATFORM=old) + +#Position-indepedent build for modern android cross-android: @(cd src; $(MAKE) base64u.c base64u.h) - @(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk) + @(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk MY_PLATFORM=kitkat) iodine-latest-android.zip: iodine-latest @mv iodine-latest iodine-latest-android - @mkdir -p iodine-latest-android/armeabi iodine-latest-android/x86 + @mkdir -p iodine-latest-android/pre-kitkat/armeabi + @mkdir -p iodine-latest-android/pre-kitkat/x86 + @$(MAKE) cross-android-old TARGET_ARCH_ABI=armeabi + @cp src/libs/armeabi/* iodine-latest-android/pre-kitkat/armeabi + @$(MAKE) cross-android-old TARGET_ARCH_ABI=x86 + @cp src/libs/x86/* iodine-latest-android/pre-kitkat/x86 + @rm -rf src/libs src/obj + @mkdir -p iodine-latest-android/armeabi + @mkdir -p iodine-latest-android/arm64-v8a + @mkdir -p iodine-latest-android/x86 @$(MAKE) cross-android TARGET_ARCH_ABI=armeabi @cp src/libs/armeabi/* iodine-latest-android/armeabi + @$(MAKE) cross-android TARGET_ARCH_ABI=arm64-v8a + @cp src/libs/arm64-v8a/* iodine-latest-android/arm64-v8a @$(MAKE) cross-android TARGET_ARCH_ABI=x86 @cp src/libs/x86/* iodine-latest-android/x86 @cp README-android.txt iodine-latest-android diff --git a/README-android.txt b/README-android.txt index f08c6cf..b7e73bb 100644 --- a/README-android.txt +++ b/README-android.txt @@ -13,7 +13,7 @@ Extra README file for Android 2. Find/build a compatible tun.ko for your specific Android kernel 3. Copy tun.ko and the iodine binary to your device: - (Almost all devices need the armeabi binary. Only Intel powered + (Almost all devices need the armeabi binary. Only Intel powered ones need the x86 build.) adb push tun.ko /data/local/tmp @@ -35,11 +35,15 @@ For more information: http://blog.bokhorst.biz/5123 2. Download and unpack the iodine sources 3. Build: - cd src - make base64u.h base64u.c - ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk + cd src + make base64u.h base64u.c + ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk MY_PLATFORM=kitkat or run "make cross-android" in the iodine root directory. - To build for other archs, specify TARGET_ARCH_ABI: + To build for other archs, specify TARGET_ARCH_ABI: "make cross-android TARGET_ARCH_ABI=x86" + For older android versions (pre-kitkat), build with "make cross-android" in the + root directory, or manually like above but without the MY_PLATFORM part. + + The iodine binary ends up in src/libs//iodine diff --git a/src/Android.mk b/src/Android.mk index 81136e5..3767ab6 100644 --- a/src/Android.mk +++ b/src/Android.mk @@ -20,5 +20,14 @@ LOCAL_SRC_FILES := tun.c dns.c read.c encoding.c login.c base32.c base64.c base6 LOCAL_CFLAGS := -c -DANDROID -DLINUX -DIFCONFIGPATH=\"/system/bin/\" -Wall -DGITREVISION=\"$(HEAD_COMMIT)\" LOCAL_LDLIBS := -lz +#Choose platform level (for PIE support) +ifeq (kitkat, $(strip $(MY_PLATFORM))) +APP_PLATFORM := android-16 +LOCAL_CFLAGS += -fPIE +LOCAL_LDFLAGS += -fPIE -pie +else +APP_PLATFORM := android-3 +endif + include $(BUILD_EXECUTABLE) diff --git a/src/android_dns.h b/src/android_dns.h index 0085af6..5a86e71 100644 --- a/src/android_dns.h +++ b/src/android_dns.h @@ -17,6 +17,9 @@ #ifndef __FIX_ANDROID_H__ #define __FIX_ANDROID_H__ +/* Newer android platforms can have this data already */ +#ifndef C_IN + typedef struct { unsigned id :16; unsigned rd :1; @@ -51,4 +54,6 @@ typedef struct { #define T_TXT 16 #define T_SRV 33 +#endif /* !C_IN */ + #endif diff --git a/src/client.c b/src/client.c index 759f652..38b573b 100644 --- a/src/client.c +++ b/src/client.c @@ -32,10 +32,10 @@ #ifdef WINDOWS32 #include "windows.h" #else +#include #ifdef ANDROID #include "android_dns.h" #endif -#include #ifdef DARWIN #define BIND_8_COMPAT #include diff --git a/src/dns.c b/src/dns.c index 5f187e4..6eecab2 100644 --- a/src/dns.c +++ b/src/dns.c @@ -27,9 +27,6 @@ #ifdef WINDOWS32 #include "windows.h" #else -#ifdef ANDROID -#include "android_dns.h" -#endif #include #ifdef DARWIN #define BIND_8_COMPAT @@ -38,6 +35,9 @@ #include #include #include +#ifdef ANDROID +#include "android_dns.h" +#endif #endif