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

简介

 

libimobiledevice:一个开源包,可让Linux支持链接iPhone/iPod Touch等iOS设备。ios

Git仓库: https://github.com/libimobiledevice/libimobiledevice.gitgit

 

ifuse: 也是一个开源包,能够用来访问iDevice的工具github

Git仓库: https://github.com/libimobiledevice/ifuse.gitshell

 

咱们能够利用libimobiledevice与ifuse进行shell封装,辅助实现自动化的测试过程。微信

这里咱们用来提取iOS设备上APP沙盒中的日志文件app

 

 

快速直接安装libmobiledevice的方法

MacOS上安装libimobiledeviceiphone

sudo brew update
sudo brew install libimobiledevice
#libimobiledevice中并不包含ipa的安装命令,因此还须要安装
sudo brew install ideviceinstaller

Ubuntu下安装libimobiledeviceide

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 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

或者经过官网安装

https://osxfuse.github.io

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$ 
相关文章
相关标签/搜索