예제 #1
0
 def shell(self, cmd):
     """run command in device, returns pty output after the command exits"""
     if len(cmd) == 0:
         raise ValueError('no command specified for blocking shell')
     sock = self.shell_stream(cmd)
     data = recvall(sock)
     sock.close()
     return data
예제 #2
0
 def exec(self, cmd):
     """run command in device, returns stdout content after the command exits"""
     if len(cmd) == 0:
         raise ValueError('no command specified for blocking exec')
     sock = self.exec_stream(cmd)
     data = recvall(sock)
     sock.close()
     return data
예제 #3
0
 def screencap(self):
     """returns (width, height, pixels)
     pixels in RGBA/RGBX format"""
     s = self.device_session_factory().exec_stream('screencap|gzip -1')
     data = recvall(s, 4194304)
     s.close()
     data = zlib.decompress(data, zlib.MAX_WBITS | 16, 8388608)
     w, h, f = struct.unpack_from('III', data, 0)
     assert (f == 1)
     return (w, h, data[12:])
예제 #4
0
 def _reverse_connection_screencap(self):
     """returns (width, height, pixels)
     pixels in RGBA/RGBX format"""
     future = self.rch.register_cookie()
     with future:
         control_sock = self.device_session_factory().exec_stream(
             '(echo -n %s; screencap) | nc %s %d' %
             (future.cookie.decode(), self.loopback, self.rch.port))
         with control_sock:
             with future.get() as conn:
                 data = recvall(conn, 8388608, True)
     w, h, f = struct.unpack_from('III', data, 0)
     assert (f == 1)
     return (w, h, data[12:].tobytes())
예제 #5
0
 def _test_reverse_connection(self, loopbacks):
     for addr in loopbacks:
         logger.debug('testing loopback address %s' % addr)
         future = self.rch.register_cookie()
         with future:
             cmd = 'echo -n %sOKAY | nc -w 1 %s %d' % (
                 future.cookie.decode(), addr, self.rch.port)
             logger.debug(cmd)
             control_sock = self.device_session_factory().exec_stream(cmd)
             with control_sock:
                 conn = future.get(2)
                 if conn is not None:
                     data = recvall(conn)
                     conn.close()
                     if data == b'OKAY':
                         self.loopback = addr
                         logger.debug('found loopback address %s' % addr)
                         return True
     return False
예제 #6
0
 def screencap_png(self):
     """returns PNG bytes"""
     s = self.device_session_factory().exec_stream('screencap -p')
     data = recvall(s, 4194304)
     return data