Fuzion24 / AndroidObfuscation-NDK

Example of obfuscating an Android NDK project using O-LLVM
216 stars 89 forks source link

Not working on x86 platform #1

Open ctjhai opened 10 years ago

ctjhai commented 10 years ago

I tried to create an obfuscated binary for x86 platform, but it failed with linker error that it did not understand sysroot option. See the log below

rm -f /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi/lib.so /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a/lib.so /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a-hard/lib.so /Users/test/scratchpad/AndroidObfuscation-NDK/libs/mips/lib.so /Users/test/scratchpad/AndroidObfuscation-NDK/libs/x86/lib_.so rm -f /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi/gdbserver /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a/gdbserver /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a-hard/gdbserver /Users/test/scratchpad/AndroidObfuscation-NDK/libs/mips/gdbserver /Users/test/scratchpad/AndroidObfuscation-NDK/libs/x86/gdbserver rm -f /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi/gdb.setup /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a/gdb.setup /Users/test/scratchpad/AndroidObfuscation-NDK/libs/armeabi-v7a-hard/gdb.setup /Users/test/scratchpad/AndroidObfuscation-NDK/libs/mips/gdb.setup /Users/test/scratchpad/AndroidObfuscation-NDK/libs/x86/gdb.setup [x86] Compile : obfuscated <= obfuscationTest.c /Applications/ADT/android-ndk-r10/toolchains/obfuscator-llvm-3.4/prebuilt/darwin-x86_64/bin/clang -MMD -MP -MF /Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86/objs/obfuscated/obfuscationTest.o.d -gcc-toolchain /Applications/ADT/android-ndk-r10/toolchains/x86-4.8/prebuilt/darwin-x86_64 -target i686-none-linux-android -ffunction-sections -funwind-tables -fstack-protector -fPIC -no-canonical-prefixes -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -I/Users/test/scratchpad/AndroidObfuscation-NDK/jni -DANDROID -mllvm -sub -mllvm -fla -mllvm -bcf -Wa,--noexecstack -Wformat -Werror=format-security -I/Applications/ADT/android-ndk-r10/platforms/android-9/arch-x86/usr/include -c /Users/test/scratchpad/AndroidObfuscation-NDK/jni/obfuscationTest.c -o /Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86/objs/obfuscated/obfuscationTest.o [x86] Executable : obfuscated /Applications/ADT/android-ndk-r10/toolchains/obfuscator-llvm-3.4/prebuilt/darwin-x86_64/bin/clang++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/Applications/ADT/android-ndk-r10/platforms/android-9/arch-x86 -Wl,-rpath-link=/Applications/ADT/android-ndk-r10/platforms/android-9/arch-x86/usr/lib -Wl,-rpath-link=/Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86 /Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86/objs/obfuscated/obfuscationTest.o -lgcc -gcc-toolchain /Applications/ADT/android-ndk-r10/toolchains/x86-4.8/prebuilt/darwin-x8664 -target i686-none-linux-android -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -static -lc -lm -o /Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86/obfuscated ld: unknown option: --sysroot=/Applications/ADT/android-ndk-r10/platforms/android-9/arch-x86 clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: ** [/Users/test/scratchpad/AndroidObfuscation-NDK/obj/local/x86/obfuscated] Error 1

There is no issue with ARM and MIPS platforms though.

Any idea on this?

ctjhai commented 10 years ago

I found some additional information after some digging around. If I set the target to ARM and execute the following command:

/Applications/ADT/android-ndk-r10/toolchains/obfuscator-llvm-3.4/prebuilt/darwin-x86_64/bin/clang++ -v --sysroot=/Applications/ADT/android-ndk-r10/platforms/android-3/arch-arm -target armv5te-none-linux-androideabi -gcc-toolchain /Applications/ADT/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/

and I have the following output:

Obfuscator-clang version 3.4 (tags/RELEASE_34/final) (based on LLVM 3.4svn)
Target: armv5te-none-linux-androideabi
Thread model: posix
Found candidate GCC installation: /Applications/ADT/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8
Selected GCC installation: /Applications/ADT/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8

On the other hand, if I set the target to i686 or x86, GCC installation could not be found

/Applications/ADT/android-ndk-r10/toolchains/obfuscator-llvm-3.4/prebuilt/darwin-x86_64/bin/clang++ -v --sysroot=/Applications/ADT/android-ndk-r10/platforms/android-9/arch-x86 -target i686-none-linux-android -gcc-toolchain /Applications/ADT/android-ndk-r10/toolchains/x86-4.8/prebuilt/darwin-x86_64/

Obfuscator-clang version 3.4 (tags/RELEASE_34/final) (based on LLVM 3.4svn)
Target: i686-none-linux-android
Thread model: posix
Selected GCC installation: 
Fuzion24 commented 10 years ago

I have not used the Android NDK + clang to build a native x86 application. It is possible that the NDK doesn't support building via clang for x86. Did you try building a simple hello world app for x86 (without the obfuscator) using the stock NDK?

ctjhai commented 10 years ago

Yes, if I use the stock NDK, it can build for all supported platforms, including x86. Having said that, I have not run the resulting binary on x86 platform.

Fuzion24 commented 10 years ago

You can build for x86 using clang with the ndk?

ctjhai commented 10 years ago

Confirmed, I can build my JNI shared library with clang. On my Application.mk file, I have the following entries:

APP_ABI := x86
NDK_TOOLCHAIN_VERSION := clang3.4

Just for your information, I am using Android NDK r10.