'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 1:[1]

#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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Farrell