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

后端 未结 12 2227
清酒与你
清酒与你 2020-11-22 11:01

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 c

相关标签:
12条回答
  • 2020-11-22 11:24

    I couldn't get anything else to work for me but this:

    adb shell
    run-as package.name
    cat /databases/databaseFileName.db > /sdcard/copiedDatabaseFileName.db
    exit
    exit
    adb pull /sdcard/copiedDatabaseFileName.db /file/location/on/computer/
    

    The first exit is to exit out of the run-as, the second exit is to exit out of adb shell to do the pull.

    0 讨论(0)
  • 2020-11-22 11:28

    If anyone looking for pulling database from debug application may use the procedure below:

    1. search and open device file explorer

    1. Select your handset and then browse to data/data directory

    1. Now find your application package and go to databases folder. You can see the databases there and upon right click, you will get option to save this in your drive.

    0 讨论(0)
  • 2020-11-22 11:28

    I've published a simple shell script for dumping databases:

    https://github.com/Pixplicity/humpty-dumpty-android

    It performs two distinct methods described here:

    1. First, it tries to make the file accessible for other users, and attempting to pull it from the device.
    2. If that fails, it streams the contents of the file over the terminal to the local machine. It performs an additional trick to remove \r characters that some devices output to the shell.

    From here you can use a variety of CLI or GUI SQLite applications, such as sqlite3 or sqlitebrowser, to browse the contents of the database.

    0 讨论(0)
  • 2020-11-22 11:29

    Steps to pull app db(installed in debug mode) from device

    Close DB connection if opened

    Open cmd (command prompt) (Change dir to your adb path)

    cd C:\Program Files (x86)\Android\android-sdk\platform-tools

    (list the app files)

    adb -d shell "run-as com.xyz.name ls /data/data/com.xyz.name/files/"

    (copy required file to sdcard)

    adb -d shell "run-as com.xyz.name cp /data/data/com.xyz.name/files/abc.db /sdcard/abc.db"

    (copy from sdcard to machine adb folder)

    adb pull /sdcard/abc.db

    Open DB connection

    Destination file path in my case C:\Users{userName}\AppData\Local\VirtualStore\Program Files (x86)\Android\android-sdk\platform-tools Or Device storage

    0 讨论(0)
  • 2020-11-22 11:30

    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 .
    
    0 讨论(0)
  • 2020-11-22 11:36

    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
    
    0 讨论(0)
提交回复
热议问题