I want to get the /data/data/packagename/databases/test.db, but i can not get it "Permission denied".
I use adb shell to access data folder, it shows:
$ sudo adb shell
$ cd data
$ ls
ls: can't open '.': Permission denied
why?? I can access /system folder
You need to be a root user to do that.
First your phone should be rooted, you can use https://www.kingoapp.com/ for that.
Next, you should modify the permission of your app access, to do so you have to :
Locate your adb.exe folder (you can find it in your sdk folders)
Right click
open cmd here
Type:
adb shell
su
chmod 777 /data /data/data /data/data/yourapp
Good luck
Related
I have debbugable app, and I need to copy file to phone, and back after. I use this command and receive error.
adb shell run-as app cp /data/data/app/shared_prefs/app_preferences.xml /storage/emulated/0
cp: /storage/emulated/0/app_preferences.xml: Operation not permitted
I tryied to edit file
adb shell run-as app "echo test > /data/user/0/app/shared_prefs/app_preferences.xml"
/system/bin/sh: can't create /data/data/app/shared_prefs/app_preferences.xml: Permission denied
But if I try
adb shell
run-as app
echo test > /data/user/0/app/shared_prefs/app_preferences.xml
This way I able to edit file, but cp not. Also via Android Studio I can save and upload file.
In total, how to edit in one command or copy file?
How do install a *.apk from adb command line?
First I tried to cp the *.apk from /sdcard/backups/apps to /system/app (after rw mounting the file system of course)
I did successfully move it to /system/app but the *apk was not "installed"
I used this code :-
**
adb shell
su
mount -o rw,remount /system
adb shell
su
cd /sdcard
mv com.ogp.gpstoggler-1.apk /system/priv-app
finally after I write
chown 644 /system/priv-app/com.ogp.gpstoggler-1.apk
and press enter the result is
Unable to open /system/priv-app/com.ogp.gpstoggler-1.apk: No such file or direc
tory***
how to fix this ? thank you ?
Instead of using "mv" use "cp" to copy it to system/priv-app folder.
Ensure it is in the priv-app folder using "ls"
use chmod 777 to give it privileges
Ensure it has the correct privileges using "ls -l"
use "adb reboot" to have the system install the application.
Edit
One thing I forgot to note - if you go into the system/priv-app folder and you see that all the other APK's are in their own folders, you might also have to create a folder for your apk.
mkdir system/priv-app/app_name
cp app_name.apk system/priv-app/app_name
cd system/priv-app/app_name
chmod 777 system/priv-app/app_name/app_name.apk
adb reboot
I am unable to pull a the database from the device even after changing the permission. I have a rooted phone.
It used to work. I could pull before. For some unknown reason now I cannot.
The error I receive is
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
Does anybody know why this is happening?
Below is what I did in command window.
C:\users\thupten>adb shell
shell#android:/ $ su
su
root#android:/ # cd /data/data/com.thuptencho.transitbus/databases/
cd /data/data/com.thuptencho.transitbus/databases/
root#android:/data/data/com.thuptencho.transitbus/databases # ls
ls
ttc.db
ttc.db-journal
webview.db
webview.db-journal
webviewCookiesChromium.db
webviewCookiesChromiumPrivate.db
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 755 ttc.db
5 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 777 ttc.db
7 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # exit
exit
shell#android:/ $ exit
exit
C:\users\thupten>adb pull /data/data/com.thuptencho.transitbus/databases/ttc.db
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
I using these commands to get data from /data/data folders, no changing permission required
adb kill-server
adb root
I figured it out.
I had to chmod the databases folder as well and then the file.
The problem is that you need permission not just to the file, but also to its parent directories.
(That permission should not be 777 though!)
Rather than trying to change the permission, what you probably want to do is get adb running as root if that is supported, (ie, if you have an engineering build, rather than an aftermarket "rooting" of a secured device) or else use your root access (or the app itself, or the stock run-as command if you have a debug apk) to copy the file of interest somewhere accessible and then adb pull the copy.
My preferred solution was:
Install Chainfire's adbd insecure app
From within the adbd insecure app, select "Enable Insecure adbd"
adb pull /data/data/com.package.name/databases/database.db
Caution - adb insecure means adb is running as root on your device.
for i in `adb shell ls /data/ -1`;do adb pull /data/$i data; done
how to give write permission to system/app folder
i have rooted my android device
i want to download the app and install in system/app folder
Process p = Runtime.getRuntime().exec( "su" );
i had tried this command it ask for user permission and then it throws exception
system/app is read only file system
First go to shell using
adb shell
Then remount the system folder as writable using following commands
$ su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
Then change the permission of system folder to Read, Write and Execute using
# chmod 777 /system/app
Just type in your android device terminal
su
and then
chmod 777 system/app
su- grants you superuser permission
and chmod 777 file, change the permissions of the file to read, write, and execute..
Try adb remount in terminal.
If you want to do it from the device shell, see this question on how to remount the file system with write permission.
Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privileges on the phone?
For example, I know the location on my rooted magic and dream is:
/data/data/com.xxxx.xxxx/databases/xxxx
I know that you can use ADB without root, but when trying to use the shell - you can't view that location without root privaliges. But I have been told you can use push and pull if you know the file you want?
Basically I want to pull a database from MY app on a non rooted phone modify it and push it back on.
Only trouble I have is, the two phones I have are both root and I don't have access to a non root one to try it out.
While Nilhcem's answer didn't work for me, it lead me in the right direction (for that I upvoted) and I now have a working solution.
Old answer that may not work with newer versions of Android:
#Transfer file from app databases directory to PC
adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/
#Transfer file from PC to app databases directory (requires the above permission change)
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
Alternate method using external storage (confirmed to work with 6.0.1):
#Transfer file from app databases directory to external storage
adb shell
$ run-as package.name
$ cp ./databases/dbname.db /sdcard/
$ exit
$ exit
#Transfer file from external storage to app databases directory
adb shell
$ run-as package.name
$ cp /sdcard/dbname.db ./databases/
$ exit
$ exit
A quick workaround is to use the run-as command to copy the database in a folder where you can have access, such as /sdcard and then, do a normal adb pull
adb shell
$ run-as package.name cp /data/data/package.name/dbname.db /sdcard/
$ exit
adb pull /sdcard/dbname.db
More information on the run-as command here
Note that the run-as command is available since API level 8 (Android 2.2) and can only be used if the application is debbugable.
On OxygenOS (based on Android 5.2) I've combined the two solutions provided by Pilot_51.
First, I used run-as to gain access to /data/data/package.name/databases, but from here I wasn't able to copy directly to /sdcard/ so I changed the permissions of the file. After that, I exited from run-as mode and used cp to copy the file in /sdcard/ storage. Finally, I was able to use adb pull
$ adb -s <DEVICE_ID> shell
$ run-as package.name
$ chmod 666 databases/dbname.db
$ exit
$ cp /data/data/package.name/databases/dbname.db /sdcard/dbname.db
$ exit
$ adb pull /sdcard/dbname.db ./dbname.db
We set the file permissions to readable for all users from within the app.
if (BuildConfig.DEBUG)
{
new File(mDB.getPath()).setReadable(true, false);
}
Then just pull the .db off with adb normally.
adb -d pull //data/data/xxxxx/databases/xxxxx.db .
NOTE: I've discovered that this needs to be done each time the database file is opened, for example in onCreate as well as the constructor of your SQLiteOpenHelper wrapper (when your database is not null) or perhaps onOpen. If only in onCreate, then the next time you run your app and the .db already exists, for some reason the permissions have been changed back. This might have something to do with how Android manages its data.
if you want to push db file into the application
first of all, place "file.db" under "/storage/emulated/0/" because of permission issue. then you should pretend as application to access data folder.
adb shell
$ run-as com.package.name
:/data/data/com.package.name $ cp /storage/emulated/0/file.db /data/data/com.package.name/databases/
it copies the file.db that in main folder to databases.