def file_write(self, handle, data): MAXIMUM_WRITE_SIZE = 1 << 15 hh = struct.pack("<Q", handle) segments = int(len(data) / MAXIMUM_WRITE_SIZE) try: for i in range(segments): self.dispatch_packet( AFC_OP_WRITE, hh + data[i * MAXIMUM_WRITE_SIZE:(i + 1) * MAXIMUM_WRITE_SIZE], this_length=48) s, d = self.receive_data() if s != AFC_E_SUCCESS: self.logger.error("file_write error: %d", s) break if len(data) % MAXIMUM_WRITE_SIZE: self.dispatch_packet(AFC_OP_WRITE, hh + data[segments * MAXIMUM_WRITE_SIZE:], this_length=48) s, d = self.receive_data() except: self.lockdown = LockdownClient() self.service = self.lockdown.start_service(self.serviceName) self.file_write(handle, data) return s
def main(): parser = OptionParser(usage="%prog") parser.add_option("-l", "--list", dest="list", action="store_true", default=False, help="List installed profiles") parser.add_option("-i", "--install", dest="install", action="store", metavar="FILE", help="Install profile") parser.add_option("-r", "--remove", dest="remove", action="store", metavar="IDENTIFIER", help="Remove profile") (options, args) = parser.parse_args() if not options.list and not options.install and not options.remove: parser.print_help() return lockdown = LockdownClient() mc = MobileConfigService(lockdown) if options.list: pprint(mc.GetProfileList()) elif options.install: mc.InstallProfile(read_file(options.install)) elif options.remove: pprint(mc.RemoveProfile(options.remove))
def file_read(self, handle, sz): MAXIMUM_READ_SIZE = 1 << 16 data = "" if PY3: data = b"" while sz > 0: if sz > MAXIMUM_READ_SIZE: toRead = MAXIMUM_READ_SIZE else: toRead = sz try: self.dispatch_packet(AFC_OP_READ, struct.pack("<QQ", handle, toRead)) s, d = self.receive_data() except: import traceback traceback.print_exc() self.lockdown = LockdownClient() self.service = self.lockdown.start_service("com.apple.afc") return self.file_read(handle, sz) if s != AFC_E_SUCCESS: break sz -= toRead data += d return data
def __init__(self, lockdown=None, serviceName='com.apple.mobile.screenshotr', udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.service = self.lockdown.start_service(serviceName) DLMessageVersionExchange = self.service.recv_plist() version_major = DLMessageVersionExchange[1] self.service.send_plist(["DLMessageVersionExchange", "DLVersionsOk", version_major]) DLMessageDeviceReady = self.service.recv_plist()
def do_operation(self, opcode, data=""): try: self.dispatch_packet(opcode, data) return self.receive_data() except Exception as E: print(E) self.lockdown = LockdownClient() self.service = self.lockdown.start_service(self.serviceName) return self.do_operation(opcode, data)
def __init__(self, lockdown=None, serviceName="com.apple.afc", service=None, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.serviceName = serviceName self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.service = service if service else self.lockdown.start_service( self.serviceName) self.packet_num = 0
def __init__(self, afcname='com.apple.afc', completekey='tab', stdin=None, stdout=None, client=None, udid=None, logger=None): Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout) self.logger = logger or logging.getLogger(__name__) self.lockdown = LockdownClient() self.afc = client if client else AFCClient( self.lockdown, serviceName=afcname, udid=udid) self.curdir = '/' self.prompt = 'AFC$ ' + self.curdir + ' ' self.complete_cat = self._complete self.complete_ls = self._complete
def __init__(self, lockdown=None, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) if not self.lockdown: raise Exception("Unable to start lockdown") self.start()
def __init__(self, lockdown=None, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.service = self.lockdown.start_service( "com.apple.springboardservices")
screen_data = res[1]['ScreenShotData'] else: screen_data = res[1]['ScreenShotData'].data return screen_data return None if __name__ == '__main__': parser = OptionParser(usage='%prog') parser.add_option("-u", "--udid", default=False, action="store", dest="device_udid", metavar="DEVICE_UDID", help="Device udid") parser.add_option('-p', '--path', dest='outDir', default=False, help='Output Directory (default: . )', type='string') (options, args) = parser.parse_args() outPath = '.' if options.outDir: outPath = options.outDir logging.basicConfig(level=logging.INFO) lckdn = LockdownClient(options.device_udid) screenshotr = screenshotr(lockdown=lckdn) data = screenshotr.take_screenshot() if data: filename = strftime('screenshot-%Y-%m-%d-%H-%M-%S.png', gmtime()) outPath = os.path.join(outPath, filename) print('Saving Screenshot at %s' % outPath) o = open(outPath, 'wb') o.write(data)
def run(self) -> None: def _callback(res): self.callback(get_auxiliary_text(res.raw)) lock_down = LockdownClient(udid=self.device_id) installation = InstallationProxy(lockdown=lock_down) app_info = installation.find_bundle_id(self.bundle_id) if not app_info: raise Exception("No app matches", self.bundle_id) logging.info("BundleID: %s", self.bundle_id) logging.info("DeviceIdentifier: %s", lock_down.device_info.get('UniqueDeviceID')) sign_identity = app_info.get("SignerIdentity", "") logging.info("SignIdentity: %r", sign_identity) xcode_version = 29 session_identifier = NSUUID('96508379-4d3b-4010-87d1-6483300a7b76') manager_lock_down_1 = TestManagerdLockdown(lock_down).init() manager_lock_down_1._make_channel( "dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface" ) if lock_down.ios_version > LooseVersion('11.0'): result = manager_lock_down_1.call( "dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface", "_IDE_initiateControlSessionWithProtocolVersion:", DTXServerRPCRawObj(xcode_version)).parsed logging.info("result: %s", result) manager_lock_down_1.register_callback(DTXEnum.FINISHED, lambda _: self.quit_event.set()) manager_lock_down_1.register_unhandled_callback(_callback) manager_lock_down_2 = TestManagerdLockdown(lock_down).init() manager_lock_down_2._make_channel( "dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface" ) manager_lock_down_2.register_callback(DTXEnum.FINISHED, lambda _: self.quit_event.set()) manager_lock_down_2.register_unhandled_callback(_callback) _start_flag = threading.Event() def _start_executing(res=None): if _start_flag.is_set(): return _start_flag.set() logging.info( " _start_executing Start execute test plan with IDE version: %d", xcode_version) manager_lock_down_2._call( False, 0xFFFFFFFF, '_IDE_startExecutingTestPlanWithProtocolVersion:', DTXServerRPCRawObj(xcode_version)) def _show_log_message(res): logging.info(f"{res.parsed} : {get_auxiliary_text(res.raw)}") if 'Received test runner ready reply with error: (null' in ''.join( get_auxiliary_text(res.raw)): logging.info("_start_executing Test runner ready detected") _start_executing() manager_lock_down_2.register_callback( '_XCT_testBundleReadyWithProtocolVersion:minimumVersion:', _start_executing) manager_lock_down_2.register_callback('_XCT_logDebugMessage:', _show_log_message) manager_lock_down_2.register_callback( '_XCT_didFinishExecutingTestPlan', lambda _: self.quit_event.set()) result = manager_lock_down_2.call( 'dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface', '_IDE_initiateSessionWithIdentifier:forClient:atPath:protocolVersion:', DTXServerRPCRawObj( session_identifier, str(session_identifier) + '-6722-000247F15966B083', '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild', xcode_version)).parsed logging.info("_start_executing result: %s", result) # launch_wda xctest_path = "/tmp/WebDriverAgentRunner-" + str( session_identifier).upper() + ".xctestconfiguration" xctest_content = archive( XCTestConfiguration({ "testBundleURL": NSURL( None, "file://" + app_info['Path'] + "/PlugIns/WebDriverAgentRunner.xctest"), "sessionIdentifier": session_identifier, })) fsync = HouseArrestClient(udid=self.device_id) fsync.send_command(self.bundle_id) for fname in fsync.read_directory("/tmp"): if fname.endswith(".xctestconfiguration"): logging.debug("remove /tmp/%s", fname) fsync.file_remove("/tmp/" + fname) fsync.set_file_contents(xctest_path, xctest_content) conn = InstrumentServer(lock_down).init() conn.call('com.apple.instruments.server.services.processcontrol', 'processIdentifierForBundleIdentifier:', self.bundle_id) conn.register_unhandled_callback(_callback) app_path = app_info['Path'] app_container = app_info['Container'] xctestconfiguration_path = app_container + xctest_path logging.info("AppPath: %s", app_path) logging.info("AppContainer: %s", app_container) app_env = { 'CA_ASSERT_MAIN_THREAD_TRANSACTIONS': '0', 'CA_DEBUG_TRANSACTIONS': '0', 'DYLD_FRAMEWORK_PATH': app_path + '/Frameworks:', 'DYLD_LIBRARY_PATH': app_path + '/Frameworks', 'NSUnbufferedIO': 'YES', 'SQLITE_ENABLE_THREAD_ASSERTIONS': '1', 'WDA_PRODUCT_BUNDLE_IDENTIFIER': '', 'XCTestConfigurationFilePath': xctestconfiguration_path, 'XCODE_DBG_XPC_EXCLUSIONS': 'com.apple.dt.xctestSymbolicator', 'MJPEG_SERVER_PORT': '', 'USE_PORT': '', } if self.app_env: app_env.update(self.app_env) if lock_down.ios_version > LooseVersion('11.0'): app_env[ 'DYLD_INSERT_LIBRARIES'] = '/Developer/usr/lib/libMainThreadChecker.dylib' app_env['OS_ACTIVITY_DT_MODE'] = 'YES' app_options = {'StartSuspendedKey': False} if lock_down.ios_version > LooseVersion('12.0'): app_options['ActivateSuspended'] = True app_args = [ '-NSTreatUnknownArgumentsAsOpen', 'NO', '-ApplePersistenceIgnoreState', 'YES' ] identifier = "launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:" pid = conn.call('com.apple.instruments.server.services.processcontrol', identifier, app_path, self.bundle_id, app_env, app_args, app_options).parsed if not isinstance(pid, int): logging.error(f"Launch failed: {pid}") raise Exception("Launch failed") logging.info(f" Launch {self.bundle_id} pid: {pid}") conn.call('com.apple.instruments.server.services.processcontrol', "startObservingPid:", DTXServerRPCRawObj(pid)) if self.quit_event: conn.register_callback(DTXEnum.FINISHED, lambda _: self.quit_event.set()) if lock_down.ios_version > LooseVersion('12.0'): identifier = '_IDE_authorizeTestSessionWithProcessID:' result = manager_lock_down_1.call( 'dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface', identifier, DTXServerRPCRawObj(pid)).parsed logging.info("_IDE_authorizeTestSessionWithProcessID: %s", result) else: identifier = '_IDE_initiateControlSessionForTestProcessID:protocolVersion:' result = manager_lock_down_1.call( 'dtxproxy:XCTestManager_IDEInterface:XCTestManager_DaemonConnectionInterface', identifier, DTXServerRPCRawObj(pid, xcode_version)).parsed logging.info("_IDE_authorizeTestSessionWithProcessID: %s", result) while not self.quit_event.wait(.1): pass logging.warning("xctrunner quited") conn.stop() manager_lock_down_2.stop() manager_lock_down_1.stop()
def __init__(self, lockdown, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.service = lockdown.start_service("com.apple.mobile.MCInstall")
def __init__(self, lockdown=None, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.c = self.lockdown.start_service("com.apple.syslog_relay")
def __init__(self, lockdown=None, udid=None, logger=None): self.logger = logger or logging.getLogger(__name__) self.lockdown = lockdown if lockdown else LockdownClient(udid=udid) self.crash_server = AFCCrashLog(lockdown=self.lockdown)