我试图提取一个安装的Android应用程序的APK文件没有根权限。

我认为这是不可能的,因为所有非系统应用程序的APK文件都位于/data/app中,访问这个文件夹需要root权限。然后我发现谷歌Play商店中有许多应用程序似乎可以在非根设备上访问APK文件。

谁能告诉我这是怎么回事?难道没有备份程序可以备份APK文件吗?


当前回答

当你安装了Eclipse for Android开发时:

Use your device as debugging device. On your phone: Settings > Applications > Development and enable USB debugging, see http://developer.android.com/tools/device.html In Eclipse, open DDMS-window: Window > Open Perspective > Other... > DDMS, see http://developer.android.com/tools/debugging/ddms.html If you can't see your device try (re)installing USB-Driver for your device In middle pane select tab "File Explorer" and go to system > app Now you can select one or more files and then click the "Pull a file from the device" icon at the top (right to the tabs) Select target folder - tada!

其他回答

在Nougat(7.0) Android版本上运行adb shell pm list packages来列出设备上安装的包。 然后执行adb shell pm path your-package-name命令显示apk的路径。 使用adb复制包到下载adb shell cp /data/app/com.test-1/base.apk /storage/emulated/0/Download。 然后通过运行adb pull /storage/emulated/0/Download/base.apk将apk从Downloads拉到你的机器。

访问/data/app不需要root权限;该目录的权限为rwxrwx—x。对一个目录的执行权限意味着你可以访问它,但是缺乏读权限意味着你不能获得它的内容列表——所以为了访问它,你必须知道你要访问的文件的名称。Android的包管理器会告诉你一个给定包的apk的名称。

要从命令行执行此操作,请使用adb shell pm list packages来获取已安装包的列表并找到所需的包。

有了包名,我们可以使用adb shell pm path your-package-name获取APK的实际文件名和位置。

知道了完整的目录,我们最终可以使用adb拉/the.apk的完整/directory/来拉adb。APK文件存储在运行控制台的目录中。

感谢@tarn指出,在Lollipop下,apk路径将是/data/app/your-package-name-1/base.apk

我找到了一种在非根设备中获取APK包名的方法。 虽然不是很优雅,但是一直都很好用。

第一步:在您的设备上,打开目标APK

第二步:在PC的cmd窗口,输入以下命令:

 adb shell dumpsys activity a > dump.txt

因为这个命令的输出很多,所以建议重定向到一个文件。

步骤3:用任何编辑器打开这个dump.txt文件。

Android 4.4之前的设备: 文件的开头是这样的:

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)  
  Main stack:  
  * TaskRecord{41aa9ed0 #4 A com.tencent.mm U 0}  
    numActivities=1 rootWasReset=true userId=0  
    affinity=com.tencent.mm  
    intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10600000 cmp=com.tencent.mm/.ui.LauncherUI}  
    realActivity=com.tencent.mm/.ui.LauncherUI  
    askedCompatMode=false  
    lastThumbnail=null lastDescription=null  
    lastActiveTime=19915965 (inactive for 10s)  
    * Hist #9: ActivityRecord{41ba1a30 u0 com.tencent.mm/.ui.LauncherUI}  
        packageName=com.tencent.mm processName=com.tencent.mm 

包名在第三行,本例中为com.tencent.mm。

Android 4.4及以上版本: dumpsys的输出发生了一些变化。 尝试搜索“Stack #1”,包名会在它下面很近的地方。

另外,搜索“baseDir”,你会找到apk文件的完整路径!

当你安装了Eclipse for Android开发时:

Use your device as debugging device. On your phone: Settings > Applications > Development and enable USB debugging, see http://developer.android.com/tools/device.html In Eclipse, open DDMS-window: Window > Open Perspective > Other... > DDMS, see http://developer.android.com/tools/debugging/ddms.html If you can't see your device try (re)installing USB-Driver for your device In middle pane select tab "File Explorer" and go to system > app Now you can select one or more files and then click the "Pull a file from the device" icon at the top (right to the tabs) Select target folder - tada!

我得到了一个不存在的错误

以下是我如何做到的:

adb shell pm list packages -f | findstr zalo

package:/data/app/com.zing.zalo-1/base.apk=com.zing.zalo

adb shell

mido:/ $ cp /data/app/com.zing.zalo-1/base.apk /sdcard/zalo.apk
mido:/ $ exit


adb pull /sdcard/zalo.apk Desktop

/sdcard/zalo.apk: 1 file pulled. 7.7 MB/s (41895394 bytes in 5.200s)