Skip to content

fix:兼容iOS17.4系统start_tunnel #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tidevice3/cli/tunneld.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
logger = logging.getLogger(__name__)
os_utils = OsUtils.create()


class Address(NamedTuple):
ip: str
port: int
Expand All @@ -43,6 +44,16 @@ def get_connected_devices() -> list[str]:
return [d.Identifier for d in devices if Version(d.ProductVersion) >= Version("17")]


def get_need_lockdown_devices() -> list[str]:
"""return list of udid"""
try:
devices = list_devices(usb=True, network=False)
except MuxException as e:
logger.error("list_devices failed: %s", e)
return []
return [d.Identifier for d in devices if Version(d.ProductVersion) >= Version("17.4")]


def guess_pymobiledevice3_cmd() -> List[str]:
pmd3path = shutil.which("pymobiledevice3")
if not pmd3path:
Expand All @@ -64,7 +75,10 @@ def start_tunnel(pmd3_path: List[str], udid: str) -> Tuple[Address, subprocess.P
"""
# cmd = ["bash", "-c", "echo ::1 1234; sleep 10001"]
log_prefix = f"[{udid}]"
cmdargs = pmd3_path + f"remote start-tunnel --script-mode --udid {udid}".split()
start_tunnel_cmd = "remote"
if udid in get_need_lockdown_devices():
start_tunnel_cmd = "lockdown"
cmdargs = pmd3_path + f"{start_tunnel_cmd} start-tunnel --script-mode --udid {udid}".split()
logger.info("%s cmd: %s", log_prefix, shlex.join(cmdargs))
process = subprocess.Popen(
cmdargs, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE
Expand Down Expand Up @@ -120,9 +134,9 @@ def _start_tunnel_keeper(self, udid: str):
except TunnelError:
logger.exception("udid: %s start-tunnel failed", udid)
time.sleep(3)

def _wait_process_exit(self, process: subprocess.Popen, udid: str):
while True:
while True:
try:
process.wait(1.0)
self.addresses.pop(udid, None)
Expand Down