使用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
sudo brew update sudo brew install libimobiledevice #libimobiledevice中並不包含ipa的安裝命令,所以還需要安裝 sudo 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偏好設定中看到存放目錄
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 install ifuse
或者通過官網安裝
1. 安裝好後使用ifuse -h會列印詳細使用說明
Usage: ifuse MOUNTPOINT [OPTIONS] Mount directories of an iOS device locally using fuse. -o opt,[opt...]mount options -u, --udid UDIDmount specific device by its 40-digit device UDID -h, --helpprint usage information -V, --versionprint version -d, --debugenable libimobiledevice communication debugging --documents APPIDmount 'Documents' folder of app identified by APPID --container APPIDmount sandbox root of an app identified by APPID --rootmount 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 DocumentsLibrarySystemDatatmp Jackeys-MacBook-Pro:xiaoailite jackey$