Running elf executable on Android - android

I was wondering if the only way to run an executable in android is by installing an apk. Would it be possible to run an elf executable? Just as done on linux.

Just drop and run it might be a problem due to restrictions that android uses. Note that those restrictions are updated every Android version.
If you target your executable to run on a rooted device, you can write an app that dumps the executable in a way that bypasses the restrictions and runs it.
If you target you executable to run on a custom ROM or Recovery, you can place the executable in a way that pass the restrictions and run it (without the need of a wrapper app).

if the executable is built for the target architecture, then
If the executable is statically linked: Yes
If the executable is built with Android toolchain/NDK: Yes
If you have the libraries against which the executable is linked: Yes
fi
If you have USB debugging enabled, just use adb push to copy the executable to device, not to a location mounted with noexec, and go to the shell with adb shell, and execute it. You might need to chmod it before executing.

Related

How to run a C program in adb shell?

So adb shell gives one a linux terminal into an android phone, when it is connected to a computer. One can run all the standard linux commands like ls and cat inside the android phone, and explore the android filesystem using the adb shell.
Now I wonder, is it possible to use a C/C++ compiler such as clang or gcc to compile and execute a C/C++ program in the android phone, as on linux? I am not talking about android app development here, I mean a linux command line C/C++ program for android. Also, can I use the C standard library and linux system calls such as fork(), exec(), kill(), and working with file descriptors, in the android adb shell, just as I would do it on linux?
Yes. You can . For that you need copy your compiler exe's to android file system. From there you can easily call. Same time make sure that all pre-builed libs in android PATH folder.

Compile and run ARM assembly code via SSH on Android Lollipop

I am trying to run some ARM assembly codes on Snapdragon 810 development board to evaluate performance on Cortex-A53 and A57 processors. My codes are nothing to do with android applications and they are C/Assembly coeds. Moreover, I want to get remote access to the board preferably via SSH and run gcc commands. The board default OS in Android Lollipop and my first intention was to install Linux on it to make things work desirably. However, Qualcomm customer support informed me that Linux isn't supported by this board and I have to deal with Android.
I've already searched over various forums. Some of them suggest to root the Android device, install QuickSSHD or SSHDroid on the device and simply SSH to it. However, I am not sure if the provided console has the capability of running gcc commands, generating executable and running it. Others, suggest to generate executable using cross-compilation and push the executable via adb console and run it on the Android device. This approach makes more sense, but I need to have remote access via SSH to the board and edit my code on the device continuously.
My question is, what is the best and easiest approach to get remote access via SSH to this device, compile and run C/ARM Assembly code, transfer files and get the real timing of my codes?!
Cross compile is the easiest option to generate the executable. Else you will have to port GCC to the target first. Don't even bother.
And Adb is a lot better when dealing with Android devices as you need not install any additional applications/executables to get it working. Adb can work on TCP connection as well. So there is no need of SSH for the task. And if the device is rooted, "adb root" followed by "adb shell" would give you the root console.

How to invoke "./configure; make; make install" on Android adb

I have a program that I would like to install on an android phone (x86). The program can be installed on a Linux PC. The procedure of installing the program on the PC is:
$./configure
$make
$make install
Now I would like to do the above through android ADB so I can install it on the phone. What are the utilities needed? (I cannot find "make" in busybox http://www.busybox.net/live_bbox/live_bbox.html)
Building your program directly on the phone probably isn't going to be practical. The number of dependencies that make will wind up invoking during the build process will be huge, and either not exist or not work well on the device itself.
It would be better to look at cross-compiling, where you use a different system to build a binary that is suitable for your device.
It wouldn't be possible to provide more specific info without more detail, but be warned: you're probably in for a big project.
Maybe start here? http://forum.xda-developers.com/showthread.php?t=2723240

I need root permissions to execute a native application under Android?

I have compiled a native application, a terminal only application basically, with the android NDK, my main problem right is that I can't change the permissions on my executable ( a dynamically linked one ) like so chmod +x executable to test and use the application.
I need to root my device just to do that ?
I tried with both adb shell and a random terminal application directly from my phone.
No, you don't need to root a device to use executable binaries. You cannot put it on /sdcard but on most devices there is a directory /data/tmp or /data/local/tmp where you can push files with adb and execute with adb shell.
The robust option is to package an executable in an APK and get it on device by installing the APK, see Is it possible to run a native arm binary on a non-rooted android phone? or How to package native commandline application in apk?.
Note that you cannot change the LD_LIBRARY_PATH, so be careful if your executable depends on some shared libs that are not part of /system/lib.
These guys say root is needed:
How to compile C into an executable binary file and run it in Android from Android Shell?
From my understanding, the regular sdcard is mounted with no execution permission, so you need to write to something like /data/local/, which indeed requires root access.
If you don't package your native code as an Android app, you'll need to run it from shell.
Starting with Android KitKat/Lollipop, executables can only be run from restricted locations. eg an executable installed in /data/data//... will not be allowed to run in any ways, be it with or without root.
Before KitKat, one can copy the executable to its own data directory, make it executable and run it. Not anymore in more recent version of KitKat.
So you will definitively need root to run linux exe on recent versions of Android.

how to run script at boot-time?

I need to run a script that sets cpu_freq .In order to retain the settings after reboot i need to run script which takes care of this issue.I tried to write service in init.rc but the edited part in init.rc disappears on reboot .is there some other way to start script on reboot.thanks
I've found success with magisk. When installed, it adds a directory for boot scripts under /data/adb/service.d, in which you can throw your shell scripts and have them executed by Magisk on boot.
For example, I have the following script:
#!/bin/sh
sleep 15 # to make sure we aren't running in an early stage of the boot process
crond -b -c /data/crontab/
Once created as /data/adb/service.d/start-crond.sh and made executable, it automatically launches crond at boot (provided by Magisk's internal busybox instance).
Use Script Manager.
This link may be helpful:
[ADDON][Xperia S] Generic startup/init.d scripts support for Stock ROM/Kernel
http://forum.xda-developers.com/showthread.php?t=1547238
Although it is for Xperia S, it also works for my ideos. I think the theory behind is quite generic. And if you have installed busybox, you can unzip the downloaded package, read the batch and make some change to the phone by yourself.
If you really want to run your script manually after boot, I prefer scriptme in play market. It's simple and small.

Categories

Resources