Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusyBox"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public BusyBox( Device device )
 {
     this.Device = device;
     Version = new System.Version ( "0.0.0.0" );
     Commands = new List<string> ( );
     CheckForBusyBox ( );
 }
Esempio n. 2
0
        //-------------------------------------------------------------------------------------------------------------
        // Operations
        //-------------------------------------------------------------------------------------------------------------

        /**
         * Opens a socket to the indicated device at indicated address and port
         * 
         * @exception   SocketException thrown when the socket parameters are invalid
         * @exception   AdbException    Thrown when an Adb error condition occurs
         *
         * @param   address The address.
         * @param   device  the device to connect to. Can be null in which case the connection will be to the first available
         *                  device.
         * @param   port    The port.
         *
         * @return  A Socket.
         */
        public Socket Open(IPAddress address, Device device, int port)
            {
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
                {
                s.Connect(address, port);
                s.Blocking = true;
                s.NoDelay = false;

                SetDevice(s, device?.SerialNumber);

                byte[] req = CreateAdbForwardRequest(null, port);
                Write(s, req);
                AdbResponse resp = ReadAdbResponse(s);
                if (!resp.Okay)
                    {
                    throw new AdbException("connection request rejected");
                    }
                s.Blocking = true;
                }
            catch (Exception)
                {
                s?.Close();
                throw;
                }
            return s;
            }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Client"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="pid">The pid.</param>
        public Client( Device device, Socket channel, int pid )
        {
            this.Device = device;
            this.Channel = channel;
            this.ClientData = new ClientData ( pid );

            IsThreadUpdateEnabled = DdmPreferences.InitialThreadUpdate;
            IsHeapUpdateEnabled = DdmPreferences.InitialHeapUpdate;
            ConnectionState = ClientConnectionState.Init;
        }
Esempio n. 4
0
        public void RunLogService(IPEndPoint address, Device device, string logName, LogReceiver rcvr)
            {
            using (Socket socket = ExecuteRawSocketCommand(address, device, "log:{0}".With(logName)))
                {
                byte[] data = new byte[16384];
                using (MemoryStream ms = new MemoryStream(data))
                    {
                    int offset = 0;

                    while (true)
                        {
                        int count;
                        if (rcvr != null && rcvr.IsCancelled)
                            {
                            break;
                            }
                        byte[] buffer = new byte[4*1024];

                        count = socket.Receive(buffer);
                        if (count < 0)
                            {
                            break;
                            }
                        else if (count == 0)
                            {
                            try
                                {
                                Thread.Sleep(WAIT_TIME*5);
                                }
                            catch (ThreadInterruptedException)
                                {
                                }
                            }
                        else
                            {
                            ms.Write(buffer, offset, count);
                            offset += count;
                            if (rcvr != null)
                                {
                                byte[] d = ms.ToArray();
                                rcvr.ParseNewData(d, 0, d.Length);
                                }
                            }
                        }
                    }
                }
            }
Esempio n. 5
0
 public void RunEventLogService(IPEndPoint address, Device device, LogReceiver rcvr)
     {
     RunLogService(address, device, "events", rcvr);
     }
Esempio n. 6
0
 public DeviceEventArgs(Device device)
 {
     this.Device = device;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncService"/> class.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <param name="device">The device.</param>
 public SyncService( IPEndPoint address, Device device )
 {
     Address = address;
     Device = device;
     Open ( );
 }
Esempio n. 8
0
 private Socket ExecuteRawSocketCommand(IPEndPoint address, Device device,       string command) => ExecuteRawSocketCommand(address, device, FormAdbRequest(command));
Esempio n. 9
0
 private string HostPrefixFromDevice(Device device)
     {
     switch (device.TransportType)
         {
     case TransportType.Host:
         return "host-serial";
     case TransportType.Usb:
         return "host-usb";
     case TransportType.Local:
         return "host-local";
     case TransportType.Any:
     default:
         return "host";
         }
     }
Esempio n. 10
0
 public void ListForward(IPEndPoint address, Device device)
     {
     throw new NotImplementedException();
     }
Esempio n. 11
0
 public bool RemoveForward(IPEndPoint address, Device device, int localPort)
     {
     using (Socket socket = ExecuteRawSocketCommand(address, device, "host-serial:{0}:killforward:tcp:{1}".With(device.SerialNumber, localPort)))
         {
         // do nothing...
         return true;
         }
     }
Esempio n. 12
0
        public Socket CreatePassThroughConnection(IPEndPoint endpoint, Device device, int pid)
            {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
                {
                socket.Connect(endpoint);
                socket.NoDelay = true;

                // if the device is not -1, then we first tell adb we're looking to talk to a specific device
                SetDevice(socket, device?.SerialNumber);

                byte[] req = CreateJdwpForwardRequest(pid);

                Write(socket, req);

                AdbResponse resp = ReadAdbResponse(socket);
                if (!resp.Okay)
                    throw new AdbException("connection request rejected: " + resp.Message); //$NON-NLS-1$
                }
            catch (Exception)
                {
                socket?.Close();
                throw;
                }

            return socket;
            }
Esempio n. 13
0
        public bool CreateForward(IPEndPoint adbSockAddr, Device device, int localPort, int remotePort)
            {
            Socket adbChan = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
                {
                adbChan.Connect(adbSockAddr);
                adbChan.Blocking = true;

                // host-serial should be different based on the transport...
                byte[] request = FormAdbRequest($"host-serial:{device.SerialNumber}:forward:tcp:{localPort};tcp:{remotePort}");

                Write(adbChan, request);

                AdbResponse resp = ReadAdbResponse(adbChan);
                if (!resp.IOSuccess || !resp.Okay)
                    {
                    throw new AdbException("Device rejected command: " + resp.Message);
                    }
                }
            finally
                {
                adbChan?.Close();
                }

            return true;
            }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileSystem"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public FileSystem( Device device )
 {
     Device = device;
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileListingService"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public FileListingService( Device device )
     : this(device, device.BusyBox.Available)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileListingService"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="forceBusyBox">if set to <c>true</c> [force busy box].</param>
 public FileListingService( Device device, bool forceBusyBox )
 {
     this.Device = device;
     this.Threads = new List<Thread> ( );
     this.ForceBusyBox = forceBusyBox && device.BusyBox.Available;
 }
Esempio n. 17
0
 public void Reboot(IPEndPoint adbSocketAddress, Device device)
     {
     Reboot(string.Empty, adbSocketAddress, device);
     }
Esempio n. 18
0
 public bool RemoveAllForward(IPEndPoint address, Device device)
     {
     using (Socket socket = ExecuteRawSocketCommand(address, device, "host-serial:{0}:killforward-all".With(device.SerialNumber)))
         {
         // do nothing...
         return true;
         }
     }
Esempio n. 19
0
        public void Reboot(string into, IPEndPoint adbSockAddr, Device device)
            {
            byte[] request = string.IsNullOrEmpty(@into) ? FormAdbRequest("reboot:") : FormAdbRequest("reboot:" + @into);

            using (ExecuteRawSocketCommand(adbSockAddr, device, request))
                {
                // nothing to do...
                }
            }
Esempio n. 20
0
        public RawImage GetFrameBuffer(IPEndPoint adbSockAddr, Device device)
            {
            RawImage imageParams = new RawImage();
            byte[] request = FormAdbRequest("framebuffer:"); //$NON-NLS-1$
            byte[] nudge = { 0 };
            byte[] reply;

            Socket adbChan = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
                {
                adbChan.Connect(adbSockAddr);
                adbChan.Blocking = true;

                // if the device is not -1, then we first tell adb we're looking to talk
                // to a specific device
                SetDevice(adbChan, device?.SerialNumber);
                Write(adbChan, request);

                AdbResponse resp = ReadAdbResponse(adbChan);
                if (!resp.IOSuccess || !resp.Okay)
                    {
                    Log.v(LOGGING_TAG, "Got timeout or unhappy response from ADB fb req: " + resp.Message);
                    adbChan.Close();
                    return null;
                    }

                // first the protocol version.
                reply = new byte[4];
                Read(adbChan, reply);
                BinaryReader buf;
                int version = 0;
                using (MemoryStream ms = new MemoryStream(reply))
                    {
                    buf = new BinaryReader(ms);
                    version = buf.ReadInt16();
                    }

                // get the header size (this is a count of int)
                int headerSize = RawImage.GetHeaderSize(version);
                // read the header
                reply = new byte[headerSize*4];
                Read(adbChan, reply);
                using (MemoryStream ms = new MemoryStream(reply))
                    {
                    buf = new BinaryReader(ms);

                    // fill the RawImage with the header
                    if (imageParams.ReadHeader(version, buf) == false)
                        {
                        Log.v(LOGGING_TAG, "Unsupported protocol: " + version);
                        return null;
                        }
                    }

                Log.d(LOGGING_TAG, "image params: bpp=" + imageParams.Bpp + ", size="
                    + imageParams.Size + ", width=" + imageParams.Width
                    + ", height=" + imageParams.Height);

                Write(adbChan, nudge);

                reply = new byte[imageParams.Size];
                Read(adbChan, reply);
                imageParams.Data = reply;
                }
            finally
                {
                adbChan?.Close();
                }

            return imageParams;
            }
Esempio n. 21
0
 private Socket ExecuteRawSocketCommand(IPEndPoint address, Device device, byte[] command)
     {
     if (device != null && !device.IsOnline)
         throw new AdbException("Device is offline");
     return ExecuteRawSocketCommand(address, device?.SerialNumber, command);
     }
 /// <summary>
 /// Creates an instance of PackageManagerReceiver
 /// </summary>
 /// <param name="device"></param>
 /// <param name="pm"></param>
 public PackageManagerReceiver( Device device, PackageManager pm )
 {
     Device = device;
     PackageManager = pm;
 }
 public EnvironmentVariablesReceiver(Device device)
 {
     Device = device;
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MountPointReceiver"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public MountPointReceiver( Device device )
 {
     Device = device;
 }
Esempio n. 25
0
 public void ExecuteRemoteRootCommand(IPEndPoint endPoint, string command, Device device, IShellOutputReceiver rcvr)
     {
     ExecuteRemoteRootCommand(endPoint, $"su -c \"{command}\"", device, rcvr, int.MaxValue);
     }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncService"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public SyncService( Device device )
     : this(AndroidDebugBridge.AdbServerSocketAddress, device)
 {
 }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageManager"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public PackageManager( Device device )
 {
     Device = device;
     Packages = new Dictionary<string, FileEntry> ( );
 }
Esempio n. 28
0
 public void ExecuteRemoteRootCommand(IPEndPoint endPoint, string command, Device device, IShellOutputReceiver rcvr, int maxTimeToOutputResponse)
     {
     ExecuteRemoteCommand(endPoint, $"su -c \"{command}\"", device.SerialNumber, rcvr);
     }
Esempio n. 29
0
 public GetPropReceiver(Device device)
 {
     this.Device = device;
 }
Esempio n. 30
0
 // Do what we need to do when we detect a device making its transition to the online state
 private void OnDeviceTransitionToOnline(Device device)
 {
     device.RefreshFromDevice();
     this.bridge?.OnDeviceConnected(new DeviceEventArgs(device));
 }