/// <summary> /// Create foward port /// </summary> /// <param name="minitouchport"></param> public void CreateForward(string localport, string remoteport) { try { client.CreateForward(selectedDevice, ForwardSpec.Parse(localport), ForwardSpec.Parse(remoteport), true); Console.Out.WriteLine("Forward Success"); } catch { } }
public void StartLocationService() { Dispatcher.BackgroundThread(() => { var adb = new AdbClient(AdbServer.Instance.EndPoint); if (LocationPort == -1) { adb.ExecuteRemoteCommand("am start com.github.fakegps/.ui.MainActivity", Device, null); adb.CreateForward(Device, LocationPort = Program.getFreePort(Program.LocationBase), 9998); Thread.Sleep(1000); locClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); locClient.Connect("127.0.0.1", LocationPort); } }); }
public void Forward(int port) { var localSpec = new ForwardSpec { Protocol = ForwardProtocol.Tcp, Port = port }; var remoteSpec = new ForwardSpec { Protocol = ForwardProtocol.LocalAbstract, SocketName = "Unity-" + GlobalData.Instance.AndroidPackageName }; port = m_client.CreateForward(m_deviceData, localSpec, remoteSpec, true); if (port == 0) { return; } MessageBox.Show($"Forward : {port}"); }
void Enslave(int virtualWid, int virtualHei) { Overseer = new Overseer(this); var adb = new AdbClient(AdbServer.Instance.EndPoint); // 初始化minicap adb.ExecuteRemoteCommand("getprop", Device, this); while (!flushed) { Thread.Sleep(100); } if (int.Parse(SDK) > 23) { throw new NotSupportedException($"SDK版本不支持:{SDK}"); } try { adb.ExecuteRemoteCommand("mkdir /data/local", Device, null); } catch { } try { adb.ExecuteRemoteCommand("mkdir /data/local/tmp", Device, null); } catch { } try { adb.ExecuteRemoteCommand("chmpod -R 777 /data/local/tmp/", Device, null); } catch { } try { adb.ExecuteRemoteCommand($"mkdir {Program.GlobalSetting.Get("ContentPath").Value}", Device, null); } catch { } // 上传动态链接库 new SyncService(Device).Push( File.OpenRead($@"{Program.usrDir + Program.DIR_LIBS}\android-{SDK}\{ABI}\minicap.so"), "/data/local/tmp/minicap.so", 777, DateTime.Now, CancellationToken.None); adb.ExecuteRemoteCommand("chmod 777 /data/local/tmp/minicap.so", Device, this); var exeFile = "minicap"; if (int.Parse(SDK) < 16) { exeFile = "minicap-nopie"; } // 上传可执行文件 new SyncService(Device).Push(File.OpenRead(Program.usrDir + Program.DIR_EXE + ABI + @"\" + exeFile), "/data/local/tmp/minicap", 777, DateTime.Now, CancellationToken.None); adb.ExecuteRemoteCommand("chmod 777 /data/local/tmp/minicap", Device, this); // 分配端口 ScreenPort = Program.getFreePort(Program.ScreenPortBase); ManipulatePort = Program.getFreePort(Program.MonkeyPortBase); var touchFile = "minitouch"; if (int.Parse(SDK) < 16) { touchFile = "minitouch-nopie"; } new SyncService(Device).Push( File.OpenRead($@"{Program.usrDir}\bin\lib\touch\{ABI}\{touchFile}"), "/data/local/tmp/minitouch", 777, DateTime.Now, CancellationToken.None); adb.ExecuteRemoteCommand("chmod 777 /data/local/tmp/minitouch", Device, this); adb.CreateForward(Device, new ForwardSpec() { Port = ManipulatePort, Protocol = ForwardProtocol.Tcp }, new ForwardSpec() { Protocol = ForwardProtocol.LocalAbstract, SocketName = "minitouch" }, true); ScreenService = new Screen(this, virtualWid, virtualHei); Manipulation = new Manipulate(this); Overseer.WatchDirectory("/data/local/tmp/img/"); Overseer.Watch(Program.GlobalSetting.Get("DroidLog").Value.ToString()); }