Skip to content

Commit

Permalink
Merge pull request #15 from mynamecool/master
Browse files Browse the repository at this point in the history
fix:兼容iOS17.4系统start_tunnel
  • Loading branch information
codeskyblue authored May 11, 2024
2 parents 2e22b66 + 8908321 commit c90ab46
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit c90ab46

Please sign in to comment.