使用libimobiledevice&ifuse提取iOS沙盒文件

时间:2022-07-23
本文章向大家介绍使用libimobiledevice&ifuse提取iOS沙盒文件,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

使用libimobiledevice&ifuse提取iOS沙盒文件

转载原文

一、libimobiledevice简介及使用方法

1.1 简介

libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod TouchiOS设备。由于苹果官方并不支持Linux系统,但是Linux上的高手绝对不能忍受因为要连接iOS设备就换用操作系统这个事儿。因此就有人逆向出iOS设备与Windows/Mac Host接口的通讯协议,最终成就了横跨三大桌面平台的非官方版本USB接口library。经常用Linux系统的人一定对libimobiledevice不陌生,但是许多WindowsMac用户也许就不知道了。事实上,它同iTools一样,都是可以替代iTunes,进行iOS设备管理的工具。因为源码是开放的,可以自行编译,所以对很多开发者而言可以说更为实用。

github官方地址:https://github.com/libimobiledevice/libimobiledevice

1.2 安装

仅演示mac下的安装方法,其它平台请自行google。在MacOS下安装可以使用brew,具体过程如下:

sudo brew update
sudo brew install libimobiledevice
sudo brew install ideviceinstaller

1.3 常用功能

查看当前所连接的设备
idevice_id -l                     # 显示当前所连接的设备[udid],包括 usb、WiFi 连接
instruments -s devices      # 列出设备包括模拟器、真机及 mac 电脑本身
安装应用 xxx.ipa为应用在本地的路径。
ideviceinstaller -u [udid] -i [xxx.ipa]        # 给指定连接的设备安装应用
卸载应用 bundleId为应用的包名。
ideviceinstaller -u [udid] -U [bundleId]      # 给指定连接的设备卸载应用
查看设备已安装的应用
ideviceinstaller -u [udid] -l                        # 指定设备,查看安装的第三方应用
ideviceinstaller -u [udid] -l -o list_user      # 指定设备,查看安装的第三方应用
ideviceinstaller -u [udid] -l -o list_system  # 指定设备,查看安装的系统应用
ideviceinstaller -u [udid] -l -o list_all         # 指定设备,查看安装的系统应用和第三方应用
获取设备信息
ideviceinfo -u [udid]                                # 指定设备,获取设备信息
ideviceinfo -u [udid] -k DeviceName         # 指定设备,获取设备名称:iPhone6s
idevicename -u [udid]                              # 指定设备,获取设备名称:iPhone6s
ideviceinfo -u [udid] -k ProductVersion     # 指定设备,获取设备版本:10.3.1
ideviceinfo -u [udid] -k ProductType         # 指定设备,获取设备类型:iPhone8,1
ideviceinfo -u [udid] -k ProductName        # 指定设备,获取设备系统名称:iPhone OS

二、挂载文件系统工具ifuse使用简介

ifuse是一个依赖libimobiledevice库的工具,所以必须首先安装libimobiledevice。 安装方式:

brew cask install osxfuse
brew install ifuse

安装好后使用ifuse -h会打印详细使用说明

Usage: ifuse MOUNTPOINT [OPTIONS]
Mount directories of an iOS device locally using fuse.
      -o opt,[opt...]    mount options
      -u, --udid UDID    mount specific device by its 40-digit device UDID
      -h, --help        print usage information
      -V, --version        print version
      -d, --debug        enable libimobiledevice communication debugging
      --documents APPID    mount 'Documents' folder of app identified by APPID
      --container APPID    mount sandbox root of an app identified by APPID
      --root        mount root file system (jailbroken device required)
Example:
  $ ifuse /media/iPhone --root
  This mounts the root filesystem of the first attached device on
  this computer in the directory /media/iPhone.

挂载媒体文件目录:

注意,此处的挂载点必须要真实存在,需要预先创建好目录,否则挂载失败

ifuse [挂载点]

卸载挂载点

fusermount -u [挂载点]

挂载某个应用的documents目录

ifuse --documents [要挂载的应用的bundleID] [挂载点]
//注意,iOS 8.3之后要求应用的UIFileSharingEnabled权限要开启,否则可能没有权限访问,会有如下的错误提示
ERROR: InstallationLookupFailed
The App 'com.wsgh.test' is either not present on the device, or the 'UIFileSharingEnabled' key is not set in its Info.plist. Starting with iOS 8.3 this key is mandatory to allow access to an app's Documents folder.

挂载某应用的整个沙盒目录

ifuse --container [要挂载的应用的bundleID] [挂载点]