Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve database or any other file from the Internal Storage using run-as

On a non-rooted android device, I can navigate to the data folder containing the database using the run-as command with my package name. Most files types I am content with just viewing, but with the database I would like to pull if from the android device.

Is there a download copy or move command from this part of adb shell? I would like to download the database file and view its content using a database browser.

One answer here involves turning entire application package into a compressed archive, but there is no further answer on how to extract that archive once this is done and moved to the machine, leaving me very sidetracked when there might be a more direct solution to begin with

like image 821
CQM Avatar asked Aug 27 '13 17:08

CQM


People also ask

How we can store and retrieve data in internal and external storage?

Storage on the Inside To save a file to the internal storage, you must first obtain it from the internal directory. You can do this by calling the getFilesDir() or getCacheDir() methods. The getFilesDir() method returns the absolute path to the directory where files are created on the filesystem.

What is ADB exec out?

Resolution. Use the ADB option exec-out instead of shell in the screencap command. For example, adb exec-out screencap screenshot. png. This command will store the screenshot direct on your PC in the folder where you have started the command.


2 Answers

By design user build of Android (that's what you have on your phone until you unlock the bootloader and flash the phone with userdebug or eng software) restricts access to the Internal Storage - every app can only access its own files. Fortunately for software developers not willing to root their phones Google provides a way to access the Internal Storage of debuggable versions of their packages using run-as command.

To download the /data/data/debuggable.app.package.name/databases/file from an Android 5.1+ device run the following command:

adb exec-out run-as debuggable.app.package.name cat databases/file > file 

To download multiple files in a folder under the /data/data/debuggable.app.package.name/ at once - use tar:

adb exec-out run-as debuggable.app.package.name tar c databases/ > databases.tar adb exec-out run-as debuggable.app.package.name tar c shared_prefs/ > shared_prefs.tar 
like image 117
Alex P. Avatar answered Sep 21 '22 19:09

Alex P.


The accepted answer doesn't work anymore for me (blocked by Android?)

So instead I did this:

> adb shell shell $ run-as com.example.package shell $ chmod 666 databases/file shell $ exit                                               ## exit out of 'run-as' shell $ cp /data/data/package.name/databases/file /sdcard/ shell $ run-as com.example.package shell $ chmod 600 databases/file > adb pull /sdcard/file . 
like image 45
marmor Avatar answered Sep 21 '22 19:09

marmor