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

https://osxfuse.github.io

然后使用上面指令安裝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$ 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM