Skip to content

Commit

Permalink
little update for tidevice
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 25, 2023
1 parent 9a39808 commit db097e2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 2 additions & 10 deletions tidevice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
10 changes: 6 additions & 4 deletions tidevice/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -702,21 +702,23 @@ 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
"""
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:
"""
Expand Down
7 changes: 4 additions & 3 deletions tidevice/_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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序列化后的数据,没有长度字段
Expand Down
5 changes: 5 additions & 0 deletions tidevice/struct2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import struct
from collections import namedtuple
from functools import partial
import typing


class Field(object):
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit db097e2

Please sign in to comment.