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 get_device_info(self, udid): device = self._device_service.new_device(udid) if not device: return None, "No device connected with udid(%s)" % 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 = self._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) self._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_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_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)
class LockdownServiceTestCase(unittest.TestCase): def setUp(self): self.device_service = DeviceService() self.lockdown_service = LockdownService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_new_client(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_get_value(self): device = self._create_device() client = self.lockdown_service.new_client(device, handshake=False) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values, error = self.lockdown_service.get_value(client, None) print("values", type(values), values) # self.assertTrue("DeviceName" in values) # self.assertTrue("UniqueDeviceID" in values) # self.assertTrue("ProductVersion" in values) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_get_domain_value(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values = self.lockdown_service.get_domain_Value( client, "com.apple.iTunes", None) print("values", type(values), values) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_set_domain_value(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values = self.lockdown_service.get_domain_Value(client, None, None) self.lockdown_service.set_domain_Value( client, None, "DeviceName", plist_new_string("DeviceName".encode("utf-8"))) values = self.lockdown_service.get_domain_Value(client, None, None) print("after values", type(values), values) self.lockdown_service.free_client(client) self.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)