jcubic
jcubic

Reputation: 66490

Is it possible to build CLI app for android that can be executed from adb shell?

Just wondering is it possible to build CLI app that can be run from adb shell?

Upvotes: 0

Views: 167

Answers (2)

t0mm13b
t0mm13b

Reputation: 34592

Yes it is possible, with Android NDK using C. You may need to be rooted in order to store the binary somewhere to be executed, note, it will not run off the sdcard, usually /data/local/tmp is one spot that comes to mind. And when you push the binary across to the said location, you will have to set the permission's execute bit on the binary itself in order to run it. Quite possibly also, the ownership and group owner would have to be changed.

Your mileage will vary depending on the ROM.

Upvotes: 1

Chris Stratton
Chris Stratton

Reputation: 40357

Currently it is possible, though not officially supported/encouraged.

The easiest way is probably to set up a project directory and within it a jni folder with an Android.mk and your C sources - use the hello-jni ndk sample as a guide.

Then change the BUILD_SHARED_LIBRARY in the Android.mk to BUILD_EXECTUABLE and run ndk-build from the parent project directory as normal.

You could probably also use the ndk standalone toolchain generation feature, or there have at times in the past been various unofficial wrapper systems to make the ndk gcc easier to (ab)use.

There is no excess of places where you can put an executable on a secured device. The sdcard is out due to the mount-level blocking of the executable bit. From approximately Android 2.2 the directory /data/local is writable by the adb shell user, and on earlier versions there is an /sqlite_stmt_journals directory people often abused for tests.

Another possibility is to use an APK to deploy the executables in its private storage and make them world readable and executable (it might take jni to call chmod() to get the execute bit set for others, or I suppose you could exec the chmod shell utility). A downside is that the shell will have to work with long /data/data/some.package.name paths, where the intermediate /data folder is not browsable!

Upvotes: 1

Related Questions