def install(self, ipa_path, options=None, handler=None, *args): '''安装应用程序 :param ipa_path: 安装包的路径 :type ipa_path: str :return: boolean - 安装是否成功 ''' print "上传安装包..." afc_client = AFCClient(self.lockdown) tmp_ipa = "t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc_client.set_file_contents("/" + tmp_ipa, ipa_content) print "上传完毕" print "开始安装" cmd = {"Command": "Install", "PackagePath": tmp_ipa} if options: cmd.update(options) self.lockdown = LockdownClient(self.udid) self.service = self.lockdown.startService( "com.apple.mobile.installation_proxy") self.service.sendPlist(cmd) ret = self.wait_completion(handler, args) if ret[0]: print "安装成功" else: print "安装失败:%s" % ret[1] return ret
def test_get_crash_log(self): mux = USBMux() if not mux.devices: mux.process(0.1) if len(mux.devices) == 0: print("no real device found") self.no_device = True return udid = mux.devices[0].serial procname = "QQ" lockdown = LockdownClient(udid) self.service = lockdown.startService("com.apple.crashreportcopymobile") client = AFCClient(lockdown, service=self.service) afc_shell = AFCShell(client=client) remote_crash_path = '/' dest_path = '/tmp' local_crashes = [] print('udid:', udid) for _dirname, _dirs, files in afc_shell.afc.dir_walk( remote_crash_path): for filename in files: if procname in filename: remote_crash_file = os.path.join(remote_crash_path, filename) data = afc_shell.afc.get_file_contents(remote_crash_file) local_crash_file = os.path.join(dest_path, filename) local_crashes.append(local_crash_file) with open(local_crash_file, 'wb') as fp: fp.write(data) print(local_crashes)
def start(self): self.udid = lockdown.getValue("", "UniqueDeviceID") self.willEncrypt = lockdown.getValue("com.apple.mobile.backup", "WillEncrypt") self.escrowBag = lockdown.getValue('', 'EscrowBag') # We need this to create lock files self.afc = AFCClient(self.lockdown) self.service = self.lockdown.startServiceWithEscrowBag( "com.apple.mobilebackup2", self.escrowBag) if not self.service: raise Exception( "MobileBackup2 init error : Could not start com.apple.mobilebackup2" ) if not os.path.isdir(self.backupPath): os.makedirs(self.backupPath, 0o0755) self.logger.info( "Starting new com.apple.mobilebackup2 service with working dir: %s", self.backupPath) DLMessageVersionExchange = self.service.recvPlist() version_major = DLMessageVersionExchange[1] self.service.sendPlist( ["DLMessageVersionExchange", "DLVersionsOk", version_major]) DLMessageDeviceReady = self.service.recvPlist() if DLMessageDeviceReady and DLMessageDeviceReady[ 0] == "DLMessageDeviceReady": res = self.version_exchange() protocol_version = res.get('ProtocolVersion') self.logger.info("Negotiated Protocol Version %s", protocol_version[1]) else: raise Exception("MobileBackup2 init error %s", DLMessageDeviceReady)
def create_info_plist(self): root_node = self.lockdown.allValues info = {"BuildVersion": root_node.get("BuildVersion") or "", "DeviceName": root_node.get("DeviceName") or "", "Display Name": root_node.get("DeviceName") or "", "GUID": "---", "ProductType": root_node.get("ProductType") or "", "ProductVersion": root_node.get("ProductVersion") or "", "Serial Number": root_node.get("SerialNumber") or "", "Unique Identifier": self.udid.upper(), "Target Identifier": self.udid, "Target Type": "Device", "iTunes Version": "10.0.1" } info["ICCID"] = root_node.get("IntegratedCircuitCardIdentity") or "" info["IMEI"] = root_node.get("InternationalMobileEquipmentIdentity") or "" info["Last Backup Date"] = datetime.datetime.now() afc = AFCClient(self.lockdown) iTunesFilesDict = {} iTunesFiles = afc.read_directory("/iTunes_Control/iTunes/") for i in iTunesFiles: data = afc.get_file_contents("/iTunes_Control/iTunes/" + i) if data: iTunesFilesDict[i] = plistlib.Data(data) info["iTunesFiles"] = iTunesFilesDict iBooksData2 = afc.get_file_contents("/Books/iBooksData2.plist") if iBooksData2: info["iBooks Data 2"] = plistlib.Data(iBooksData2) info["iTunes Settings"] = self.lockdown.getValue("com.apple.iTunes") self.logger.info("Creating: %s", os.path.join(self.udid,"Info.plist")) self.write_file(os.path.join(self.udid,"Info.plist"), plistlib.writePlistToString(info))
def install_ipa(uuid, ipa_path): """ docstring for install_ipa """ from pymobiledevice.afc import AFCClient lockdown, service = get_lockdown_and_service(uuid) afc = AFCClient(lockdown=lockdown) afc.set_file_contents(path.basename(ipa_path), open(ipa_path, "rb").read()) cmd = {"Command": "Install", "PackagePath": path.basename(ipa_path)} return run_command(service, uuid, cmd)
def install_or_upgrade(self, ipaPath, cmd="Install", options=None, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, "rb").read()) cmd = {"Command": cmd, "PackagePath": os.path.basename(ipaPath)} if options: cmd.update(options) self.service.sendPlist(cmd) # print "%s : " % (cmd, bundleID) print "%s : %s\n" % (cmd, self.watch_completion(handler, args))
def house_arrest(lockdown, applicationId): try: mis = lockdown.startService("com.apple.mobile.house_arrest") except: lockdown = LockdownClient() mis = lockdown.startService("com.apple.mobile.house_arrest") if mis == None: return mis.sendPlist({"Command": "VendDocuments", "Identifier": applicationId}) res = mis.recvPlist() if res.get("Error"): print("Unable to Lookup the selected application: You probably trying to access to a system app...") return None return AFCClient(lockdown, service=mis)
def install_or_upgrade(self, ipaPath, cmd="Install", options={}, handler=None, *args): afc = AFCClient(self.lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, "rb").read()) cmd = { "Command": cmd, "ClientOptions": options, "PackagePath": os.path.basename(ipaPath) } self.service.sendPlist(cmd) self.watch_completion(handler, args)
def test_install_app(self): if self.no_device: return ipa_path = os.path.join(os.path.expanduser("~"), "Downloads/app/DemoApp.ipa") tmp_ipa = "/t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc = AFCClient(self.lockdownclient) afc.set_file_contents(tmp_ipa, ipa_content) print("Upload completed") print("Starting installation") cmd = {"Command":"Install", "PackagePath": tmp_ipa} self.lockdownclient = LockdownClient(self.udid) self.service = self.lockdownclient.startService("com.apple.mobile.installation_proxy") self.service.sendPlist(cmd) result, err = self.wait_completion() self.assertTrue(result, 'install_app failed: %s' % err)
def install(self, ipa_path, options=None, handler=None, *args): '''安装应用程序 :param ipa_path: 安装包的路径 :type ipa_path: str :return: boolean - 安装是否成功 ''' print "上传安装包..." afc_client = AFCClient() tmp_ipa = "t%d.ipa" % time.time() with open(ipa_path, "rb") as f: ipa_content = f.read() afc_client.set_file_contents("/" + tmp_ipa, ipa_content) print "上传完毕" print "开始安装" cmd = {"Command": "Install", "PackagePath": tmp_ipa} if options: cmd.update(options) self.service.sendPlist(cmd) return self.wait_completion(handler, args)
def mobile_install(lockdown, ipaPath): # Start afc service & upload ipa afc = AFCClient(lockdown) afc.set_file_contents("/" + os.path.basename(ipaPath), open(ipaPath, 'rb').read()) mci = lockdown.startService("com.apple.mobile.installation_proxy") #print mci.sendPlist({"Command":"Archive","ApplicationIdentifier": "com.joystickgenerals.STActionPig"}) mci.sendPlist({"Command": "Install", # "ApplicationIdentifier": "com.gotohack.JBChecker", "PackagePath": os.path.basename(ipaPath)}) while True: z = mci.recvPlist() if not z: break completion = z.get('PercentComplete') if completion: print('Installing, %s: %s %% Complete' % ( ipaPath, z['PercentComplete'])) if z.get('Status') == 'Complete': print("Installation %s\n" % z['Status']) break
def setUp(self): mux = USBMux() if not mux.devices: mux.process(0.1) if len(mux.devices) == 0: print("no real device found") self.no_device = True return udid = mux.devices[0].serial lockdown_client = LockdownClient(udid) self.service = lockdown_client.startService( "com.apple.mobile.house_arrest") self.service.sendPlist({ "Command": "VendContainer", "Identifier": "com.gotohack.testapp" }) status = self.service.recvPlist() if 'Error' in status and status['Error'] == "ApplicationLookupFailed": raise RuntimeWarning('ApplicationLookupFailed') if 'Status' in status and status['Status'] != 'Complete': raise RuntimeWarning('House arrest service launch failed') self.afc = AFCClient(lockdown_client, service=self.service) self.afc_shell = AFCShell(client=self.afc)