rooting android phone to run cross compiled C file? - android

Do I actually need to root my phone to run a program that prints hello world?
I am trying to run a binary file after I have cross compiled it.
I get permission denied when I push the file into /data/local/tmp directory.
Any ideas where I should push it so that it can run? If possible?
Or do I need to try it on Terminal Emulator?

No, you don't need to have root permissions to run executable on Android.
Most likely, after pushing file to /data/local/tmp, it have no required permissions - that's why you got "permission denied". Do it as following:
adb push /path/to/executable /data/local/tmp
adb shell chmod 0755 /data/local/tmp/executable
adb shell 'cd /data/local/tmp && ./executable'
It works for me.

Do I actually need to root my phone to run a program that prints hello world?
No.
I get permission denied when I push the file into /data/local/tmp directory.
Perform a chmod a+x after you push it. I seem to recall the Android runtime does not understand octal. (Or maybe its the other way around based on #crystax's answer).

Related

Running adb as root from an Ubuntu machine

I'm trying to modify the hosts file on my android phone and I am using adb for this on Ubuntu 20.04 to pull the file, modify it and push it back as suggested here. I was able to pull the file but when I try to push it I get an error
adb: error: failed to copy 'Documents/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system
One suggestion seems to be to run adb remount or adb shell mount -o rw,remount /system (I'm not sure if these meant to be run on the android device itself) and this doesn't work for me, I get
/system/bin/sh: /system/bin/remount: inaccessible or not found
To this, there seems to be a suggestion to run adb root which returns adbd cannot run as root in production builds. Now I'm not sure how to proceed. There are some threads online saying what to do about this but I feel this is way above my head already. I just want to push the hosts file back to the phone. Is there a simple way to do this?

Why does data folder in android simulator deny permission?

I tried to create database file into
C:\Users\cammm\AppData\Local\Android\Sdk/platform-tools/data/data/com.cookandroid.cammm
Here are steps that I tried to get into the folder
click on "cmd" and run as administrator
cd C:\Users\cammm\AppData\Local\Android\Sdk/platform-tools
adb root
adb shell cd /data/data/com.cookandroid.cammm
Now this pops up: "/system/bin/sh: cd: /data/data/com.cookandroid.adb: Permission denied"
I used "ls" in "platform-tools" folder and saw that it was
"drwxrwx--x 37 system system 4096 2018-07-18 15:46 data"
which means file can only execute but not write or read in others.
using chmod did not work. (chmod: chmod '/data/data/com.cookandroid.adb' to 40702: Operation not permitted)
run as administor does not work
What should I do?
You will only be able to access the data/data folder if the device which you are accessing is rooted. when you have the device rooted then it will show # as prompt on the command line. so Make sure you have the rooted device to execute the above steps.
Please note: It's not advisable to use the rooted devices to carry out any function of the application as it's simply a hack of the device so you have to understand the risk associated with it.

Using ADB on Android phone

I am using adb on Android phone.
I did./adb shell
and I can see the folders inside the phone
I type cd /sdcard
but it said permission denied.
I can't use su or sudo to make myself root.
How can I make myself as root?
You should root your android phone and then you can use su command in adb.
There is some useful information in this link www.androidcentral.com/root

Android equivalent shell command

I am searching for the equivalent Linux command of following Android adb shell command:
%ANDROID%\platform-tools\adb.exe shell ^
/system/bin/chmod 0777 /data/local/asl-native
This will be used to give the read and write permissions for a particular directory or file.
I have tried with the following Linux commands:
/system/bin/chmod u+rw /data/local/filename
However, it appears the file is not given permissions.
Most Android systems do not let you run as super user (i.e. root) and without that privilege, you cannot make this work.
You can read more bout how file storage works on Android here.

How to run C++ application in Android SHELL

I want to run hello world written on C++ and compiled with Android toolchain 9, but I faced with issue: by default I have no permissions to launch it and I can't change permissions using chmod`.
I used Android 2.3.3 - Api Level 10
Application was compiled by cross compiler for API level 9
Procedure:
Compile application:
~/toolchain_andr9/bin/ arm-linux-androideabi-g++ helloworld.cpp
Then send application to SDCARD on the emulator:
>adb push a.out /mnt/sdcard
then go to SHELL and try to run a.out:
>adb shell
>
>/mnt/sdcard/a.out
And result is:
>`/mnt/sdcard/a.out: permission denied`
command ls -l shows rights for a.out:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I tried to change permissions:
>chmod 777 /mnt/sdcard/a.out
But rights don't change:
>`----rwxr-x system sdcard_rw 863656 2012-04-12 22:42 a.out`
I think I have left some important thing using android.
Could anybody help me and give me a way how to run application in `Android SHELL?
Thanks a lot.
P.S. sorry for my English =)
By default, the SD card is mounted with option noexec, that disallows the execution of any file on the card, no matter what it's permissions(even -rwxrwxrwx), so you need to move the file to another location and then execute it.
The easiest is to move the file to /data/local/tmp/ and execute it using the full path (usual POSIX PATH semantics).
> adb push a.out /data/local/tmp/a.out
> adb shell
> chmod 755 /data/local/tmp/a.out
> /data/local/tmp/a.out
This does not require root access and survives reboot.
If you have rooted your phone you can do a mount -o remount,rw /mnt/sdcard and it should run.
I've tried it on my Android.

Categories

Resources