Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a pure binary file on Android

Is there a way to run a binary executable file (compile with NDK), on Android?

/* #includes #defines ... */

int main(){
    // Do something when this is executed
    return 0;
}

I want it to run independant from the VM. As in not inside an activity, just a binary that runs directly on the proc

like image 498
user965369 Avatar asked Oct 22 '11 16:10

user965369


2 Answers

adb push exename /data/bin/exename
#next line might be needed if you are developing on Windows
adb shell chmod 777 /data/bin/exename
adb shell /data/bin/exename

But your device has to be rooted. (It also works on emulator.)

like image 99
Andrey Kamaev Avatar answered Sep 20 '22 04:09

Andrey Kamaev


I am answering to your doubt in the first answer mentioned by Andrey.

Try the codes given by him.

adb push exename /data/bin/exename

It is used to push the binary file named 'exename' to the execuatable path on Android.

adb shell chmod 777 /data/bin/exename

This line is not required in linux. Its used to change the mode. The first 7 stands for 'user', next for 'group' and the last for 'other'. Changing the numbers would CHange the MODe of each group mentioned above. 7 represents - read, write and execute. 6 represents - read, write and NO execute.

adb shell /data/bin/exename

This code is used to execute the binary. Which inturn means that its being used in the Terminal.

like image 36
Anoop K. Prabhu Avatar answered Sep 19 '22 04:09

Anoop K. Prabhu