Exemplo n.º 1
0
        public static int Main(String inParam)
        {
            if (inParam == null)
            {
                return(0);
            }
            var ptr        = (IntPtr)Int64.Parse(inParam, NumberStyles.HexNumber);
            var connection = HostConnectionData.LoadData(ptr);

            if (connection.State != HostConnectionData.ConnectionState.Valid)
            {
                return((int)connection.State);
            }

            // Adjust host PID in case of WOW64 bypass and service help...
            connection.UnmanagedInfo.m_HostPID = connection.RemoteInfo.HostPID;

            try
            {
                // Prepare parameter array.
                var paramArray = new object[1 + connection.RemoteInfo.UserParams.Length];
                // The next type cast is not redundant because the object needs to be an explicit IContext
                // when passed as a parameter to the IEntryPoint constructor and Run() methods.
                paramArray[0] = (RemoteHooking.IContext)connection.UnmanagedInfo;
                for (var i = 0; i < connection.RemoteInfo.UserParams.Length; i++)
                {
                    paramArray[i + 1] = connection.RemoteInfo.UserParams[i];
                }
                // Note: at this point all but the first parameter are still binary encoded.
                // Load the user library and initialize the IEntryPoint.
                return(LoadUserLibrary(connection.RemoteInfo.UserLibraryName, connection.RemoteInfo.UserLibrary, paramArray, connection.HelperInterface));
            }
            catch (Exception ExtInfo)
            {
                Config.PrintWarning(ExtInfo.ToString());
                return(-1);
            }
            finally
            {
                if (_connectedChannels.Contains(connection.RemoteInfo.ChannelName))
                {
                    _connectedChannels.Remove(connection.RemoteInfo.ChannelName);
                }
            }
        }
Exemplo n.º 2
0
            /// <summary>
            ///     Loads <see cref="HostConnectionData" /> from the <see cref="IntPtr" /> specified.
            /// </summary>
            /// <param name="unmanagedInfoPointer"></param>
            public static HostConnectionData LoadData(IntPtr unmanagedInfoPointer)
            {
                var data = new HostConnectionData
                {
                    _state         = ConnectionState.Valid,
                    _unmanagedInfo = new REMOTE_ENTRY_INFO()
                };

                try
                {
                    // Get the unmanaged data
                    Marshal.PtrToStructure(unmanagedInfoPointer, data._unmanagedInfo);
                    using (Stream passThruStream = new MemoryStream())
                    {
                        var passThruBytes = new byte[data._unmanagedInfo.UserDataSize];
                        var format        = new BinaryFormatter();
                        // Workaround for deserialization when not using GAC registration
                        format.Binder = new AllowAllAssemblyVersionsDeserializationBinder();
                        Marshal.Copy(data._unmanagedInfo.UserData, passThruBytes, 0, data._unmanagedInfo.UserDataSize);
                        passThruStream.Write(passThruBytes, 0, passThruBytes.Length);
                        passThruStream.Position = 0;
                        data._remoteInfo        = (ManagedRemoteInfo)format.Deserialize(passThruStream);
                    }
                    // Connect the HelperServiceInterface
                    data._helperInterface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(data._remoteInfo.ChannelName);
                    // Ensure that the connection is working...
                    data._helperInterface.Ping();
                    if (!_connectedChannels.Contains(data._remoteInfo.ChannelName))
                    {
                        _connectedChannels.Add(data._remoteInfo.ChannelName);
                        return(new HostConnectionData {
                            _state = ConnectionState.NoChannel
                        });
                    }
                }
                catch (Exception ExtInfo)
                {
                    Config.PrintError(ExtInfo.ToString());
                    return(new HostConnectionData {
                        _state = ConnectionState.Invalid
                    });
                }
                return(data);
            }
Exemplo n.º 3
0
        public static int Main(string inParam)
        {
            if (inParam == null)
            {
                return(0);
            }
            var ptr        = (IntPtr)Int64.Parse(inParam, System.Globalization.NumberStyles.HexNumber);
            var connection = HostConnectionData.LoadData(ptr);

            if (connection.State != HostConnectionData.ConnectionState.Valid)
            {
                return((int)connection.State);
            }
            // Adjust host PID in case of WOW64 bypass and service help...
            connection.UnmanagedInfo.m_HostPID = connection.RemoteInfo.HostPID;

            try
            {
                // Prepare parameter array.
                var paramArray = new object[1 + connection.RemoteInfo.UserParams.Length];
                paramArray[0] = (RemoteHooking.IContext)connection.UnmanagedInfo;
                for (int i = 0; i < connection.RemoteInfo.UserParams.Length; i++)
                {
                    paramArray[i + 1] = connection.RemoteInfo.UserParams[i];
                }
                /// Load the user library and initialize the IEntryPoint.
                return(LoadUserLibrary(connection.RemoteInfo.UserLibrary, paramArray, connection.HelperInterface));
            }
            catch (Exception ExtInfo)
            {
                Config.Log.Warning(ExtInfo.ToString());
                return(-1);
            }
            finally
            {
                if (_connectedChannels.Contains(connection.RemoteInfo.ChannelName))
                {
                    _connectedChannels.Remove(connection.RemoteInfo.ChannelName);
                }
            }
        }
Exemplo n.º 4
0
        private void Test_ParseV2ConnectionData(
            string fileName = FileName,
            int expectedNumberOfConnections      = 1,
            string expectedRequestSignalName     = ExpectedRequestSignalName,
            string expectedReadySignalName       = ExpectedReadySignalName,
            string expectedProjectPath           = ExpectedProjectPath,
            string expectedHttpConnectionString  = ExpectedHttpConnectionString,
            string expectedHttpsConnectionString = ExpectedHttpsConnectionString,
            string expectedInjectScriptVerb      = ExpectedInjectScriptVerb,
            string expectedMappingDataVerb       = ExpectedMappingDataVerb,
            string expectedServerDataVerb        = ExpectedServerDataVerb)
        {
            // Act
            var result = HostConnectionUtil.ParseV2ConnectionData(fileName, SampleConnectionDataV2);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedNumberOfConnections, result.Count());

            if (expectedNumberOfConnections > 0)
            {
                Assert.False(result.Any(x => x == null), "List should not contain null connections");

                HostConnectionData connection = result.Where(x => x.ProjectPaths.First() == expectedProjectPath).SingleOrDefault();
                Assert.NotNull(connection);

                Assert.Equal(expectedRequestSignalName, connection.RequestSignalName);
                Assert.Equal(expectedReadySignalName, connection.ReadySignalName);

                Assert.NotNull(connection.ProjectPaths);
                Assert.Single(connection.ProjectPaths);
                Assert.Equal(expectedProjectPath, connection.ProjectPaths.First());

                Assert.Equal(expectedHttpConnectionString, connection.ConnectionString);
                Assert.Equal(expectedHttpsConnectionString, connection.SslConnectionString);
                Assert.Equal(expectedInjectScriptVerb, connection.InjectScriptVerb);
                Assert.Equal(expectedMappingDataVerb, connection.MappingDataVerb);
                Assert.Equal(expectedServerDataVerb, connection.ServerDataVerb);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Loads <see cref="HostConnectionData"/> from the <see cref="IntPtr"/> specified.
 /// </summary>
 /// <param name="unmanagedInfoPointer"></param>
 public static HostConnectionData LoadData(IntPtr unmanagedInfoPointer)
 {
     var data = new HostConnectionData
     {
         _state = ConnectionState.Valid,
         _unmanagedInfo = new REMOTE_ENTRY_INFO()
     };
     try
     {
         // Get the unmanaged data
         Marshal.PtrToStructure(unmanagedInfoPointer, data._unmanagedInfo);
         using (Stream passThruStream = new MemoryStream())
         {
             byte[] passThruBytes = new byte[data._unmanagedInfo.UserDataSize];
             BinaryFormatter format = new BinaryFormatter();
             // Workaround for deserialization when not using GAC registration
             format.Binder = new AllowAllAssemblyVersionsDeserializationBinder();
             Marshal.Copy(data._unmanagedInfo.UserData, passThruBytes, 0, data._unmanagedInfo.UserDataSize);
             passThruStream.Write(passThruBytes, 0, passThruBytes.Length);
             passThruStream.Position = 0;
             data._remoteInfo = (ManagedRemoteInfo)format.Deserialize(passThruStream);
         }
         // Connect the HelperServiceInterface
         data._helperInterface = RemoteHooking.IpcConnectClient<HelperServiceInterface>(data._remoteInfo.ChannelName);
         // Ensure that the connection is working...
         data._helperInterface.Ping();
         if (!_connectedChannels.Contains(data._remoteInfo.ChannelName))
         {
             _connectedChannels.Add(data._remoteInfo.ChannelName);
             return new HostConnectionData { _state = ConnectionState.NoChannel };
         }
     }
     catch (Exception ExtInfo)
     {
         Config.PrintError(ExtInfo.ToString());
         return new HostConnectionData { _state = ConnectionState.Invalid };
     }
     return data;
 }