コード例 #1
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            // write to console
            CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("Launching pipes...\r\n")));

            // save auth mode in application settings
            Properties.Settings.Default.authMode = authTabControl.SelectedTab.Name;

            // start service, authenticating to target machine as specified
            if (Properties.Settings.Default.authMode == "elevated")
            {
                paexecService.StartService(PAExecEXELocation.Text, TestComputer.Text, AdminUsername.Text,
                                           ElevatedAccountEXELocation.Text);
            }
            else
            {
                paexecService.StartService(PAExecEXELocation.Text, TestComputer.Text, AdminUsername.Text,
                                           userAuthTextbox.Text, passAuthTextbox.Text, ElevatedAccountEXELocation.Text);
            }

            // enable/disable buttons on gui
            KillButton.Enabled    = paexecService.IsRunning;
            ConnectButton.Enabled = !paexecService.IsRunning;
            ExecuteButton.Enabled = (CmdQueueListView.Items.Count > 0);
        }
コード例 #2
0
 private void StringFromClientHandler(object o, string e)
 {
     if (e.StartsWith("echo **HEARTBEAT"))
     {
         // do not print to cmd
     }
     else
     {
         CmdOutput.Invoke(new Action(() => CmdOutput.AppendText(e.ToString())));
     }
 }
コード例 #3
0
 private void KillButton_Click(object sender, EventArgs e)
 {
     // sends kill message to paexecService service
     paexecService.KillPipes();
     shouldSendCommands = false;
     CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("\r\nKilling pipes...\r\n")));
     CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("\r\nPipes killed.\r\n")));
     KillButton.Enabled    = false;
     ConnectButton.Enabled = true;
     ExecuteButton.Enabled = false;
 }
コード例 #4
0
        /// <summary>
        /// Begins the process of executing the commands that are "checked" in CmdQueueListView. <para/>
        /// Commands are sent to the remote computer via the PAExecService instance, and displayed in real time.
        /// </summary>
        private async void StartCmdQueue()
        {
            // because this is an asynchronous method, all access to the GUI thread (and its controls) must be through invokes.
            int numUnchecked = (int)CmdQueueListView.Invoke(new Func <int>(() => CmdQueueListView.Items.Count - CmdQueueListView.CheckedItems.Count));


            while (shouldSendCommands && CmdQueueListView.Items.Count > numUnchecked)
            {
                // is the item at top (index 0) of the queue checked?
                bool isChecked = (bool)CmdQueueListView.Invoke(new Func <bool>(() => CmdQueueListView.Items[0].Checked));

                if (isChecked)
                {
CheckIfConsoleAllowsInput:
                    string cmdText = (string)CmdOutput.Invoke(new Func <string>(() => CmdOutput.Text));
                    string endOfConsoleText = cmdText.Substring(cmdText.Length - Math.Min(10, cmdText.Length));
                    if (!endOfConsoleText.Contains('>'))
                    {
                        if (!shouldSendCommands)
                        {
                            break;
                        }                                   // stop endless loops if console dies
                        await Task.Delay(1000);

                        goto CheckIfConsoleAllowsInput; // check again after waiting
                    }

                    // send next command to the paexecService, remove from queue, then start over
                    string nextCmd = (string)CmdQueueListView.Invoke(new Func <string>(() => CmdQueueListView.Items[0].SubItems[1].Text.ToString()));
                    paexecService.WriteToClient(nextCmd.TrimEnd());
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.RemoveAt(0)));
                    await Task.Delay(500);

                    await Task.Run(() => StartCmdQueue());
                }
                else
                {
                    // if the command isn't checked, then move it to bottom of command queue
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.Add((ListViewItem)CmdQueueListView.Items[0].Clone())));
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.RemoveAt(0)));
                }
            }
            shouldSendCommands = false;
            StopExecutingButton.Invoke(new Action(() => StopExecutingButton.Enabled = false));
        }
コード例 #5
0
        private void MessageHandle(string msg)
        {
            if (_debugMode)
            {
                Debug.Log($"[debug mode]{msg}");
            }

            if (msg.Equals(ProcessProxy.CommandReturnFlag))
            {
                var msgs    = new Queue <string>();
                var command = _returnMsgs.Dequeue();

                if (_fullInfo)
                {
                    msgs.Enqueue(command);
                }

                while (_returnMsgs.Count > 0)
                {
                    var line = _returnMsgs.Dequeue();
                    if (!line.Contains(ProcessProxy.CommandReturnFlag))
                    {
                        msgs.Enqueue(line);
                    }
                }

                // 如果没有如何返回值,则默认添加一个"\n"换行符
                if (msgs.Count == 0)
                {
                    msgs.Enqueue("\n");
                }

                _currentCallback?.Invoke(new Queue <string>(msgs));
            }
            else
            {
                _returnMsgs.Enqueue(msg);
            }
        }