是否可以从 adb shell 中查看应用程序数据,就像我看到它安装 SD 卡一样?

发布于 2024-12-29 05:44:57 字数 949 浏览 1 评论 0原文

我正在测试 Android 应用程序。
关注内容

/sdcard/Android/data/com.myapplication   

我想在应用程序运行时 。
但如果 SD 卡作为磁盘驱动器安装在 PC 上(访问图片和视频),我的应用程序将无法正常工作。
所以我想我可以使用 adb shell。但它不允许我访问同一个文件夹:

ls /sdcard/Android/data/com.myapplication  
/sdcard/Android/data/com.myapplication: Permission denied

查看 Stack Overflow,我发现通过 adb shell 查看应用程序数据的方式:

run-as com.myapplication

这样做我发现自己在该文件夹中

/data/data/com.myapplication

我感到困惑的是我看到的数据这与我通过PC浏览SD卡内容看到的数据不同。

$ ls
ls
files
databases
shared_prefs
lib

我在文件下看到一些也在 sdcard Android/data/com.myapplication 文件夹下的东西,但不是我正在寻找的东西。此外,所有其他文件夹都不同。
之间是否存在关联

/data/data/com.myapplication

通过 adb 访问的此文件夹与

/sdcard/Android/data/com.myapplication 

通过 PC 访问的文件夹 ?
有没有办法在 adb shell 中查看后者中存在的文件?

I am testing an Android application.
I would like to keep an eye on the content of

/sdcard/Android/data/com.myapplication   

while the app is running.
But my app does not work correctly if the sd card is mounted as disk drive on PC (accesses pictures and videos).
So I thought I could use adb shell. But it doesn't let me access that same folder:

ls /sdcard/Android/data/com.myapplication  
/sdcard/Android/data/com.myapplication: Permission denied

Looking on Stack Overflow, I found this way to see application data via adb shell:

run-as com.myapplication

and doing so I find myself in the folder

/data/data/com.myapplication

What I'm confused about is that the data I see here are different from the data I see browsing the sdcard content via PC.

$ ls
ls
files
databases
shared_prefs
lib

I see under files something that was also under the sdcard Android/data/com.myapplication folder, but not what I was looking for. Besides, all other folders are different.
Is there a correlation between this

/data/data/com.myapplication

folder accessible via adb and the

/sdcard/Android/data/com.myapplication 

folder accessible via PC?
Is there a way to see in adb shell the files present in the latter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里人 2025-01-05 05:44:57

作为一般规则,位于内部存储上并由您的应用存储的文件(默认情况下不是WORLD_READABLE)仅可供您的应用读取。当您尝试使用 adb pull这些文件时,您将在未获得 root 权限的设备上获得拒绝权限。有一种方法可以解决这个问题,我稍后会解释。另一方面,外部存储中的文件可供用户和所有其他应用程序读取。所以这取决于你想要什么。

现在,为了读取内部存储中的文件 (/data /data/com.app.name)您无法直接读取这些文件,但您可以将它们移动到 外部存储,然后像这样从那里读取它们。

adb shell "run-as com.yourappName cat /data/data/com.yourappName/files/myfile.txt > /sdcard/Downloads/myfile.txt"

然后您可以从外部存储中提取文件,而不会出现权限问题。

adb pull /sdcard/Downloads/myfile.txt

如果您不确定哪个文件或想要浏览所有文件,请使用 shell 浏览所有应用程序文件。

adb shell
run-as yourappPackageName
cd /data/data/youappPackageName
ls -all

As a general rule, files that are on the Internal storage and stored by your app (by default not WORLD_READABLE) will only be available for your application to read. When you try to pull these files using adb pull you will get permission denied on a NOT rooted device. There is a way to go around this, I will explain later. Files in External storage on the other hand, are available to the User and to all other apps to read. so it depends on what you are after.

Now in order to read files in your internal storage (/data/data/com.app.name) you cannot read these files directly, but what you can do is move them to the external storage and then read them from there like this.

adb shell "run-as com.yourappName cat /data/data/com.yourappName/files/myfile.txt > /sdcard/Downloads/myfile.txt"

Then you can pull the file from the external storage with no permission issues.

adb pull /sdcard/Downloads/myfile.txt

If you are unsure about which file or you want to browse all the files, then user the shell to browse all your app files.

adb shell
run-as yourappPackageName
cd /data/data/youappPackageName
ls -all
谁把谁当真 2025-01-05 05:44:57

我已经能够通过以下 Adb 命令获取应用程序正在使用的 Sqlite DB:

adb exec-out run-as xxx.xxx.xxx.xxx cat "/data/data/xxx.xxx.xxx.xxx/databases/databasefile.db" > %userprofile%\Desktop\databasefile.db

其中 xxx.xxx.xxx.xxx 是 Android 应用程序的 bundleId,databasefile.db 是 Sqlite DB 的名称

所以我想你可以获取应用程序的任何现有文件,知道它在哪里,然后使用 adb exec-out run-as xxx.xxx.xxx.xxx 命令

I have been able to get the Sqlite DB the App is using with this Adb command:

adb exec-out run-as xxx.xxx.xxx.xxx cat "/data/data/xxx.xxx.xxx.xxx/databases/databasefile.db" > %userprofile%\Desktop\databasefile.db

Where xxx.xxx.xxx.xxx is the bundleId of your Android App, and databasefile.db is the name of the Sqlite DB

So I imagine you can get any existing file of the App, knowing where is it, and using the adb exec-out run-as xxx.xxx.xxx.xxx command

仄言 2025-01-05 05:44:57

您可以通过之前在博客中发布的实用程序来访问它。
它是一个java实用程序,通过它您只需提供应用程序的包名称即可获取应用程序数据文件夹中的所有文件夹。
只是应用程序需要可调试。

提取 Android 文件

确实有效

You can access it via utility which was posted earlier in a blog.
Its a java utility through which you can get the all folders in your application's data folder by just giving the package name of your application.
Just app needs to be debuggable.

Extract Android Files

Really works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文