Why does data folder in android simulator deny permission? - android

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.

Related

Connected to my android device using ADB but not able to use ls command, it says permission denied

I connected to my android device (stock android, 10) using ADB on ubuntu, now when I go to /data/ and do ls, it says permission denied.
Why? How to solve this problem?
Once you enter the ADB shell(adb -s your_ip:5555 shell), you can use run-as com.example.app to access the data folder of a specific application.
Replace "com.example.app" with your package name
The user id used in adb shell sessions is different from the one that created the data folder (and subfolders). The permissions' set are drwxrwx--x that means --x for everyone, i.e., execute only.
What you can do is to go into the different folders using cd command or using Android Studio's Device File Explorer, more info here.

how to change the adb target shell root directory with my pre-defined directory

i have my android device, whenever I am opening the adb client and giving the "adb shell" command, it is directly getting root directory.or if I want to push any file directly I am using adb push file.exe /data/ like this. but as per my requirement, nobody should able to access the root directory if they are trying to connect my device to PC. So I want to know the changes what i need to do so that before "adbd" launch, i will give a pre-defined directory, so that if anyone will push any file with that directory, only it will work or else it will fail.
I want to protect the adb shell, so that only my given directory someone can push any file except this all other access should prevent means no access.
I can say adb shell should not work etc. Only adb push should work.

Copy folder from Android app to local Windows directory

I'm trying to use the Android Adb Command Prompt to copy a folder inside the app container to a local Windows folder. The device is running Android 5.1.1 and is not rooted.
adb pull or cp aren't working. How can I copy a folder?
The following approaches aren't working:
Approach 1
adb shell
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
error: device not found
Inside the shell you can't see to do adb pull. See here.
Approach 2
DDMS can't access the data folder.
Approach 3
adb shell
run-as DroidSample.DroidSample
cp /files/MetroLog/MetroLogs/ C:/temp/test
cp: /files/MetroLog/MetroLogs/: No such file or directory
Approach 4
adb shell
run-as DroidSample.DroidSample
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs/ C:/temp/test
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs is a directory (not copied).
This is also not working.
Approach 5
adb shell
run-as DroidSample.DroidSample
chmod 777 /files/MetroLog/MetroLogs
exit
exit
adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
adb shell run-as DroidSample.DroidSample
chmod 700 /files/MetroLog/Metrologs
remote object '/data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs' does not exist
So also this isn't working.
Approach 6
adb shell
mkdir /sdcard/tmp
cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs /sdcard/tmp
cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs: Permission denied
This is also not working.
Approach 7
The only thing which half work is this
adb exec-out run-as DroidSample.DroidSample cat "files/MetroLog/MetroLogs/Log - 20160509.log" > C:/temp/test/test.log
But here I don't get the original file and I also have to know the exact file name. Additionally, that I loose line breaks and I have to do this for each file. Not that what I want.
So I'm running out of ideas. How can I access the internal stored files and copy them over?
You have almost solved the problem. As the storage of this kind is secured, you need to do one additional step. You need to copy the file from secured location to sdcard of the device. And then you can copy it anywhere via usb or android pull. Here are the command sequence I executed successfully.
adb shell
run-as DroidSample.DroidSample
cd shared_prefs
cp DroidSample.DroidSample_preferences.xml /sdcard/DroidSample.DroidSample_preferences.xml
exit
exit
adb pull /sdcard/DroidSample.DroidSample_preferences.xml C:/test/
That's it.
And I really appreciate the way you posted your question. Best of luck.
You're trying to gain read access to /data partition on actual android device. Such thing is not possible without root access, even if the app folder is yours. For the reason that permissions to read /data partition are not granted and cannot be granted, unless you're using an emulator. On emulator, which by default is with admin privileges for developer, you can access the data partition to read and write. On actual device you cannot. Not with adb, not with DDMS.
So basically speaking, anything that requires access to those files under /data is not going to work. Whether you sue cp command or pull command. The moment your kernel reads the beginning of your path which starts with /data/... it says: Oops, no can do.
You are trying to access /data folder of android device which is not accessible in unrooted device.

android : unable to run shell script(.sh) from my application

i am not able to run shell scripts from my application.only "ls -l" and echo commands respond.rest dont seem to do anything.not even "touch" command works.i tried creating a file in sdcard using touch command in my script..only the echo command worked.my shell script is in sdcard too
The sdcard is mounted with noexec. You will have to copy the scripts to the app's local data drive to execute.
You should be able to see the mounted permissions of all file-systems by logging into the phone (adb shell or whatever else) and typing mount
The rest of the commands like "cd" etc doesnot work in Android as it encounters lot of permission issues.
So the best solution is to trigger "script manager" or "terminal emulator" apps already available through your app.

Am I rooted or not?

I am trying to figure out if my Android device is rooted or not. The Superuser app is no where to be found. In a terminal emulator on my phone, I can't type the command su, and the command id reports that I'm not root. However, when I use the adb shell, I have full root access to the phone, which is confusing to me. Does this mean I'm rooted, or not?
I believe the build you are using is either debug or userdebug.
In this case apps cannot get root access since su is not present. Only ADB_SHELL will get root access.
You can push precompiled su to /system/bin after executing a adb remount
Edit: If you want root access from apps then follow this thread

Categories

Resources