diff --git a/tidevice/__main__.py b/tidevice/__main__.py index e304e9c..79a1a82 100644 --- a/tidevice/__main__.py +++ b/tidevice/__main__.py @@ -373,22 +373,14 @@ def cmd_launch(args: argparse.Namespace): logger.warning("skip_running is deprecated, always kill app now") d = _udid2device(args.udid) - env = {} for kv in args.env or []: key, val = kv.split(":", 1) env[key] = val if env: logger.info("App launch env: %s", env) - - try: - with d.connect_instruments() as ts: - pid = ts.app_launch(args.bundle_id, - app_env=env, - args=args.arguments) - print("PID:", pid) - except ServiceError as e: - sys.exit(e) + pid = d.app_start(args.bundle_id, args=args.arguments, env=env) + print("PID:", pid) def cmd_kill(args: argparse.Namespace): diff --git a/tidevice/_ssl.py b/tidevice/_ca.py similarity index 100% rename from tidevice/_ssl.py rename to tidevice/_ca.py diff --git a/tidevice/_device.py b/tidevice/_device.py index d84f581..27849a7 100644 --- a/tidevice/_device.py +++ b/tidevice/_device.py @@ -194,7 +194,7 @@ def pair(self): wifi_address = self.get_value("WiFiAddress", no_session=True) try: - from ._ssl import make_certs_and_key + from ._ca import make_certs_and_key except ImportError: #print("DevicePair require pyOpenSSL and pyans1, install by the following command") #print("\tpip3 install pyOpenSSL pyasn1", flush=True) @@ -702,13 +702,15 @@ def app_kill(self, *args, **kwargs) -> int: def app_start(self, bundle_id: str, - args: Optional[list] = []) -> int: + args: Optional[list] = [], + env: typing.Mapping = {}) -> int: """ start application Args: bundle_id: com.apple.Preferences - args: ['-AppleLanguages', '(en)'] + args: eg ['-AppleLanguages', '(en)'] + env: eg {'MYPATH': '/tmp'} Returns: pid @@ -716,7 +718,7 @@ def app_start(self, if args is None: args = [] with self.connect_instruments() as ts: - return ts.app_launch(bundle_id, args=args) + return ts.app_launch(bundle_id, args=args, app_env=env) def app_install(self, file_or_url: Union[str, typing.IO]) -> str: """ diff --git a/tidevice/_instruments.py b/tidevice/_instruments.py index 324579e..d64110b 100644 --- a/tidevice/_instruments.py +++ b/tidevice/_instruments.py @@ -520,16 +520,17 @@ def recv_dtx_message(self) -> Tuple[Any, bytearray]: >> Body 部分 00000030: F0 1B 00 00 00 00 00 00 61 1B 00 00 00 00 00 00 ........a....... \\\\ - # 前面8个字节 0X1BF0 据说是Magic word + # 前面8个字节 0X1BF0 据说是Magic word TODO # 后面的 0x1B61 是整个序列化数据的长度 # 解析的时候可以直接跳过这部分 + + 00000040: 0A 00 00 00 02 00 00 00 55 1B 00 00 62 70 6C 69 ........U...bpli # 序列化的数据部分, 使用OC的NSKeyedArchiver序列化 # 0A,00,00,00: 起始头 # 02,00,00,00: 2(obj) 3(u32) 4(u64) 5(u32) 6(u64) # 55,1B,00,00: 序列化的数据长度 - 00000040: 0A 00 00 00 02 00 00 00 55 1B 00 00 62 70 6C 69 ........U...bpli - ..... + # 62,70,6C,69: bplist00这些就是plistlib的dumps后的数据了 # 最后面还跟了一个NSKeyedArchiver序列化后的数据,没有长度字段 diff --git a/tidevice/struct2.py b/tidevice/struct2.py index f9d078d..d51af20 100644 --- a/tidevice/struct2.py +++ b/tidevice/struct2.py @@ -6,6 +6,7 @@ import struct from collections import namedtuple from functools import partial +import typing class Field(object): @@ -64,6 +65,7 @@ def __init__(self, typename: str, *fields, byteorder="<"): if f.name in self._field_names: raise ValueError("Struct has duplicated name", f.name) self._field_names.append(f.name) + self._size = sum([f.size for f in self._fields]) @property def size(self): @@ -75,6 +77,9 @@ def _convert_field(self, fvalue): else: raise ValueError("Unknown type:", fvalue) + def parse_stream(self, reader: typing.BinaryIO): + return self.parse(reader.read(self.size)) + def parse(self, buffer: bytes): values = struct.unpack(self._fmt, buffer) return namedtuple(self._typename, self._field_names)(*values)