• 工具开源免费
  • 适配MacBook
  • 支持iOS 17+

背景

修改定位的需求,一是为了方便打卡,二是修改游戏定位。

在iOS设备上实现虚拟定位大致有这几种方式:

  • 使用越狱设备通过hook相关App的定位方法来实现虚拟定位;
  • 使用Xcode模拟定位;
  • 使用第三方工具(比如爱思助手、iMyFone AnyTo、Tenorshare iAnyGo等)中的虚拟定位功能来实现虚拟定位;
  • 使用外接设备(比如车载蓝牙等)实现虚拟定位;
  • 使用libmobiledevice/pymobiledevice3命令行工具来实现虚拟定位。

对普通用户来说,使用第三方工具虚拟定位,是最便捷也是最常用的。就拿爱思助手来说,只需要在Mac上安装爱思助手软件,用数据线连接iPhone,就可以使用虚拟定位功能,设置一下经纬度就会立即在手机上生效。

爱思助手虚拟定位是免费的,但是爱思助手会在iPhone上安装一个应用,我不是很喜欢。其他第三方虚拟定位软件会面临一个收费问题,所以也不是很好用。

Xcode模拟定位使用比较繁琐,需要创建一个App,添加GPX文件,在GPX文件中添加坐标,然后通过真机调试实现虚拟定位。

libmobiledevice/pymobiledevice3实现虚拟定位

起初我使用libmobiledevice工具中的idevicesetlocation命令实现虚拟定位,但是当iOS升级到17.0之后,这种方式就失效了。目前仍然没有解决,参考GitHub上相关Issue:ERROR: Could not start the simulatelocation service. Make sure a developer disk image is mounted!

在之后的一段时间内,我只能使用Xcode来进行虚拟定位,尽管比较繁琐,也只能忍受。直到我遇到了pymobiledevice3。

pymobiledevice3使用方法

pymobilevice3是一个纯python3实现,用于与iDevices(iPhone,etc)配合使用。以下示例在我的MacBook上进行操作。

我目前的MacBook系统为macOS Sequoia(15.0),iPhone版本为iOS 18,是最新的公测版。

安装

可以通过PyPi进行安装:

为了不破环系统环境,创建一个虚拟环境来操作。

python3 -m venv /path/to/.venv
source /path/to/.venv

pip install -U pymobiledevice3
OpenSSL libraries(虚拟定位非必须)

目前,如果在较旧的iOS版本(<13)上使用,则明确要求使用openssl。

brew install openssl
libusb dependency(虚拟定位非必须)

在恢复或DFU模式下与设备交互需要安装libusb(处理还原子命令所必需的)。

brew install libusb

使用开发人员工具(iOS>=17.0)

从iOS 17.0开始,苹果推出了新的CoreDevice框架来与iOS设备配合使用。此框架依赖于RemoteXPC协议。为了与开发人员服务通信,需要首先以以下两种形式之一创建可信隧道:

启动名为tunneld的隧道服务器以自动检测设备并建立连接
sudo pymobiledevice3 remote tunneld
使用start-tunnel手动创建隧道
sudo pymobiledevice3 lockdown start-tunnel

# 如果你想通过wifi建立连接,需要开启wifi-connections
pymobiledevice3 lockdown wifi-connections on

# 可以通过参数`-t wifi`强制建立WiFi隧道
sudo pymobiledevice3 remote start-tunnel

在成功创建隧道后,会打印出必要的连接信息。

Interface: utun6
RSD Address: fd7b:e5b:6f53::1
RSD Port: 64337
Use the follow connection option:
--rsd fd7b:e5b:6f53::1 64337

现在,(几乎)所有pymobilevice3都接受一个额外的--rsd/--tunnel选项,用于通过隧道连接到服务。具体来说,在出现InvalidServiceError错误时,总是隐式尝试使用--tunnel选项,以简化开发人员服务的工作。现在,您可以尝试执行其中任何一个,如下所示:

使用tunneld创建的隧道会自动建立连接,手动创建的隧道必须传递--rsd/--tunnel才能进行通讯,因此推荐使用tunneld自动连接。
# Accessing the DVT services
# The --tunnel option may accept either an empty string, or a UDID for a specific device 
# The UDID may be suffixed with :PORT in case tunneld in serving at a non-default port 
pymobiledevice3 developer dvt ls / --tunnel ''

# Or simply without the `--tunnel` option, assuming the tunneld is running
pymobiledevice3 developer dvt ls /

# Or we could use the manual tunnel details
pymobiledevice3 developer dvt ls / --rsd fd7b:e5b:6f53::1 64337

# And we can also access or the other "normal" lockdown services
pymobiledevice3 syslog live --tunnel ''

修改定位

# Simulate a `lat long` location (iOS < 17.0)
pymobiledevice3 developer simulate-location set -- lat long

# Simulate a `lat long` location (iOS >= 17.0)
pymobiledevice3 developer dvt simulate-location set -- lat long
顺便提供一个网站,通过地点名称查询对应经纬度:经纬度查询定位
最后修改:2024 年 09 月 16 日
如果觉得我的文章对你有用,请随意赞赏