-
Notifications
You must be signed in to change notification settings - Fork 19
/
app.py
703 lines (588 loc) · 26.7 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
import argparse
import json
import os
import io
import sys
import time
import datetime
from afc_service import AfcService
from device_service import DeviceService
from house_arrest_proxy_service import House_arrest_proxy_service
from installation_proxy_service import InstallationProxyService
from diagnostics_relay_service import DiagnosticsRelayService
from libimobiledevice import IDeviceConnectionType, SbservicesInterfaceOrientation
from instrument_service import instrument_main, setup_parser as setup_instrument_parser
from screenshotr_service import ScreenshotrService
from spring_board_service import SpringBoardService
from image_mounter_service import ImageMounterService
from syslog_relay_service import SyslogRelayService
from lockdown_service import LockdownService
from amfi_service import AMFIService
try:
from PIL import Image
except:
Image = None
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
device_service = DeviceService()
def _get_device_or_die(udid = None):
device = None
if udid is not None:
device = device_service.new_device(udid)
else:
device_list = device_service.get_device_list()
if len(device_list) > 0:
device = device_service.new_device(device_list[0]['udid'])
if device is None:
print("No device attached")
exit(-1)
else:
return device
def print_devices():
print("List of devices attached")
device_list = device_service.get_device_list()
for device in device_list:
conn_type = "USB" if device['conn_type'] == IDeviceConnectionType.CONNECTION_USBMUXD else "WIFI"
print("%s device %s" % (device['udid'], conn_type))
def get_device_info_from_configs(product_type):
with open(os.path.join(ROOT_DIR, "ios_deviceinfo_new.json")) as fp:
device_info_map = json.load(fp)
if product_type in device_info_map:
return device_info_map[product_type]
return None
def get_device_info(udid):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
lockdown_client = lockdown_service.new_client(device)
values, error = lockdown_service.get_value(lockdown_client, key=None)
if error:
return None, error
device_name = values['DeviceName']
product_version = values['ProductVersion']
build_version = values['BuildVersion']
product_type = values['ProductType']
unique_device_id = values['UniqueDeviceID']
os = "%s(%s)" % (product_version, build_version)
device_info = get_device_info_from_configs(product_type)
device_type = device_info['deviceType']
cpu_type = device_info['cpuInfo']['hwType']
cpu_arch = device_info['cpuInfo']['processor']
cpu_core_num = device_info['cpuInfo']['coreNum']
min_cpu_freq = int(int(device_info['cpuInfo']['minCpuFreq']) / 1000)
max_cpu_freq = int(int(device_info['cpuInfo']['maxCpuFreq']) / 1000)
cpu_freq = "[%s, %s]" % (str(min_cpu_freq), str(max_cpu_freq))
gpu_type = device_info['gpuInfo']
battery_info = device_info['batteryInfo'] # TODO:
lockdown_service.free_client(lockdown_client)
device_service.free_device(device)
return {
"os_type": "iOS",
"device_name": device_name,
"device_type": device_type,
"product_type": product_type,
"os": os,
"cpu_type": cpu_type,
"cpu_arch": cpu_arch,
"cpu_core_num": cpu_core_num,
"cpu_freq": cpu_freq,
"gpu_type": gpu_type,
}, None
def print_device_info(udid):
device_info, error = get_device_info(udid)
if error:
print("Error: %s" % error)
return
print("Device info of device(udid: %s)" % udid)
for key, value in device_info.items():
print("%s: %s" % (key, value))
def print_get_value(udid, key=None):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
lockdown_client = lockdown_service.new_client(device)
values, error = lockdown_service.get_value(lockdown_client, key=key)
if error:
print("Error: %s" % error)
return
print("Values of device(udid: %s)" % udid)
if type(values) == dict:
for name, value in values.items():
print("%s: %s" % (name, value))
else:
print("%s: %s" % (key, values))
lockdown_service.free_client(lockdown_client)
device_service.free_device(device)
def print_diagnostics(udid, name): # name = ["AppleSmartBattery" >= 13.0 , "AppleARMPMUCharger" < 13.0]
device = _get_device_or_die(udid)
diagnostics_relay_service = DiagnosticsRelayService()
diagnostics_relay_client = diagnostics_relay_service.new_client(device)
if diagnostics_relay_client:
data = diagnostics_relay_service.query_ioregistry_entry(diagnostics_relay_client, name, "")
print(data)
if data and len(data) >= 2:
if data[0]:
if "IORegistry" in data[1]:
io_registry = data[1]["IORegistry"]
update_time = io_registry['UpdateTime'] if "UpdateTime" in io_registry else None
voltage = io_registry['Voltage'] if "Voltage" in io_registry else None
instant_amperage = io_registry['InstantAmperage'] if "InstantAmperage" in io_registry else None
temperature = io_registry['Temperature'] if "Temperature" in io_registry else None
current = instant_amperage * -1
power = current * voltage / 1000
print("[Battery] time=%d, current=%d, voltage=%d, power=%d, temperature=%d" % (update_time, current, voltage, power, temperature))
diagnostics_relay_service.goodbye(diagnostics_relay_client)
diagnostics_relay_service.free_client(diagnostics_relay_client)
def get_app_list(device):
installation_proxy_service = InstallationProxyService()
installation_proxy_client = installation_proxy_service.new_client(device)
user_apps = None
system_apps = None
if installation_proxy_client:
user_apps = installation_proxy_service.browse(installation_proxy_client, "User")
system_apps = installation_proxy_service.browse(installation_proxy_client, "System")
installation_proxy_service.free_client(installation_proxy_client)
return user_apps, system_apps
def print_applications(udid):
device = _get_device_or_die(udid)
user_apps, system_apps = get_app_list(device)
print("List of user applications installed:")
if user_apps:
for app in user_apps:
for key, value in app.items():
print("%s: %s" % (key, value))
print("")
print("")
if system_apps:
print("List of system applications installed:")
for app in system_apps:
for key, value in app.items():
print("%s: %s" % (key, value))
print("")
device_service.free_device(device)
def print_icon(udid, bundle_id, output):
device = _get_device_or_die(udid)
spring_board_service = SpringBoardService()
spring_board_client = spring_board_service.new_client(device)
pngdata = spring_board_service.get_icon_pngdata(spring_board_client, bundle_id)
if pngdata:
with open(output, "wb") as fp:
fp.write(pngdata)
print("Save icon file at %s" % os.path.abspath(output))
else:
print("Can not get icon of app(bundleId=%s)" % bundle_id)
spring_board_service.free_client(spring_board_client)
device_service.free_device(device)
def enable_Wireless(udid,enable = 1):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
client = lockdown_service.new_client(device)
lockdown_service.enable_wireless(client,int(enable),"","")
lockdown_service.free_client(client)
def orientation_to_str(orientation):
if orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT_UPSIDE_DOWN:
return "PORTRAIT_UPSIDE_DOWN"
elif orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_LEFT:
return "LANDSCAPE_LEFT"
elif orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_RIGHT:
return "LANDSCAPE_RIGHT"
elif orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT:
return "PORTRAIT"
else:
return "UNKNOWN"
def rotate_image(data, orientation):
if Image is None:
print("[WARNING] PIL is not installed, can not auto rotate image, orientation=%s!" % orientation_to_str(orientation))
return data
bytes_io = io.BytesIO(data)
image = Image.open(bytes_io)
#print("image size=%s orientation=%s" % (str(image.size), str(orientation)))
if orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT_UPSIDE_DOWN:
image = image.transpose(Image.ROTATE_180)
elif orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_LEFT:
image = image.transpose(Image.ROTATE_270)
elif orientation == SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_RIGHT:
image = image.transpose(Image.ROTATE_90)
else:
image = image # portrait, do nothing
bytes_io = io.BytesIO()
image.save(bytes_io, format="PNG")
return bytes_io.getvalue()
def print_screenshot(udid, output = None):
device = _get_device_or_die(udid)
# get orientation of device
spring_board_service = SpringBoardService()
spring_board_client = spring_board_service.new_client(device)
orientation = spring_board_service.get_interface_orientation(spring_board_client)
spring_board_service.free_client(spring_board_client)
# take screenshot
screenshotr_service = ScreenshotrService()
screenshotr_client = screenshotr_service.new_client(device)
imgdata, file_ext = screenshotr_service.take_screenshot(screenshotr_client)
if imgdata:
if output is None:
output = os.path.join(ROOT_DIR, "screenshot_%s%s" % (datetime.datetime.now().strftime("%Y%m%d_%H%M%S"), file_ext))
imgdata = rotate_image(imgdata, orientation)
with open(output, "wb") as fp:
fp.write(imgdata)
print("Save screenshot image file at %s(orientation: %s)" % (os.path.abspath(output), orientation_to_str(orientation)))
else:
print("Error: Can not take screenshot")
screenshotr_service.free_client(screenshotr_client)
device_service.free_device(device)
def print_image_lookup(udid, image_type = None):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
lockdown_client = lockdown_service.new_client(device)
product_version, error = lockdown_service.get_value(lockdown_client, key="ProductVersion")
if error:
print("Error: %s" % error)
return
lockdown_service.free_client(lockdown_client)
if image_type is None:
image_type = "Developer"
image_mounter_service = ImageMounterService()
image_mounter_client = image_mounter_service.new_client(device)
image_mounted, error = image_mounter_service.lookup_image(image_mounter_client, image_type, product_version)
if error:
print("Error: %s" % error)
else:
print("Image mount status: " + ("Yes" if image_mounted else "No"))
image_mounter_service.hangup(image_mounter_client)
image_mounter_service.free_client(image_mounter_client)
def print_mount_image(udid, image_type, image_file, image_signature_file):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
lockdown_client = lockdown_service.new_client(device)
product_version, error = lockdown_service.get_value(lockdown_client, key="ProductVersion")
if error:
print("Error: %s" % error)
return
lockdown_service.free_client(lockdown_client)
if image_type is None:
image_type = "Developer"
image_mounter_service = ImageMounterService()
image_mounter_client = image_mounter_service.new_client(device)
result = image_mounter_service.upload_image(image_mounter_client, image_type, image_file, image_signature_file)
if not result:
print("Error: Can not upload image")
else:
image_path = "/private/var/mobile/Media/PublicStaging/staging.dimage"
result, error = image_mounter_service.mount_image(image_mounter_client, image_type, image_path, image_signature_file)
if error:
print("Error: %s" % error)
else:
print("Mount result: %s" % str(result))
image_mounter_service.hangup(image_mounter_client)
image_mounter_service.free_client(image_mounter_client)
device_service.free_device(device)
line = ""
def print_syslog(udid = None):
device = _get_device_or_die(udid)
syslog_relay_service = SyslogRelayService()
syslog_relay_client = syslog_relay_service.new_client(device)
def callback(char_data, user_data):
global line
if char_data == b"\n":
print(line)
line = ""
else:
line += char_data.decode("utf-8")
result = syslog_relay_service.start_capture(syslog_relay_client, callback)
if result:
print("System log:(pressing Ctrl+C to exit)")
try:
while True:
pass
except KeyboardInterrupt:
pass
syslog_relay_service.free_client(syslog_relay_client)
device_service.free_device(device)
def get_house_arrest_Client(device, device_directory, bundle_id, docType):
print(bundle_id)
if docType == None:
docType = 1
house_arrest_service = House_arrest_proxy_service()
client = house_arrest_service.new_client(device)
afc_client = house_arrest_service.open_sandbox_with_appid(client, docType, bundle_id)
if docType == 1:
root = "/Documents/"
if device_directory == "/":
device_directory = ""
elif device_directory.startswith("/"):
root = "/Documents"
device_directory = root + device_directory
return client, afc_client, device_directory
# docType = 1: sharing documents ,else: sandBox
def print_list(udid, device_directory = ".", bundle_id = None, docType = 1):
device = _get_device_or_die(udid)
afc_service = AfcService()
client = None
if bundle_id == None:
afc_client = afc_service.new_client(device)
else:
client, afc_client, device_directory = get_house_arrest_Client(device, device_directory, bundle_id, docType)
file_list = afc_service.read_directory(afc_client, device_directory)
print("List of directory %s:" % device_directory)
if file_list:
for file in file_list:
print(file['filename'], end=" ")
afc_service.free_client(afc_client)
device_service.free_device(device)
if client != None:
House_arrest_proxy_service.free_client(client)
def pull_file(udid, remote_file , bundle_id = None, docType = 1): # TODO: pull directory
device = _get_device_or_die(udid)
afc_service = AfcService()
client = None
if bundle_id == None:
afc_client = afc_service.new_client(device)
else:
client, afc_client, remote_file = get_house_arrest_Client(device, remote_file, bundle_id, docType)
afc_file = afc_service.open_file(afc_client, remote_file, "r")
output_file = os.path.join(ROOT_DIR, os.path.basename(remote_file))
output = open(output_file, "wb")
while True:
buffer = afc_file.read(1024)
output.write(buffer)
if not buffer:
break
output.close()
afc_file.close()
afc_service.free_client(afc_client)
device_service.free_device(device)
print("pull file %s" % output_file)
if client != None:
House_arrest_proxy_service.free_client(client)
def push_file(udid, local_file, device_directory, bundle_id = None, docType = 1):
if not os.path.exists(local_file):
print("Error: %s is not exists" % local_file)
return
device = _get_device_or_die(udid)
afc_service = AfcService()
client = None
if bundle_id == None:
afc_client = afc_service.new_client(device)
else:
client, afc_client, device_directory = get_house_arrest_Client(device, device_directory, bundle_id, docType)
success = afc_service.make_directory(afc_client, device_directory) # TODO: check
remote_file = device_directory + "/" + os.path.basename(local_file)
afc_file = afc_service.open_file(afc_client, remote_file, "w")
input_file = open(local_file, "rb")
while True:
buffer = input_file.read(1024)
if not buffer:
break
afc_file.write(buffer)
input_file.close()
afc_file.close()
afc_service.free_client(afc_client)
device_service.free_device(device)
if client != None:
House_arrest_proxy_service.free_client(client)
print("push file %s to %s" % (local_file, remote_file))
def make_directory(udid, device_directory, bundle_id = None, docType = 1):
device = _get_device_or_die(udid)
client = None
afc_service = AfcService()
if bundle_id == None:
afc_client = afc_service.new_client(device)
else:
client, afc_client, device_directory = get_house_arrest_Client(device, device_directory, bundle_id, docType)
result = afc_service.make_directory(afc_client, device_directory)
print("Make directory %s %s" % (device_directory, "Success" if result else "Fail"))
afc_service.free_client(afc_client)
device_service.free_device(device)
if client != None:
House_arrest_proxy_service.free_client(client)
def remove_path(udid, device_path, bundle_id = None, docType = 1):
device = _get_device_or_die(udid)
client = None
afc_service = AfcService()
if bundle_id == None:
afc_client = afc_service.new_client(device)
else:
client, afc_client, device_path = get_house_arrest_Client(device, device_path, bundle_id, docType)
result = False
error = None
try:
result = afc_service.remove_path(afc_client, device_path)
except IOError as e:
error = e
if result:
print("%s Deleted." % device_path)
else:
print("Error: %s" % error)
afc_service.free_client(afc_client)
device_service.free_device(device)
if client != None:
House_arrest_proxy_service.free_client(client)
def install_ipa(udid, ipa_path):
device = _get_device_or_die(udid)
installation_proxy_service = InstallationProxyService()
client = installation_proxy_service.new_client(device)
print("start install")
apps = installation_proxy_service.install(device, client, ipa_path)
print("finsih install")
installation_proxy_service.free_client(client)
def uninstall_ipa(udid, bundle_id):
device = _get_device_or_die(udid)
installation_proxy_service = InstallationProxyService()
client = installation_proxy_service.new_client(device)
print("start install")
apps = installation_proxy_service.uninstall(device, client, bundle_id)
print("finsih install")
installation_proxy_service.free_client(client)
def start_heartbeat(udid):
control = DeviceService.start_heartbeat(udid)
try:
while control['running']:
time.sleep(1)
except:
pass
finally:
control['running'] = False
control['thread'].join()
def print_developer_mode_status(udid):
device = _get_device_or_die(udid)
lockdown_service = LockdownService()
client = lockdown_service.new_client(device)
result = lockdown_service.get_developer_mode_status(client)
print("develpoer mode status: {0}".format(result))
lockdown_service.free_client(client)
def print_set_developer_mode(udid, mode):
device = _get_device_or_die(udid)
amfi_client_service = AMFIService()
amfi_client = amfi_client_service.new_client(device)
ret = amfi_client_service.set_developer_mode(amfi_client, int(mode))
if ret == 0:
print("set developer mode success")
else:
print("error, error code: {0}".format(ret))
amfi_client_service.free_client(amfi_client)
device_service.free_device(device)
def main():
argparser = argparse.ArgumentParser()
# argparser.add_argument("command", help="command", choices=["devices", "deviceinfo", "devicename", "instrument"])
cmd_parser = argparser.add_subparsers(dest="command")
cmd_parser.add_parser("devices")
cmd_parser.add_parser("applications")
cmd_parser.add_parser("deviceinfo")
cmd_parser.add_parser("syslog")
# list
list_parser = cmd_parser.add_parser("ls")
list_parser.add_argument("device_directory")
list_parser.add_argument("--bundle_id", required=False )
list_parser.add_argument("-d", "--docType", required=False, type=int, help='default 1,1 for sharing documents other for sandBox')
# mkdir
list_parser = cmd_parser.add_parser("mkdir")
list_parser.add_argument("device_directory")
list_parser.add_argument("--bundle_id", required=False )
list_parser.add_argument("-d", "--docType", required=False, type=int, help='default 1,1 for sharing documents other for sandBox')
# rm
list_parser = cmd_parser.add_parser("rm")
list_parser.add_argument("device_path")
list_parser.add_argument("--bundle_id", required=False )
list_parser.add_argument("-d", "--docType", required=False, type=int, help='default 1,1 for sharing documents other for sandBox')
# pull file
pull_parser = cmd_parser.add_parser("pull")
pull_parser.add_argument("remote_file")
pull_parser.add_argument("--bundle_id", required=False )
pull_parser.add_argument("-d", "--docType", required=False, type=int, help='default 1,1 for sharing documents other for sandBox')
# push file
push_parser = cmd_parser.add_parser("push")
push_parser.add_argument("local_file")
push_parser.add_argument("device_directory")
push_parser.add_argument("--bundle_id", required=False )
push_parser.add_argument("-d", "--docType", required=False, type=int, help='default 1,1 for sharing documents other for sandBox')
# imagemounter
lookupimage_parser = cmd_parser.add_parser("lookupimage")
lookupimage_parser.add_argument("-t", "--image_type", required=False)
# imagemounter
mountimage_parser = cmd_parser.add_parser("mountimage")
mountimage_parser.add_argument("-t", "--image_type", required=False)
mountimage_parser.add_argument("-i", "--image_file", required=False)
mountimage_parser.add_argument("-s", "--sig_file", required=False)
# screenshot
screenshot_parser = cmd_parser.add_parser("screenshot")
screenshot_parser.add_argument("-o", "--output", required=False)
# geticon
geticon_parser = cmd_parser.add_parser("geticon")
geticon_parser.add_argument("--bundle_id", required=True)
geticon_parser.add_argument("-o", "--output", required=True)
# getvalue
getvalue_parser = cmd_parser.add_parser("getvalue")
getvalue_parser.add_argument("-k", "--key")
# instrument
instrument_parser = cmd_parser.add_parser("instrument")
setup_instrument_parser(instrument_parser)
# diagnostics
diagnostics_parser = cmd_parser.add_parser("diagnostics")
diagnostics_subcmd_parsers = diagnostics_parser.add_subparsers(dest="diagnostics_cmd")
diagnostics_ioregentry_parser = diagnostics_subcmd_parsers.add_parser("ioregentry")
diagnostics_ioregentry_parser.add_argument("key")
# get_developer_mode_status
cmd_parser.add_parser("developermodestatus")
# AMFI set_developer_mode
amfi_developer_mode_parser = cmd_parser.add_parser("setdevelopermode")
amfi_developer_mode_parser.add_argument("-m", "--mode", required=True)
# enableWireless
cmd_wireless = cmd_parser.add_parser("enableWireless")
cmd_wireless.add_argument("-e", "--enable", required=False)
cmd_parser.add_parser("heartbeat")
argparser.add_argument("-u", "--udid", help="udid")
## install
install_parser = cmd_parser.add_parser("install")
install_parser.add_argument("ipa_path")
## uninstall
uninstall_parser = cmd_parser.add_parser("uninstall")
uninstall_parser.add_argument("bundle_id")
args = argparser.parse_args()
if args.command == "devices":
print_devices()
elif args.command == "applications":
print_applications(args.udid)
elif args.command == "deviceinfo":
print_device_info(args.udid)
elif args.command == "lookupimage":
print_image_lookup(args.udid, args.image_type)
elif args.command == "mountimage":
print_mount_image(args.udid, args.image_type, args.image_file, args.sig_file)
elif args.command == "geticon":
print_icon(args.udid, args.bundle_id, args.output)
elif args.command == "syslog":
print_syslog(args.udid)
elif args.command == "screenshot":
print_screenshot(args.udid, args.output)
elif args.command == "getvalue":
print_get_value(args.udid, args.key)
elif args.command == 'instrument':
instrument_main(_get_device_or_die(args.udid), args)
elif args.command == 'ls':
print_list(args.udid, args.device_directory, args.bundle_id, args.docType)
elif args.command == 'mkdir':
make_directory(args.udid, args.device_directory, args.bundle_id, args.docType)
elif args.command == 'rm':
remove_path(args.udid, args.device_path, args.bundle_id, args.docType)
elif args.command == 'pull':
pull_file(args.udid, args.remote_file, args.bundle_id, args.docType)
elif args.command == 'push':
push_file(args.udid, args.local_file, args.device_directory, args.bundle_id, args.docType)
elif args.command == 'enableWireless':
enable_Wireless(args.udid, args.enable)
elif args.command == 'install':
install_ipa(args.udid, args.ipa_path)
elif args.command == 'uninstall':
uninstall_ipa(args.udid, args.bundle_id)
elif args.command == 'heartbeat':
start_heartbeat(args.udid)
elif args.command == 'diagnostics':
if args.diagnostics_cmd == "ioregentry":
print_diagnostics(args.udid, args.key)
else:
print("unknown diagnostics cmd:", args.diagnostics_cmd, "support cmds:", ["ioregentry"])
elif args.command == 'developermodestatus':
print_developer_mode_status(args.udid)
elif args.command == 'setdevelopermode':
print_set_developer_mode(args.udid, args.mode)
else:
argparser.print_usage()
if __name__ == "__main__":
main()