使用libimobiledevice + ifuse提取iOS沙盒文件
简介
libimobiledevice:一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备。
Git仓库: https://github.com/libimobiledevice/libimobiledevice.git
ifuse: 也是一个开源包,可以用来访问iDevice的工具
Git仓库: https://github.com/libimobiledevice/ifuse.git
我们可以利用libimobiledevice与ifuse进行shell封装,辅助实现自动化的测试过程。
这里我们用来提取iOS设备上APP沙盒中的日志文件
快速直接安装libmobiledevice的方法
MacOS上安装libimobiledevice
brew update
brew install libimobiledevice
#libimobiledevice中并不包含ipa的安装命令,所以还需要安装
brew install ideviceinstaller
Ubuntu下安装libimobiledevice
sudo add-apt-repository ppa:pmcenery/ppa sudo apt-get update apt-get install libimobiledevice-utils sudo apt-get install ideviceinstaller
常用功能
1. 获取设备已安装app的bundleID
ideviceinstaller -l
演示:
Jackeys-MacBook-Pro:/ jackey$ ideviceinstaller -l Total: 13 apps com.zhouxi.xiaoailiteios - 小米同学 20 com.apple.test.WebDriverAgentRunner-Runner - WebDriverAgentRunner-Runner 1 com.apple.store.Jolly - Apple Store 5.0.0.0302 com.apple.clips - 可立拍 4141.1.91 com.apple.mobilegarageband - 库乐队 4878.17 com.apple.Keynote - Keynote 讲演 5625 com.apple.Numbers - Numbers 表格 5625 com.apple.Pages - Pages 文稿 5625 com.apple.iMovie - iMovie 3709.9.72 com.apple.itunesu - iTunes U 2360 com.sogou.sogouinput - 搜狗输入法 148198 com.tencent.xin - 微信 6.7.4.44 com.ss.iphone.ugc.AwemeInhouse - 抖音短视频内测 43006 Jackeys-MacBook-Pro:/ jackey$
2. 安装ipa包,卸载应用
//命令安装一个ipa文件到手机上,如果是企业签名的,非越狱机器也可以直接安装了。 ideviceinstaller -i xxx.ipa //命令卸载应用,需要知道此应用的bundleID ideviceinstaller -U [bundleID]
卸载演示:
Jackeys-MacBook-Pro:/ jackey$ ideviceinstaller -U com.zhouxi.xiaoailiteios Uninstalling 'com.zhouxi.xiaoailiteios' - RemovingApplication (50%) - GeneratingApplicationMap (90%) - Complete Jackeys-MacBook-Pro:/ jackey$
安装演示:
Jackeys-MacBook-Pro:Code jackey$ ideviceinstaller -i QQ音乐\ 8.9.7.ipa Copying 'QQ音乐 8.9.7.ipa' to device... DONE. Installing 'com.tencent.QQMusic' - CreatingStagingDirectory (5%) - ExtractingPackage (15%) - InspectingPackage (20%) - TakingInstallLock (20%) - PreflightingApplication (30%) - VerifyingApplication (40%) - CreatingContainer (50%) - InstallingApplication (60%) - PostflightingApplication (70%) - SandboxingApplication (80%) - GeneratingApplicationMap (90%) - Complete Jackeys-MacBook-Pro:Code jackey$
这里补充一个: ipa我们可以通过itunes来进行下载, 下载完后可以在iTunnes偏好设置中看到存放目录
如果连接了多部手机需要分别安装时,请使用UDID指定:ideviceinstaller -u udid -i *.ipa
3. 查看系统日志
idevicesyslog
4. 查看当前已连接的设备的UUID
idevice_id --list
5. 截图
idevicescreenshot
6. 查看设备信息
ideviceinfo
7. 获取设备时间
idevicedate
8. 设置代理
iproxy
usage: iproxy LOCAL_TCP_PORT DEVICE_TCP_PORT [UDID]
9. 获取设备名称
idevicename
10. 查看和操作设备的描述文件
ideviceprovision list
11. 挂载DeveloperDiskImage,用于调试(这个在我的机器上面不能用, 应该是缺少什么东西了)
ideviceimagemounter
12. 调试程序
idevicedebug
如果在运行上面指令出现以下错误:
"Could not connect to lockdownd. Exiting."
使用以下方式重新安装
brew uninstall ideviceinstaller brew uninstall libimobiledevice brew install --HEAD libimobiledevice brew link --overwrite libimobiledevice brew install --HEAD ideviceinstaller
brew link --overwrite ideviceinstaller
重新安装过程中如果出现以下错误:
A recent change to libimobiledevice bumped the constraint on libusbmuxd to >= version 1.1.0. The current usbmuxd homebrew package is version 1.0.10. As a result, homebrew --HEAD installs of libimobiledevice no longer build without a --HEAD install of usbmuxd.
使用以下指令升级usbmuxd:
brew update brew uninstall --ignore-dependencies usbmuxd brew install --HEAD usbmuxd brew link --overwrite usbmuxd
升级后接着安装libimobiledevice
挂载文件系统工具:ifuse
安装方式:
brew cask install osxfuse
brew install ifuse
或者通过官网安装 osxfuse
然后使用上面指令安装ifuse
1. 安装好后使用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. Jackeys-MacBook-Pro:Code jackey$
2. 挂在媒体文件目录:
//注意,此处的挂载点必须要真实存在,需要预先创建好目录,否则挂载失败 ifuse [挂载点]
演示:
sudo mkdir /myapp
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse myapp/
Password:
Jackeys-MacBook-Pro:/ jackey$
卸载挂载点
fusermount -u [挂载点]
这个指令在我的电脑上不行, 我改用的sudo umount /myapp
3. 挂载某个应用的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.
演示:
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse --documents com.zhouxi.xiaoailiteios /myapp
Password:
ERROR: InstallationLookupFailed
Jackeys-MacBook-Pro:/ jackey$
报这个错是因为我们app没有开启文件共享,需要在app的info.plist添加一下字段
我们再试试
Jackeys-MacBook-Pro:/ jackey$ sudo ifuse --documents com.zhouxi.xiaoailiteios /myapp Password: mount_osxfuse: mount point /myapp is itself on a OSXFUSE volume
这里报错的原因是我们不能把文件挂在到根目录, 我们先删除之前的挂载
重新挂在到Document目录下我们自己的文件夹中
ifuse --documents com.zhouxi.xiaoailiteios /Users/jackey/Documents/Xiaomi/myapp
OK, 这次没有出错, 打开Finder进入所在目录发现myapp文件夹没有了, 但增加了一个OSXFUSE Volume的目录
打开里面就是我们的Documents目录
使用umount可卸载
umount /Users/jackey/Documents/Xiaomi/myapp
4. 挂在某应用的整个沙盒目录
ifuse --container [要挂载的应用的bundleID] [挂载点]
演示:
ifuse --container com.zhouxi.xiaoailiteios /Users/jackey/Documents/Xiaomi/myapp/xiaoailite
打开finder可以看到整个沙盒目录都挂在上来了
如果需要自动提取沙盒日志,这里我们可以写脚本使用挂在的目录去获取里面的内容
Jackeys-MacBook-Pro:xiaoailite jackey$ pwd /Users/jackey/Documents/Xiaomi/myapp/xiaoailite Jackeys-MacBook-Pro:xiaoailite jackey$ ls Documents Library SystemData tmp Jackeys-MacBook-Pro:xiaoailite jackey$