Read Android Data Folder Without Rooting

I got my new galaxy s3 and I am all excited doing new android development. I fire up the adb shell to look around and I see this:

Grrrr. Ok so I can’t access the data folder because it is read protected. What do I do now? I can root the phone, but I don’t really want to do that for various reasons. All I really want is to see into my data folder application directories, be able to remove test files such as databases and preferences.

Turns out there is a simple solution, the run-as command.

That will allow you to run commands as your app. You can also use run-as in interactive mode.

Interactive mode will drop you into the data folder for your app. You can navigate from there.

For the run-as command to work the app must be debuggable. This means that run-as will work for apps that you are developing and have deployed through eclipse and for any apps that have been released with the debuggable flag turned on. It will not work for most android system and commercially released apps. Sorry, no hacking your favorite app this way.

Hope this helps save you some time and frustration.



14 Responses to “Read Android Data Folder Without Rooting”

  1. Ray Britton says:

    Wonderful, thank you for finding this, the android guide for the shell doesn’t mention this command at all. (http://developer.android.com/tools/help/adb.html#shellcommands)

  2. nil says:

    Can we pull files from myapp/data/files folder? I tried using below command but getting permission denied error.

    shell@android:/data/data/com.sample.activities/files $ run-as com.sample.a
    ctivities adb pull “/data/data/com.sample.activities/files/neuron.jpeg”
    data/com.sample.activities/files/neuron.jpeg” sh: run-as: cannot execute – Permission denied

    • Dennis Kubes says:

      I haven’t tried to pull files. I do know that this only works on applications that are debuggable. Which means it works for development apps but usually not deployed system apps.

    • Ben says:

      Check out the permissions for the files in ../files On my phone they were set to 600, so if you want to do a pull just “chmod 604 file”. After that you should be able to pull them off.

  3. Mr Zaphraud says:

    LOL great trolling. run-as is permission set to:
    -rws-r-s—
    and won’t run anyway unless a user is ALREADY root or at the very least, in the shell group. So much for “without rooting your phone”. That’s a rooted phone – maybe you got it that way, maybe not – but if you arbitrarily change your user ID like that, that’s every bit as good as root access.

    I mean, why not just do a
    $run-as root sh
    at this point?!?

    • Dennis Kubes says:

      I have a stock Samsung Galaxy S3 that I got from Best Buy. AFAIK those don’t come rooted. This is the only way I have found to look inside the data folder of the application I am developing. I use something like run-as com.package.name from adb shell. Even using eclipse DDMS views I can’t see into the phone’s app data folder. Pretty sure run-as root wouldn’t even work as it isn’t an app name by I haven’t tried that. From what I have seen run-as give you permission of the app, and only for apps that are set to debuggable true, so it doesn’t give you complete root access to the phone.

  4. kevin says:

    this is nice for removing/clearing your db. if you want to export a populated db, you can also run the following sequence:

    adb -d shell
    run-as com.your.packagename
    cat databases/database.db > /sdcard/database.db
    exit
    cd /sdcard
    ls -l <– check to make sure database.db is in here
    exit

    adb pull /sdcard/database.db

    you have to use this adb pull command because the file will be hidden in an explorer (mac/windows/linux)

    • Yulong says:

      Hi,

      when tried your method on my non-root phone, it says following at command “cat databases/database.db > /sdcard/test.db”:
      sh: can’t create /sdcard/test.db: Permission denied

      is this because not root?

      • Dennis Kubes says:

        The run-as would give you access to files and folder from the run-as user, which is usually the app package folder and subfolders. It wouldn’t give you access to the /sdcard folder. The /sdcard folder is not for mounted storage cards. Any mounted sdcard would be in something like /mnt/sdcard0 or /storage/sdcard0/ and is device specific.

    • Anon says:

      Worked for me on my non-rooted tablet! Thanks!

  5. Rácz Pál says:

    So…. I’am frustrating please help me! I’m not a expert android master just a siple player. I have a Nexus 7 and a game name is My Little Pony. So I would like backup my save file. This file location is
    /data/data/com.gameloft.android.ANMP.GloftPOHM/files/mlp_save.dat this folder protected but I would like saving this file and recover when it need (pull and push command)
    Have you any idea?

  6. [...] did a bit of Googling, and found a post about reading the /data directory without rooting. This turned me on to the run-as command in adb [...]