静,是一种休息,更是一种修行。所有的烦恼,都来自于喧嚣,所有的伤痛,都来自于躁动。身体奔波太久会劳累,灵魂游离太久会成伤。红尘淹没了纯洁,欲望吞噬了安详,经年后,心若一动,泪已千行。 停一停追逐的脚步,缓一缓紧绷的心弦,让心宁静,让伤口复原,让灵魂升华。

iFuse-非越狱手机访问沙盒

王海峰 | 发表于:2016-01-13 18:29:27 | 日志分类:信息技术 | 阅读量:(991)
记得2014年下半年,有一段时间我在做埋点统计的测试开发工作,当时应用的埋点会记录本手机本地中,并实时的自动上传到服务器
因为,针对手机中的埋点,我才去把应用的沙盒映射到电脑中,然后对埋点统计的日志进行处理和解析,然后进行对比分析。
在这里呢,我会借用到一个工具,那就是iFuse,通过它,可以在电脑上访问应用沙盒。

一、 iFuse的安装与配置
1.安装libimobiledevice,ifuse,ifuse依赖与libimobiledevice
可以选择brew安装
brew install libimobiledevice

brew install ifuse

如果上面的方法安装不成功,可以通过下面的方法:

wanghaifengdeiMac:~ wanghaifeng$ brew install Caskroom/cask/osxfuse

==> Tapping caskroom/cask
Cloning into '/usr/local/Library/Taps/caskroom/homebrew-cask'...
remote: Counting objects: 3410, done.
remote: Compressing objects: 100% (3370/3370), done.
remote: Total 3410 (delta 63), reused 238 (delta 19), pack-reused 0
Receiving objects: 100% (3410/3410), 5.88 MiB | 186.00 KiB/s, done.
Resolving deltas: 100% (63/63), done.
Checking connectivity... done.
Tapped 1 formula (3381 files, 25M)
==> brew cask install Caskroom/cask/osxfuse
==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
==> Caveats
You must reboot for the installation of osxfuse to take effect.
==> Downloading http://downloads.sourceforge.net/project/osxfuse/osxfuse-2.8.2/o
######################################################################## 100.0%
==> Verifying checksum for Cask osxfuse
==> Running installer for osxfuse; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are i
==> installer: Package name is FUSE for OS X (OSXFUSE)
==> installer: Installing at base path



可以看到在/opt/homebrew-cask/Caskroom/osxfuse/2.8.2目录下有一个pkg文件,双击进行安装操作
安装后,可以在设置面板中看到安装的 /Library/PreferencePanes/OSXFUSE.prefPane
同时在 /Library/Filesystems/osxfusefs.fs也有一份安装文件


wanghaifengdeiMac:MacOS wanghaifeng$ brew search fuse
homebrew/fuse/archivemount           homebrew/fuse/gcsfuse                homebrew/fuse/sshfs
homebrew/fuse/avfs                   homebrew/fuse/gitfs                  homebrew/fuse/stormfs
homebrew/fuse/bindfs                 homebrew/fuse/ifuse                  homebrew/fuse/tup
wanghaifengdeiMac:MacOS wanghaifeng$ brew install homebrew/fuse/ifuse
==> Installing ifuse from homebrew/fuse
==> Installing dependencies for homebrew/fuse/ifuse: gettext, libffi, glib
==> Installing homebrew/fuse/ifuse dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.6.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gettext-0.19.6.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
OS X provides the BSD gettext library and some software gets confused if both are in the library path.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS:  -L/usr/local/opt/gettext/lib
CPPFLAGS: -I/usr/local/opt/gettext/include

==> Installing homebrew/fuse/ifuse dependency: libffi
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.0.13.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libffi-3.0.13.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
Some formulae require a newer version of libffi.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS:  -L/usr/local/opt/libffi/lib

==> ./autogen.sh
==> ./configure --prefix=/usr/local/Cellar/ifuse/1.1.3
==> make install
wanghaifengdeiMac:MacOS wanghaifeng$ 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.
2.拷贝osxfusefs.fs 到/Library/Filesystems,并添加执行权限
sudo /bin/cp  -RfX  /usr/local/Cellar/osxfuse/2.6.2/Library/Filesystems/osxfusefs.fs   /Library/Filesystems
sudo chmod +s /Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs

3.终端输入ifuse -h,会打印出详细使用说明
挂载某个应用的沙盒到~/myapp:
app_bundleId=com.my.app
udid=xxxxxxxxxxxx
ifuse -u ${udid} --container ${app_bundleId} ~/myapp

4.关闭挂载:
umount ~/myapp

PS:itoos与iexploer等工具都是基于libimobiledevice库进行开发的,iOS 6.x的越狱也用到了此库,更为重要的是appium也依赖于它,如果大家有安装过appium环境那么可以查看下build/libimobiledevice-macosx/,有许多可执行的unix文件
idevice_id
idevicebackup
idevicebackup2
idevicedate
idevicedebugserverproxy
idevicediagnostics
ideviceenterrecovery
ideviceimagemounter
ideviceinfo
idevicepair
ideviceprovision
idevicescreenshot
idevicesyslog
可以直接使用这些命令行工具,例如:
idevice_id -l 可直接查看手机id
idevicediagnostics 可让iPhone进行重启,关机,睡眠等。

我们可以利用libimobiledevice与ifuse进行shell封装,辅助实现自动化的测试过程。

二、ifuse使用介绍
下面是我用到的一些实例
wanghaifengdeiMac:~ wanghaifeng$ ifuse --udid  1cc7ad4ed7c9b7ac5164651d28a316b7d7d71dc9  --container net.wanghaifeng  ~/pp25
wanghaifengdeiMac:~ wanghaifeng$ umount ~/pp25