How can I pull (private) data from one native Android application?

Trying to pull one file with

adb pull /data/data/com.corp.appName/files/myFile.txt myFile.txt 

not working with

 failed to copy '/data/data/com.corp.appName/files/myFile.txt myFile.txt' to 'myFile.txt': Permission denied 

even though USB debugging is enabled on the device.

We can solve the problem through an archaic route

 adb shell run-as com.corp.appName cat files/myFile.txt > myFile.txt 

but it is cumbersome for more than one file.

How can I pull out the /data/data/com.corp.appName/files directory on my MacBook?

Doing this directly or through transit to `/ storage / sdcard0 / myDir (from where I can continue to transfer Android files) is fine.

Additional comment

It is possible that only launch

 adb backup -f myFiles com.corp.appName 

will generate the files I'm looking for. In this case, I'm looking for a way to unzip / unzip the resulting backup!

+64
android adb
Mar 21 '13 at 21:19
source share
12 answers

adb backup will write an archive for Android:

 adb backup -f myAndroidBackup.ab com.corp.appName 

This archive can be converted to tar format using:

 dd if=myAndroidBackup.ab bs=24 skip=1 | openssl zlib -d > myAndroidBackup.tar 

Link:

http://nelenkov.blogspot.ca/2012/06/unpacking-android-backups.html

Find "Update" at this link.




Alternatively, use the Android file extractor to delete files to extract files from the Android backup file ( .ab ).

+62
Mar 21 '13 at 22:17
source share
β€” -

I had the same problem, but I decided that it works as follows:

 $ adb shell $ run-as {app-package-name} $ cd /data/data/{app-package-name} $ chmod 777 {file} $ cp {file} /mnt/sdcard/ 

After that you can run

 $ adb pull /mnt/sdcard/{file} 
+34
Jun 05 '15 at 6:54
source share

Here is what worked for me:

 adb -d shell "run-as com.example.test cat /data/data/com.example.test/databases/data.db" > data.db 

I print the database directly in a local file.

+18
Jul 19 '15 at 18:03
source share

On MacOSX, combining the answers from Calaf and Ollie Ford, it worked for me.

On the command line (make sure adb is in your path, mine was in ~ / Library / Android / sdk / platform-tools / adb), and your Android device is connected and in USB debugging mode, run:

  adb backup -f backup com.mypackage.myapp 

Your Android device will ask for permission to back up your data. Select "BACKUP MY DATA"

Wait a few minutes.

The backup copy of the file will appear in the directory in which you ran adb.

Now run:

 dd if=backup bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" > backup.tar 

You will now have a backup.tar file that you can unzip as follows:

  tar xvf backup.tar 

And look at all the files stored in your application.

+14
Aug 27 '15 at 21:56
source share

You can use this shell script below. It can also extract files from the application cache, and not as an adb backup tool:

 #!/bin/sh if [ -z "$1" ]; then echo "Sorry script requires an argument for the file you want to pull." exit 1 fi adb shell "run-as com.corp.appName cat '/data/data/com.corp.appNamepp/$1' > '/sdcard/$1'" adb pull "/sdcard/$1" adb shell "rm '/sdcard/$1'" 

Then you can use it as follows:

 ./pull.sh files/myFile.txt ./pull.sh cache/someCachedData.txt 
+6
Jul 09 '14 at 16:16
source share

This answer is based on my experience with other answers and comments in the answers. I hope that I can help someone in a similar situation.

I do this on OSX via terminal.

Vinicius Avellar's answer worked fine for me before. I only ever most of the time needed a database from a device from a debugging application.

Today I had a use case where I needed several personal files . I ended up with two solutions that worked well for this case.

  • Use the accepted answer along with some Someone Somewhere OSX special comments. Back up and use a third-party solution, sourceforge.net/projects/adbextractor/files/?source=navbar to unzip to tar. I will write more about my experience with this solution at the bottom of this answer. Scroll down if this is what you are looking for.

  • Faster solution I agreed with. I created a script to pull out several files similar to Tamas answer. I can do it this way because my application is a debugging application and I have run-as on access to my device. If you do not have access to run, because this method will not work for you on OSX.

Here is my script for pulling out a few personal files that I will share with you, a reader who is also exploring this amazing question;):

 #!/bin/bash # # Strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail IFS=$'\n\t' # # Usage: script -f fileToPull -p packageName # # This script is for pulling private files from an Android device # using run-as. Note: not all devices have run-as access, and # application must be a debug version for run-as to work. # # If run-as is deactivated on your device use one of the # alternative methods here: # http://stackoverflow.com/questions/15558353/how-can-one-pull-the-private-data-of-ones-own-android-app # # If you have encrypted backup files use: # sourceforge.net/projects/adbextractor/files/?source=navbar # From comments in the accepted answer in the above SO question # # If your files aren't encrypted use the accepted answer # ( see comments and other answers for OSX compatibility ) # # This script is open to expansions to allow selecting # device used. Currently first selected device from # adb shell will be used. #Check we have one connected device adb devices -l | grep -e 'device\b' > /dev/null if [ $? -gt 0 ]; then echo "No device connected to adb." exit 1 fi # Set filename or directory to pull from device # Set package name we will run as while getopts f:p: opt; do case $opt in f) fileToPull=$OPTARG ;; p) packageName=$OPTARG ;; esac done; # Block file arg from being blank if [ -z "$fileToPull" ]; then echo "Please specify file or folder to pull with -f argument" exit 1 fi # Block package name arg from being blank if [ -z "$packageName" ]; then echo "Please specify package name to run as when pulling file" exit 1 fi # Check package exists adb shell pm list packages | grep "$packageName" > /dev/null if [ $? -gt 0 ]; then echo "Package name $packageName does not exist on device" exit 1 fi # Check file exists and has permission with run-as fileCheck=`adb shell "run-as $packageName ls $fileToPull"` if [[ $fileCheck =~ "Permission denied" ]] || [[ $fileCheck =~ "No such file or directory" ]]; then echo "Error: $fileCheck" echo "With file -> $fileToPull" exit 1 fi # Function to pull private file # # param 1 = package name # param 2 = file to pull # param 3 = output file function pull_private_file () { mkdir -p `dirname $3` echo -e "\033[0;35m***" >&2 echo -e "\033[0;36m Coping file $2 -> $3" >&2 echo -e "\033[0;35m***\033[0m" >&2 adb shell "run-as $1 cat $2" > $3 } # Check if a file is a directory # # param 1 = directory to check function is_file_dir() { adb shell "if [ -d \"$1\" ]; then echo TRUE; fi" } # Check if a file is a symbolic link # # param 1 = directory to check function is_file_symlink() { adb shell "if [ -L \"$1\" ]; then echo TRUE; fi" } # recursively pull files from device connected to adb # # param 1 = package name # param 2 = file to pull # param 3 = output file function recurse_pull_private_files() { is_dir=`is_file_dir "$2"` is_symlink=`is_file_symlink "$2"` if [ -n "$is_dir" ]; then files=`adb shell "run-as $1 ls \"$2\""` # Handle the case where directory is a symbolic link if [ -n "$is_symlink" ]; then correctPath=`adb shell "run-as $1 ls -l \"$2\"" | sed 's/.*-> //' | tr -d '\r'` files=`adb shell "run-as $1 ls \"$correctPath\""` fi for i in $files; do # Android adds nasty carriage return that screws with bash vars # This removes it. Otherwise weird behavior happens fileName=`echo "$i" | tr -d '\r'` nextFile="$2/$fileName" nextOutput="$3/$fileName" recurse_pull_private_files "$1" "$nextFile" "$nextOutput" done else pull_private_file "$1" "$2" "$3" fi } recurse_pull_private_files "$packageName" "$fileToPull" "`basename "$fileToPull"`" 

Essence: https://gist.github.com/davethomas11/6c88f92c6221ffe6bc26de7335107dd4




Return to method 1 , decrypt backup using Android Backup Extractor

Here are the steps I took on my Mac and the problems I encountered:

First I queued a backup (and set a password to encrypt my backup, my device required it):

 adb backup -f myAndroidBackup.ab com.corp.appName 

The second I downloaded only abe.jar from here: https://sourceforge.net/projects/adbextractor/files/abe.jar/download

Next I ran:

 java -jar ./abe.jar unpack myAndroidBackup.ab myAndroidBackup.tar 

At this point, I received an error message. Since my archive is encrypted, java gave me the error that I needed to install some security policy libraries.

  • So, I went to http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html and downloaded the security banks I needed. Now in my case, the installation instructions told me the wrong location to put the jar files. It states that the correct location is <java-home> / lib / security . I put them there first and still got an error message. So I researched, and on my Mac with Java 1.8, the right place to host them was: <java-home> / jre / lib / security . I made a backup of the original policy flags and put them there. Vola I was able to enter the password using abe.jar and decrypt the tar file.

Finally, I just ran (after re-executing the previous command)

 tar xvf myAndroidBackup.tar 

Now it’s important to note that if you can just run like a cat, it’s much faster. First, you only get the files you want, not the whole application. Two, the more files (+ encryption for me) slows down the transfer. Therefore, knowing this method is important if you are not running, as in OSX, but the script should be the first goto for the debugging application.

Remember, I just wrote it today and tested it several times, so please let me know about the errors!

+2
Oct. 12 '16 at 23:10
source share

After setting the correct permissions, adding the following code:

 File myFile = ...; myFile.setReadable(true, false); // readable, not only for the owner 

adb pull works as desired.

see File.setReadable ()

+1
Jul 02 '13 at 12:37
source share

Starting form Dave Thomas script I was able to write my own solution to overcome 2 problems:

  • my backup contained only a manifest file
  • binary files received with Dave Thomas that are not readable

This is my script that copies application data to an SD card and then pulls it out

 #Check we have one connected device adb devices -l | grep -e 'device\b' > /dev/null if [ $? -gt 0 ]; then echo "No device connected to adb." exit 1 fi # Set filename or directory to pull from device # Set package name we will run as while getopts f:p: opt; do case $opt in f) fileToPull=$OPTARG ;; p) packageName=$OPTARG ;; esac done; # Block package name arg from being blank if [ -z "$packageName" ]; then echo "Please specify package name to run as when pulling file" exit 1 fi # Check package exists adb shell pm list packages | grep "$packageName" > /dev/null if [ $? -gt 0 ]; then echo "Package name $packageName does not exist on device" exit 1 fi adb shell "run-as $packageName cp -r /data/data/$packageName/ /sdcard/$packageName" adb pull /sdcard/$packageName adb shell rm -rf /sdcard/$packageName 
+1
Mar 05 '17 at 11:53 on
source share

Similar to Tamas Answer , here is one liner for Mac OS X to extract all the files for the application from your.app.id from your device and save them to (in this case) ~/Desktop/your.app.id :

 ( id=your.app.id && dest=~/Desktop && adb shell "run-as $id cp -r /data/data/$id /sdcard" && adb -d pull "/sdcard/$id" "$dest" && if [ -n "$id" ]; then adb shell "rm -rf /sdcard/$id"; fi ) 
  • Exclude -d to pull out of emulator
  • Does not stomp your session variables
  • You can insert the entire block in Terminal.app (or delete new lines if desired)
+1
Jun 21 '17 at 1:39 on
source share

If you are using a Mac computer and a Samsung phone, this is what you need to do (since run-as does not work on Samsung and zlib does not work on Mac)

  • Back up your adb backup -f /Users/username/Desktop/data.ab com.example application data directory adb backup -f /Users/username/Desktop/data.ab com.example

  • You will be asked to enter a password for encryption on your phone, do not enter it. Just click "Back Up My Data." See How to take BackUp?

  • After a successful backup, you will see the data.ab file on the desktop. Now we need to convert this to tar format.

  • To do this, use the Android Backup Screen . Download | Sourcecode

  • Download it and you will see the abe.jar file. Add this to your PATH variable.

  • Run this to generate the tar file: java -jar abe.jar unpack /Users/username/Desktop/data.ab /Users/username/Desktop/data.tar

  • Extract the data.tar file to access all files

+1
Jan 03 '18 at 12:02
source share

Backing up game data with apk . Nougat Oneplus 2.

 **adb backup "-apk com.nekki.shadowfight" -f "c:\myapk\samsung2.ab"** 
0
Apr 27 '17 at 5:57 on
source share

Does this mean that you can chmod from a directory from the world: - x to the world: rx long enough to be able to extract files?

Yes exactly. Oddly enough, you also need a file to set the x bit. (at least on Android 2.3)

chmod 755 worked all the way to copy the file (but you must again grant permissions if you plan to continue using the device).

0
Nov 10 '17 at 9:16 on
source share



All Articles