使用条件
app是可调试状态
在不root手机的情况下读取Data目录下的文件
read-android-data-folder-without-rooting
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.
1.使用adb命令时的错误
如果直接使用adb命令会产生以下错误:
127|shell@android:/ $ cd /data
cd /data
shell@android:/data $ ls
ls
opendir failed, Permission denied
你是没有权限的。
2.正确使用adb读取data目录下的文件方式
shell@android:/data $ run-as com.your.package
run-as com.your.package
shell@android:/data/data/com.your.package $ cd /data/data/com.your.package
cd /data/data/com.your.package
shell@android:/data/data/com.your.package $ ls
ls
cache
databases
lib
shared_prefs
shell@android:/data/data/com.your.package $ cd databases
cd databases
shell@android:/data/data/com.your.package/databases $ ls
yourpackagename.db
$ cat preferences.db > /mnt/sdcard/yourpackagename.db
将你要访问的package目录下的db文件拷贝到sdcard中,这样就可以正常访问了!
3.对于第三方apk
使用反编译工具反编译后在AndroidMainfest.xml加上可调试:
android:debuggable="true",再回编成apk,再安装进手机即可使用run-as。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true">