该答案基于我对其他答案的经验以及答案中的评论。我希望我可以帮助处于类似情况的人。
我正在通过终端在OSX上执行此操作。
以前,Vinicius Avellar的答案对我很有用。我只是大多数时候需要调试应用程序从设备中获取数据库。
今天,我有一个用例,其中需要多个私有文件。最后,我找到了两种适用于这种情况的解决方案。
将接受的答案与Someone Somewhere的OSX特定注释一起使用。创建一个备份,并使用第三方解决方案
sourceforge.net/projects/adbextractor/files/?source=navbar解压缩为tar。我将在此答案的底部写下有关该解决方案的更多经验。如果这是您想要的,请向下滚动。
我解决的一个更快的解决方案。我创建了一个脚本,用于提取多个文件,类似于Tamas的答案。之所以能够这样做,是因为我的应用程序是调试应用程序,并且可以在设备上运行方式。如果您无权运行-因为此方法不适用于OSX。
这是我的脚本,用于提取与读者共享的多个私人文件,读者也正在调查这个令人敬畏的问题;):
#!/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"`"
要旨:
https //gist.github.com/davethomas11/6c88f92c6221ffe6bc26de7335107dd4
返回方法1,使用解密备份 Android Backup Extractor
以下是我在Mac上执行的步骤以及遇到的问题:
首先,我将备份排队(并设置密码以加密备份,我的设备需要它):
adb backup -f myAndroidBackup.ab com.corp.appName
其次,我从这里下载了abe.jar:https ://sourceforge.net/projects/adbextractor/files/abe.jar/download
接下来我跑了:
java -jar ./abe.jar unpack myAndroidBackup.ab myAndroidBackup.tar
此时,我收到一条错误消息。因为我的存档已加密,所以java给我一个错误,我需要安装一些安全策略库。
最后,我刚运行(再次运行上一个命令后)
tar xvf myAndroidBackup.tar
现在,重要的是要注意,如果您可以同时运行和运行,则速度要快得多。一,您只获得所需的文件,而不是整个应用程序。第二,更多的文件(对我而言+加密)使传输速度变慢。因此,如果您没有在OSX上运行,那么知道这样做的方法很重要,但是该脚本应该首先用于调试应用程序。
请注意,我今天才写它,并对其进行了几次测试,因此,如有任何错误,请通知我!