def connect_device_usb() -> NoReturn: global device, device_is_connected, device_name, device_android_version, device_user if not os.path.exists(cfg.adb_key_file_path): keygen(cfg.adb_key_file_path) log_info(f"[ADB] generated and stored a new adb-RSA-key (was missing)", logger="debuglog") with open(cfg.adb_key_file_path) as f: priv = f.read() with open(cfg.adb_key_file_path + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) try: device = AdbDeviceUsb( ) # TODO: there can be more than one phone, determine with "available", "list" or similar except UsbDeviceNotFoundError: device = None log_error( f"[ADB] is the device connected and ADB activated on device?", logger="debuglog") except DevicePathInvalidError: device = None log_error( "[ADB] installation seems incomplete, adb-shell[usb] is missing (or not working as intended) or adb-server is still running on your system", logger="debuglog") if device is not None: device.connect(rsa_keys=[signer], auth_timeout_s=30) if not is_device_available(): return device_is_connected = True log_info(f"[ADB] connected to USB-Device", logger="debuglog") update_device_properties()
def main(debug, adb_server, adb_port, authkey, apk): if debug: logging.basicConfig( format="%(asctime)s:%(levelname)s:%(name)s:%(message)s") logger = logging.getLogger('apksideloader') logger.setLevel(logging.DEBUG) logger.debug("Debugging mode enabled") else: logging.basicConfig() win = MainWindow() conn = AdbConnection(server=adb_server, port=adb_port, signer=PythonRSASigner('', authkey.read())) apks = queue.Queue() for counter, pkg in enumerate(apk): apk = ApkStatus(pkg) win.add_apk(apk) apks.put(apk) win.show_all() worker_thread = threading.Thread(target=worker, daemon=True, args=(win, conn, apks)).start() Gtk.main()
async def load_adbkey(adbkey): """Load the ADB keys. Parameters ---------- adbkey : str The path to the ``adbkey`` file for ADB authentication Returns ------- PythonRSASigner The ``PythonRSASigner`` with the key files loaded """ # private key async with aiofiles.open(adbkey) as f: priv = await f.read() # public key try: async with aiofiles.open(adbkey + '.pub') as f: pub = await f.read() except FileNotFoundError: pub = '' return PythonRSASigner(pub, priv)
def _connect(self): """ in my experience, it was better to connect, send commands, disconnect right away rather than connect once and send many commands for hours => getting very slow at some point Now added auto-reconnect feature with argument auto_reconnect_seconds defaulting to 1 min """ now = time.time() if self._device and self._last_connected_time + self.auto_reconnect_seconds < now: self._disconnect() if self._device: return if self.verbose: print(f">>> connecting to {self.ip}") self._last_connected_time = now self._device = AdbDeviceTcp(self.ip, default_timeout_s=self.auto_reconnect_seconds) if not self.need_auth: self._device.connect(auth_timeout_s=0.1) else: with open(os.path.expanduser('~/.android/adbkey')) as f: private_key = f.read() signer = PythonRSASigner('', private_key) self._device.connect(rsa_keys=[signer], auth_timeout_s=0.1) if self.verbose: print(f">>> connected")
def Connect_ADB(): global ADBDevice host = request.args.get('host') print("ADB_Driver: host:", host) logger.info("ADB_Driver: connecting to host: " + host) try: # Checking if we are already connected. ADBDevice = ADBHostList[host]["ADBSocket"] return except: logger.info("Setting up connection ADB with " + host) ADBDevice = AdbDeviceTcp(host, 5555, default_transport_timeout_s=5.) ## Load the public and private keys so we can connect to Android and authenticate ourself (also for future use) adbkey = '/home/neeo/ADB_Shell_key' with open(adbkey) as f: priv = f.read() with open(adbkey + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) ADBDevice.connect(rsa_keys=[signer], auth_timeout_s=5) ADBHostList.setdefault(host, {})["ADBSocket"] = ADBDevice logger.info("Hostlist is now ") logger.info(ADBHostList) return
def load_adbkey(adbkey): """Load the ADB keys. Parameters ---------- adbkey : str The path to the ``adbkey`` file for ADB authentication Returns ------- PythonRSASigner The ``PythonRSASigner`` with the key files loaded """ # private key with open(adbkey) as f: priv = f.read() # public key try: with open(adbkey + ".pub") as f: pub = f.read() except FileNotFoundError: pub = "" return PythonRSASigner(pub, priv)
def test_connect_with_key(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey') self.device._handle._bulk_read = b''.join(patchers.BULK_READ_LIST_WITH_AUTH) self.assertTrue(self.device.connect([signer]))
def connect(self): with open(os.path.join(os.path.expanduser('~'), '.android/adbkey')) as f: p = f.read() signer = PythonRSASigner('', p) self.device = AdbDeviceTcp(self.ip, 5555, default_timeout_s=9.) self.device.connect(rsa_keys=[signer], auth_timeout_s=0.1) # ls -l self.ls() print('connect')
def _connect(target_ip, target_port, target_adbkey): # Open private key generated on first connect with open(target_adbkey) as f: priv = f.read() signer = PythonRSASigner('', priv) device = AdbDeviceTcp(target_ip, int(target_port), default_timeout_s=9.) device.connect(rsa_keys=[signer], auth_timeout_s=1.) return device
def connect(): with open(privkey) as f: priv = f.read() with open(pubkey) as f: pub = f.read() signer = PythonRSASigner(pub, priv) device = AdbDeviceTcp(address, port, default_transport_timeout_s=9.) device.connect(rsa_keys=[signer], auth_timeout_s=0.1) return device
def test_index_error(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): with patch('adb_shell.auth.sign_pythonrsa.decoder.decode', side_effect=IndexError): with self.assertRaises(ValueError): keygen('tests/adbkey') self.signer = PythonRSASigner.FromRSAKeyPath( 'tests/adbkey')
def test_value_error(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): with patch('adb_shell.auth.sign_pythonrsa.decoder.decode', return_value=([None, [None]], None)): with self.assertRaises(ValueError): keygen('tests/adbkey') self.signer = PythonRSASigner.FromRSAKeyPath( 'tests/adbkey')
def __init__(self, adbkey='~/.android/adbkey', ip='localhost', port=5555, timeout=9, **kwargs): with open(adbkey) as f: priv = f.read() with open(adbkey + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) self.device = AdbDeviceTcp(ip, port, default_transport_timeout_s=float(timeout)) self.device.connect(rsa_keys=[signer], auth_timeout_s=0.1) self.x, self.y = [int(i) for i in self.device.shell('wm size').split(' ')[-1].split('x')] if not os.path.exists(os.path.dirname(os.path.realpath(__file__)) + '/.cache'): os.makedirs(os.path.dirname(os.path.realpath(__file__)) + '/.cache')
def test_connect_with_key_invalid_response(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey') self.device._handle._bulk_read = b''.join(patchers.BULK_READ_LIST_WITH_AUTH_INVALID) with self.assertRaises(exceptions.InvalidResponseError): self.device.connect([signer]) self.assertFalse(self.device.available)
async def test_connect_with_new_key(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey') signer.pub_key = u'' self.device._transport._bulk_read = b''.join( patchers.BULK_READ_LIST_WITH_AUTH_NEW_KEY) self.assertTrue(await self.device.connect([signer]))
def test_connect_with_new_key_and_callback(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey') signer.pub_key = u'' self._callback_invoked = False def auth_callback(device): self._callback_invoked = True self.device._handle._bulk_read = b''.join(patchers.BULK_READ_LIST_WITH_AUTH_NEW_KEY) self.assertTrue(self.device.connect([signer], auth_callback=auth_callback)) self.assertTrue(self._callback_invoked)
def adb_connect(): key_dir = os.path.join(expanduser("~"), '.pyadb') if not os.path.exists(key_dir): os.makedirs(key_dir) key_path = os.path.join(key_dir, 'adbkey') keygen.keygen(key_path) adbkey = str(key_path) with open(adbkey) as f: priv = f.read() with open(adbkey + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) device = AdbDeviceUsb() device.connect(rsa_keys=[signer], auth_timeout_s=60) return device
def turn_off_tv(self): # Load the public and private keys with open(self.adb_key_filepath) as f: priv = f.read() with open(self.adb_key_filepath + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) # Connect android_tv = AdbDeviceTcp(self.tv_ip_address, self.adb_port, default_transport_timeout_s=9.) android_tv.connect(rsa_keys=[signer], auth_timeout_s=0.1) # Send a shell command logger.info('Shutting off TV via shell command') tv_off_command_key = '26' android_tv.shell('input keyevent %s' % tv_off_command_key) android_tv.close()
def scan_phone_tcp(to_search_path, remote_ip, adb_key_file, max_files=None): """ Search in the given directory for .jpg files and copy them to a temporarily folder. By default the 5555 port is used. After comparison, they're deleted from the original path. :param to_search_path: The path where the files are located. :param remote_ip: The IP of the device where the files are located. :param adb_key_file: The ADB key of the device to be connected. :param max_files: The number of files to be moved. :return: True """ android_images = [] with open(adb_key_file) as f: priv = f.read() signer = PythonRSASigner('', priv) device = AdbDeviceTcp(remote_ip, 5555, default_transport_timeout_s=100.) if device.connect(rsa_keys=[signer], auth_timeout_s=100.): if device.available: print("Connected to selected device.\n---") directory_scan = device.list(to_search_path, None, 9000) if max_files is None: max_files = len(directory_scan) for file in directory_scan: if os.path.splitext(file.filename.decode('utf-8'))[1] == ".jpg": save = AndroidPhoto() save.name = file.filename.decode("utf-8") save.size = file.size save.path = to_search_path android_images.append(save) if len(android_images) >= max_files: break print(f"There're listed {len(android_images)} files.\n---") for image in android_images: device.pull(image.path + image.name, os.path.join(temp_directory, image.name), progress_callback=log_pull_status, transport_timeout_s=100, read_timeout_s=100) if image.size == os.path.getsize(os.path.join(temp_directory, image.name)): device.shell('rm -f ' + to_search_path + image.name) print("\r\r" + image.name + " is now in the temp folder.") print("---\nAll files are now in the temp folder.\n---") return True
def get_apk_file(adbkey_path, device_ip, device_port, package_name): with open(adbkey_path) as f: priv = f.read() signer = PythonRSASigner('', priv) device = AdbDeviceTcp(device_ip, device_port, default_timeout_s=9.) device.connect(rsa_keys=[signer], auth_timeout_s=0.1) # Send a shell command # apk file (base.apk) print("<*> Copying APK file to /data/local/tmp/apkSneeze/base.apk (mobile device)...") shell_cmd = "su - root -c '\ mkdir -p /data/local/tmp/apkSneeze && \ cp /data/app/{}*/base.apk /data/local/tmp/apkSneeze && \ chmod 777 /data/local/tmp/apkSneeze/base.apk'".format(package_name) device.shell(shell_cmd) print("<*> Downloading APK file to {}...".format(DEFAULT_APP_NAME)) device.pull("/data/local/tmp/apkSneeze/base.apk", DEFAULT_APP_NAME) print("<*> Download done, check {}".format(DEFAULT_APP_NAME)) print("<*> Deleting APK file from /data/local/tmp/apkSneeze/base.apk (mobile device)...") device.shell("su - root -c 'rm /data/local/tmp/apkSneeze/base.apk'")
def setup_androidtv(hass, config): """Generate an ADB key (if needed) and load it.""" adbkey = config.get(CONF_ADBKEY, hass.config.path(STORAGE_DIR, "androidtv_adbkey")) if CONF_ADB_SERVER_IP not in config: # Use "adb_shell" (Python ADB implementation) if not os.path.isfile(adbkey): # Generate ADB key files keygen(adbkey) # Load the ADB key with open(adbkey) as priv_key: priv = priv_key.read() signer = PythonRSASigner("", priv) adb_log = f"using Python ADB implementation with adbkey='{adbkey}'" else: # Use "pure-python-adb" (communicate with ADB server) signer = None adb_log = f"using ADB server at {config[CONF_ADB_SERVER_IP]}:{config[CONF_ADB_SERVER_PORT]}" return adbkey, signer, adb_log
def __init__(self): super().__init__() subclass_name = self.get_subclass_name() plug_config = self.get_plug_config() # set defaults here defaults = { 'name': subclass_name, 'rsa_key_path': None, 'serial': None } # override defaults with plug config from station_config.yaml self._settings = dict(defaults, **plug_config) self.connected = False self.priv = None self.signer = None # check if adb server is running. If it is, terminate it. for proc in psutil.process_iter(): if proc.name() == 'adb': proc.terminate() time.sleep(1) break if self._settings['rsa_key_path'] == 'default': self._settings['rsa_key_path'] = os.path.expanduser( '~/.android/adbkey') if self._settings['rsa_key_path']: with open(self._settings['rsa_key_path']) as f: self.priv = f.read() self.signer = [PythonRSASigner('', self.priv)] self.device = AdbDeviceUsb(self._settings['serial']) self._connect() assert self.connected, "Unable to connect to Adb Usb device"
def Load_RSA_KEYS(self) -> None: # default adb key path aKeyPathes:List[cPath] = [cPath(OS_GetSystemUserPath() + '.android/adbkey')] #default Android Path if Globals.uPlatform==u'android': aKeyPathes.append(cPath(OS_GetSystemUserPath()+'misc/adb/adb_keys/adbkey')) #Download path aKeyPathes.append(Globals.oPathUserDownload+"/adbkey") for oPath in aKeyPathes: if oPath.Exists(): try: with open(str(oPath)) as f: oPriv = f.read() oSigner = PythonRSASigner('', oPriv) self.aGlobalRSA_KEYS.append(oSigner) Logger.info("RSA Keyfiles loaded from "+str(oPath)) except Exception as e: Logger.error("Error Loading RSA Keys from "+str(oPath)+" "+str(e)) else: Logger.debug("No RSA Keyfiles at "+oPath)
def get_app_data_dir(adbkey_path, device_ip, device_port, package_name): with open(adbkey_path) as f: priv = f.read() signer = PythonRSASigner('', priv) device = AdbDeviceTcp(device_ip, device_port, default_timeout_s=9.) device.connect(rsa_keys=[signer], auth_timeout_s=0.1) # apk file (base.apk) print("<*> Copying app data dir to /data/local/tmp/apkSneeze/{} (mobile device)...".format(DEFAULT_DATA_DIR)) shell_cmd = "su - root -c '\ mkdir -p /data/local/tmp/apkSneeze && \ cp -r /data/data/{} /data/local/tmp/apkSneeze/{} && \ chmod -R 777 /data/local/tmp/apkSneeze/'".format(package_name,DEFAULT_DATA_DIR) device.shell(shell_cmd) print("<*> Downloading app data dir file to {}...") ### doesnt allow pulling directories, will execute adb from terminal directly # device.pull("/data/local/tmp/apkSneeze/{}/") for line in run("adb -s {}:{} pull /data/local/tmp/apkSneeze/{}".format(device_ip,device_port,DEFAULT_DATA_DIR)): print(" {}".format(line.decode('utf-8'))) print("<*> Download done, check {} dir".format(DEFAULT_DATA_DIR)) print("<*> Deleting app data dir from /data/local/tmp/apkSneeze/{} (mobile device)...".format(DEFAULT_DATA_DIR)) device.shell("su - root -c 'rm -r /data/local/tmp/apkSneeze/{}'".format(DEFAULT_DATA_DIR))
def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S): """Connect to an Android TV / Fire TV device. Parameters ---------- always_log_errors : bool If True, errors will always be logged; otherwise, errors will only be logged on the first failed reconnect attempt auth_timeout_s : float Authentication timeout (in seconds) Returns ------- bool Whether or not the connection was successfully established and the device is available """ try: with _acquire(self._adb_lock): # Catch exceptions try: # Connect with authentication if self.adbkey: # private key with open(self.adbkey) as f: priv = f.read() # public key try: with open(self.adbkey + '.pub') as f: pub = f.read() except FileNotFoundError: pub = '' signer = PythonRSASigner(pub, priv) self._adb.connect(rsa_keys=[signer], auth_timeout_s=auth_timeout_s) # Connect without authentication else: self._adb.connect(auth_timeout_s=auth_timeout_s) # ADB connection successfully established _LOGGER.debug( "ADB connection to %s:%d successfully established", self.host, self.port) self._available = True return True except OSError as exc: if self._available or always_log_errors: if exc.strerror is None: exc.strerror = "Timed out trying to connect to ADB device." _LOGGER.warning("Couldn't connect to %s:%d. %s: %s", self.host, self.port, exc.__class__.__name__, exc.strerror) # ADB connection attempt failed self.close() self._available = False return False except Exception as exc: # pylint: disable=broad-except if self._available or always_log_errors: _LOGGER.warning("Couldn't connect to %s:%d. %s: %s", self.host, self.port, exc.__class__.__name__, exc) # ADB connection attempt failed self.close() self._available = False return False except LockNotAcquiredException: _LOGGER.warning( "Couldn't connect to %s:%d because adb-shell lock not acquired.", self.host, self.port) self.close() self._available = False return False
def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S): """Connect to an Android TV / Fire TV device. Parameters ---------- always_log_errors : bool If True, errors will always be logged; otherwise, errors will only be logged on the first failed reconnect attempt auth_timeout_s : float Authentication timeout (in seconds) Returns ------- bool Whether or not the connection was successfully established and the device is available """ self._adb_lock.acquire(**LOCK_KWARGS) # pylint: disable=unexpected-keyword-arg # Make sure that we release the lock try: # Catch errors try: if self.adbkey: # private key with open(self.adbkey) as f: priv = f.read() # public key try: with open(self.adbkey + '.pub') as f: pub = f.read() except FileNotFoundError: pub = '' signer = PythonRSASigner(pub, priv) # Connect to the device self._adb.connect(rsa_keys=[signer], auth_timeout_s=auth_timeout_s) else: self._adb.connect(auth_timeout_s=auth_timeout_s) # ADB connection successfully established self._available = True _LOGGER.debug("ADB connection to %s successfully established", self.host) except socket_error as serr: if self._available or always_log_errors: if serr.strerror is None: serr.strerror = "Timed out trying to connect to ADB device." _LOGGER.warning("Couldn't connect to host %s, error: %s", self.host, serr.strerror) # ADB connection attempt failed self._adb.close() self._available = False finally: return self._available finally: self._adb_lock.release()
def test_issue29(self): # https://github.com/JeffLIrion/adb_shell/issues/29 with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey') msg1 = AdbMessage(command=constants.OKAY, arg0=1, arg1=1, data=b'\x00') msg2 = AdbMessage(command=constants.CLSE, arg0=1, arg1=1, data=b'') self.device._handle._bulk_read = b''.join([ b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\xc5\n\x00\x00\xbe\xaa\xab\xb7', # Line 22 b"\x17\xbf\xbf\xff\xc7\xa2eo'Sh\xdf\x8e\xf5\xff\xe0\tJ6H", # Line 23 b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1", # Line 26 b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2', # Line 27 b'OKAY\x99\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6', # Line 290 (modified --> Line 30) b'CLSE\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 291 b'CLSE\xa2\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 292 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba', # Line 31 b'1', # Line 32 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x001\x00\x00\x00\xa8\xad\xab\xba', # Line 35 b'1', # Line 36 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\xa8\xad\xab\xba', # Line 39 b'0', # Line 40 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x000\x06\x00\x00\xa8\xad\xab\xba', # Line 43 b'Wake Locks: size=0\n', # Line 44 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x1e\x00\x00\x00V\x0b\x00\x00\xa8\xad\xab\xba', # Line 47 b'com.google.android.youtube.tv\n', # Line 48 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00\xa13\x00\x00\xa8\xad\xab\xba', # Line 51 b' state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=0, actions=0, custom actions=[], active item id=-1, error=null}\n', # Line 52 b'WRTE\x99\x00\x00\x00\x01\x00\x00\x00.\x01\x00\x00\xceP\x00\x00\xa8\xad\xab\xba', # Line 55 b'- STREAM_MUSIC:\n Muted: false\n Min: 0\n Max: 15\n Current: 2 (speaker): 11, 4 (headset): 10, 8 (headphone): 10, 400 (hdmi): 6, 40000000 (default): 11\n Devices: hdmi\n- STREAM_ALARM:\n Muted: false\n Min: 0\n Max: 7\n Current: 40000000 (default): 6\n Devices: speaker\n- STREAM_NOTIFICATION:\n', # Line 56 b'CLSE\x99\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 59 b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x94\t\x00\x00\xbe\xaa\xab\xb7', # Line 297 b'P\xa5\x86\x97\xe8\x01\xb09\x8c>F\x9d\xc6\xbd\xc0J\x80!\xbb\x1a', # Line 298 b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1", # Line 301 b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2', # Line 302 b'OKAY\xa5\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6', # Line 305 b'CLSE\xa5\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 306 msg1.pack(), msg1.data, msg2.pack(), b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00e\x0c\x00\x00\xbe\xaa\xab\xb7', # Line 315 b'\xd3\xef\x7f_\xa6\xc0`b\x19\\z\xe4\xf3\xe2\xed\x8d\xe1W\xfbH', # Line 316 b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1", # Line 319 b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2', # Line 320 b'OKAY\xa7\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6', # Line 323 b'CLSE\xa7\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 324 msg1.pack(), msg1.data, msg2.pack(), b'AUTH\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x93\x08\x00\x00\xbe\xaa\xab\xb7', # Line 333 b's\xd4_e\xa4s\x02\x95\x0f\x1e\xec\n\x95Y9[`\x8e\xe1f', # Line 334 b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00i\x00\x00\x00.'\x00\x00\xbc\xb1\xa7\xb1", # Line 337 b'device::ro.product.name=once;ro.product.model=MIBOX3;ro.product.device=once;features=stat_v2,cmd,shell_v2', # Line 338 b'OKAY\xa9\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb0\xb4\xbe\xa6', # Line 341 b'CLSE\xa9\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xb3\xac\xba', # Line 342 msg1.pack(), msg1.data, msg2.pack() ]) self.assertTrue(self.device.connect([signer])) self.device.shell('Android TV update command') self.assertTrue(self.device.connect([signer])) self.device.shell('Android TV update command') self.device.shell('Android TV update command') self.assertTrue(self.device.connect([signer])) self.device.shell('Android TV update command') self.device.shell('Android TV update command') self.assertTrue(self.device.connect([signer])) self.device.shell('Android TV update command') self.device.shell('Android TV update command')
from adb_shell.adb_device import AdbDeviceTcp, AdbDeviceUsb from adb_shell.auth.sign_pythonrsa import PythonRSASigner # Load the public and private keys adbkey = r"C:\Users\patri\.android\adbkey" with open(adbkey) as f: priv = f.read() with open(adbkey + '.pub') as f: pub = f.read() signer = PythonRSASigner(pub, priv) # Connect device1 = AdbDeviceTcp('localhost', 5555, default_transport_timeout_s=9.) device1.connect(rsa_keys=[signer], auth_timeout_s=0.1) # Send a shell command ak = 'com.YoStarEN.Arknights' response1 = device1.shell('am start -n com.YoStarEN.Arknights') startup = device1.shell('monkey -p com.YoStarEN.Arknights 1')
def setUp(self): with patch('adb_shell.auth.sign_pythonrsa.open', open_priv_pub), patch('adb_shell.auth.keygen.open', open_priv_pub): keygen('tests/adbkey') self.signer = PythonRSASigner.FromRSAKeyPath('tests/adbkey')
def connect(self): if not Path(ADBClient.key_path).exists(): keygen(self.key_path) signer = PythonRSASigner.FromRSAKeyPath(self.key_path) self.device.connect(rsa_keys=[signer])