Search code examples
candroid-ndkadbconsole-applicationarm64

Can I use printf in an Android native binary


Let's assume the phone is rooted and arm binaries can be installed. Can I make a console binary using Android Studio with printf output?

Is there a step-by-step guide to writing and compiling such binaries with a traditional C Program int main() with Android Studio or creation of the Android.mk file

There are some projects on GitHub doing this:

https://github.com/strazzere/android-unpacker/tree/master/native-unpacker

And

https://github.com/Shabbypenguin/DexPwn


Solution

  • #include <stdio.h>
    
    int main() {
      printf("Hello, world\n");
      return 0;
    }
    

    Then:

    1. ~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-linux-android21 helloworld.c -o helloworld
    2. adb push helloworld /data/local/tmp/helloworld
    3. adb shell /data/local/tmp/helloworld