From eafd56364031bf8759e4d2ea92d3b7fab295bdab Mon Sep 17 00:00:00 2001 From: camalot Date: Tue, 17 May 2016 20:35:13 -0500 Subject: [PATCH 1/2] manual merge of change submitted in PR #19 --- .appveyor/appveyor.before-build.ps1 | 8 +++-- Managed.AndroidDebugBridge/AdbHelper.cs | 45 +++++++++++++++++++++++++ Managed.AndroidDebugBridge/Device.cs | 19 ++++++++++- Managed.AndroidDebugBridge/IDevice.cs | 8 +++++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/.appveyor/appveyor.before-build.ps1 b/.appveyor/appveyor.before-build.ps1 index e3cc17e..e5658b4 100644 --- a/.appveyor/appveyor.before-build.ps1 +++ b/.appveyor/appveyor.before-build.ps1 @@ -7,9 +7,11 @@ try { Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Import-PfxCertificate.psm1"; Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\modules\Set-BuildVersion.psm1"; - -Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value); - +if( (Test-Path -Path 'Env:\VS_PFX_KEY') -and (Test-Path -Path Env:\MADB_PFX_KEY) ) { + Import-PfxCertificate -pfx "$env:APPVEYOR_BUILD_FOLDER\Shared\madb.pfx" -password ((Get-Item Env:\MADB_PFX_KEY).Value) -containerName ((Get-Item Env:\VS_PFX_KEY).Value); +} else { + "VS_PFX_KEY and MAD_PFX_KEY are missing; skipping PFX Certificate import." | Write-Warning; +} $env:CI_BUILD_DATE = ((Get-Date).ToUniversalTime().ToString("MM-dd-yyyy")); $env:CI_BUILD_TIME = ((Get-Date).ToUniversalTime().ToString("hh:mm:ss")); diff --git a/Managed.AndroidDebugBridge/AdbHelper.cs b/Managed.AndroidDebugBridge/AdbHelper.cs index 0553666..6d77844 100644 --- a/Managed.AndroidDebugBridge/AdbHelper.cs +++ b/Managed.AndroidDebugBridge/AdbHelper.cs @@ -547,6 +547,51 @@ public bool CreateForward ( IPEndPoint adbSockAddr, Device device, int localPort return true; } + /// + /// Creates the reverse forward. + /// + /// The adb sock addr. + /// The device. + /// The remote port. + /// The local port. + /// + /// + /// failed to submit the forward command. + /// or + /// Device rejected command: + resp.Message + /// + public bool CreateReverseForward ( IPEndPoint adbSockAddr, Device device, int remotePort, int localPort ) { + + 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 ); + + byte[] request = FormAdbRequest ( String.Format ( "reverse:forward:tcp:{0};tcp:{1}", //$NON-NLS-1$ + remotePort, localPort ) ); + + if ( !Write ( adbChan, request ) ) { + throw new AdbException ( "failed to submit the reverse forward command." ); + } + + AdbResponse resp = ReadAdbResponse ( adbChan, false /* readDiagString */); + if ( !resp.IOSuccess || !resp.Okay ) { + throw new AdbException ( "Device rejected command: " + resp.Message ); + } + } finally { + if ( adbChan != null ) { + adbChan.Close ( ); + } + } + + return true; + } + + /// /// Lists the forward. /// diff --git a/Managed.AndroidDebugBridge/Device.cs b/Managed.AndroidDebugBridge/Device.cs index 30fef13..ffaf6c6 100644 --- a/Managed.AndroidDebugBridge/Device.cs +++ b/Managed.AndroidDebugBridge/Device.cs @@ -720,7 +720,24 @@ public bool CreateForward ( int localPort, int remotePort ) { return false; } } - + + + /// + /// Creates a reverse port forwarding between a local and a remote port. + /// + /// the remote port to forward + /// the local port. + /// true if success. + public bool CreateReverseForward ( int remotePort, int localPort ) + { + try { + return AdbHelper.Instance.CreateReverseForward(AndroidDebugBridge.SocketAddress, this, remotePort, localPort); + } catch(IOException e) { + Log.w("ddms", e); + return false; + } + } + /// /// Removes a port forwarding between a local and a remote port. /// diff --git a/Managed.AndroidDebugBridge/IDevice.cs b/Managed.AndroidDebugBridge/IDevice.cs index f39dcb0..d1e37a6 100644 --- a/Managed.AndroidDebugBridge/IDevice.cs +++ b/Managed.AndroidDebugBridge/IDevice.cs @@ -280,6 +280,14 @@ public interface IDevice { /// true if success. bool CreateForward(int localPort, int remotePort); + /// + /// Creates a reverse port forwarding between a local and a remote port. + /// + /// the remote port to forward + /// the local port. + /// true if success. + bool CreateReverseForward ( int remotePort, int localPort ); + /// /// Removes a port forwarding between a local and a remote port. /// From aa010e5e33db8d69f247934890f8af4e7dc1a554 Mon Sep 17 00:00:00 2001 From: camalot Date: Tue, 17 May 2016 20:50:11 -0500 Subject: [PATCH 2/2] fixed the reference to a package in the website that was invalid. this was causing the pr build to fail. but not the branch for some reason... --- Madb.Site/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Madb.Site/packages.config b/Madb.Site/packages.config index a8d80cb..d77fa47 100644 --- a/Madb.Site/packages.config +++ b/Madb.Site/packages.config @@ -3,7 +3,7 @@ - +