예제 #1
0
        public bool Disconnect(string Identifier)
        {
            IMessenger downstream = this.DownstreamMessengers.FirstOrDefault(DM => DM.Identifier.ToLower() == Identifier.ToLower());

            if (downstream != null)
            {
                downstream.Close();
                this.DownstreamMessengers.Remove(downstream);
                return(true);
            }
            return(false);
        }
예제 #2
0
        public bool Disconnect(string Identifier)
        {
            IMessenger downstream = this.DownstreamMessengers.FirstOrDefault(DM => DM.Identifier.ToLower() == Identifier.ToLower());

            if (downstream != null)
            {
                // Notify the child Grunt about the disconnect, else it will infinitely wait for reading the already closed pipe.
                downstream.Write(GruntTaskingType.Disconnect.ToString());
                downstream.Close();
                this.DownstreamMessengers.Remove(downstream);
                return(true);
            }
            return(false);
        }
예제 #3
0
        public bool Connect(string Hostname, string PipeName)
        {
            IMessenger olddownstream = this.DownstreamMessengers.FirstOrDefault(DM => DM.Hostname.ToLower() == (Hostname + ":" + PipeName).ToLower());

            if (olddownstream != null)
            {
                olddownstream.Close();
                this.DownstreamMessengers.Remove(olddownstream);
            }

            ClientSMBMessenger downstream = new ClientSMBMessenger(Hostname, PipeName);
            Thread             readThread = new Thread(() =>
            {
                while (downstream.ActivePipe)
                {
                    try
                    {
                        string read = downstream.Read();
                        if (read != null && String.IsNullOrEmpty(downstream.Identifier))
                        {
                            GruntEncryptedMessage message = this.Profile.ParseWriteFormat(read);
                            if (message.GUID.Length == 20)
                            {
                                downstream.Identifier = message.GUID.Substring(10);
                            }
                            else if (message.GUID.Length == 10)
                            {
                                downstream.Identifier = message.GUID;
                            }
                        }
                        this.UpstreamMessenger.Write(read);
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Thread Exception: " + e.Message + Environment.NewLine + e.StackTrace);
                    }
                    Thread.Sleep(100);
                }
            });

            downstream.ReadThread = readThread;
            downstream.ReadThread.Start();
            this.DownstreamMessengers.Add(downstream);
            return(true);
        }