From b9c6caa95d3e74c95ae835c907e35e57028dbb78 Mon Sep 17 00:00:00 2001 From: yankejustin Date: Mon, 1 Jun 2015 00:04:09 -0400 Subject: [PATCH 1/4] Multi-Cast Delegates Removed a great deal of incredibly-repetitive code by implementing multi-cast delegates to handle a changed setting. --- Server/Forms/FrmBuilder.Designer.cs | 47 +++++----- Server/Forms/FrmBuilder.cs | 129 +++------------------------- 2 files changed, 36 insertions(+), 140 deletions(-) diff --git a/Server/Forms/FrmBuilder.Designer.cs b/Server/Forms/FrmBuilder.Designer.cs index b88d0e3b..b6bac28c 100644 --- a/Server/Forms/FrmBuilder.Designer.cs +++ b/Server/Forms/FrmBuilder.Designer.cs @@ -131,7 +131,7 @@ this.txtDelay.Size = new System.Drawing.Size(66, 22); this.txtDelay.TabIndex = 8; this.txtDelay.Text = "5000"; - this.txtDelay.TextChanged += new System.EventHandler(this.txtDelay_TextChanged); + this.txtDelay.TextChanged += new System.EventHandler(this.HasChangedSetting); this.txtDelay.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtDelay_KeyPress); // // lblDelay @@ -161,7 +161,7 @@ this.txtPassword.PasswordChar = '•'; this.txtPassword.Size = new System.Drawing.Size(201, 22); this.txtPassword.TabIndex = 5; - this.txtPassword.TextChanged += new System.EventHandler(this.txtPassword_TextChanged); + this.txtPassword.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblPassword // @@ -179,7 +179,7 @@ this.txtPort.Name = "txtPort"; this.txtPort.Size = new System.Drawing.Size(66, 22); this.txtPort.TabIndex = 3; - this.txtPort.TextChanged += new System.EventHandler(this.txtPort_TextChanged); + this.txtPort.TextChanged += new System.EventHandler(this.HasChangedSetting); this.txtPort.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPort_KeyPress); // // lblPort @@ -197,7 +197,7 @@ this.txtHost.Name = "txtHost"; this.txtHost.Size = new System.Drawing.Size(201, 22); this.txtHost.TabIndex = 1; - this.txtHost.TextChanged += new System.EventHandler(this.txtHost_TextChanged); + this.txtHost.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblHost // @@ -271,7 +271,7 @@ this.rbSystem.Text = "System"; this.tooltip.SetToolTip(this.rbSystem, "Administrator Privileges are required to install the client in System."); this.rbSystem.UseVisualStyleBackColor = true; - this.rbSystem.CheckedChanged += new System.EventHandler(this.rbSystem_CheckedChanged); + this.rbSystem.CheckedChanged += new System.EventHandler(this.HasChangedSettingAndFilePath); // // rbProgramFiles // @@ -284,7 +284,7 @@ this.rbProgramFiles.Text = "Program Files"; this.tooltip.SetToolTip(this.rbProgramFiles, "Administrator Privileges are required to install the client in Program Files."); this.rbProgramFiles.UseVisualStyleBackColor = true; - this.rbProgramFiles.CheckedChanged += new System.EventHandler(this.rbProgramFiles_CheckedChanged); + this.rbProgramFiles.CheckedChanged += new System.EventHandler(this.HasChangedSettingAndFilePath); // // txtRegistryKeyName // @@ -292,7 +292,7 @@ this.txtRegistryKeyName.Name = "txtRegistryKeyName"; this.txtRegistryKeyName.Size = new System.Drawing.Size(201, 22); this.txtRegistryKeyName.TabIndex = 18; - this.txtRegistryKeyName.TextChanged += new System.EventHandler(this.txtRegistryKeyName_TextChanged); + this.txtRegistryKeyName.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblRegistryKeyName // @@ -323,7 +323,7 @@ this.chkHide.TabIndex = 15; this.chkHide.Text = "Hide File"; this.chkHide.UseVisualStyleBackColor = true; - this.chkHide.CheckedChanged += new System.EventHandler(this.chkHide_CheckedChanged); + this.chkHide.CheckedChanged += new System.EventHandler(this.HasChangedSetting); // // btnMutex // @@ -359,7 +359,7 @@ this.txtInstallsub.Name = "txtInstallsub"; this.txtInstallsub.Size = new System.Drawing.Size(201, 22); this.txtInstallsub.TabIndex = 12; - this.txtInstallsub.TextChanged += new System.EventHandler(this.txtInstallsub_TextChanged); + this.txtInstallsub.TextChanged += new System.EventHandler(this.HasChangedSettingAndFilePath); this.txtInstallsub.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtInstallsub_KeyPress); // // lblInstallsub @@ -391,7 +391,7 @@ this.rbAppdata.TabStop = true; this.rbAppdata.Text = "Application Data"; this.rbAppdata.UseVisualStyleBackColor = true; - this.rbAppdata.CheckedChanged += new System.EventHandler(this.rbAppdata_CheckedChanged); + this.rbAppdata.CheckedChanged += new System.EventHandler(this.HasChangedSettingAndFilePath); // // txtMutex // @@ -400,7 +400,7 @@ this.txtMutex.Name = "txtMutex"; this.txtMutex.Size = new System.Drawing.Size(201, 22); this.txtMutex.TabIndex = 1; - this.txtMutex.TextChanged += new System.EventHandler(this.txtMutex_TextChanged); + this.txtMutex.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblMutex // @@ -426,7 +426,7 @@ this.txtInstallname.Name = "txtInstallname"; this.txtInstallname.Size = new System.Drawing.Size(168, 22); this.txtInstallname.TabIndex = 5; - this.txtInstallname.TextChanged += new System.EventHandler(this.txtInstallname_TextChanged); + this.txtInstallname.TextChanged += new System.EventHandler(this.HasChangedSettingAndFilePath); this.txtInstallname.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtInstallname_KeyPress); // // lblInstallname @@ -459,7 +459,7 @@ this.chkIconChange.Text = "Change Icon"; this.tooltip.SetToolTip(this.chkIconChange, "Custom social engineering tactic to elevate Admin privileges."); this.chkIconChange.UseVisualStyleBackColor = true; - this.chkIconChange.CheckedChanged += new System.EventHandler(this.chkIconChange_CheckedChanged); + this.chkIconChange.CheckedChanged += new System.EventHandler(this.HasChangedSetting); // // chkElevation // @@ -471,7 +471,7 @@ this.chkElevation.Text = "Enable Admin Elevation"; this.tooltip.SetToolTip(this.chkElevation, "Custom social engineering tactic to elevate Admin privileges."); this.chkElevation.UseVisualStyleBackColor = true; - this.chkElevation.CheckedChanged += new System.EventHandler(this.chkElevation_CheckedChanged); + this.chkElevation.CheckedChanged += new System.EventHandler(this.HasChangedSetting); // // btnBuild // @@ -526,7 +526,7 @@ this.txtFileVersion.Name = "txtFileVersion"; this.txtFileVersion.Size = new System.Drawing.Size(201, 22); this.txtFileVersion.TabIndex = 16; - this.txtFileVersion.TextChanged += new System.EventHandler(this.txtFileVersion_TextChanged); + this.txtFileVersion.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblFileVersion // @@ -543,7 +543,7 @@ this.txtProductVersion.Name = "txtProductVersion"; this.txtProductVersion.Size = new System.Drawing.Size(201, 22); this.txtProductVersion.TabIndex = 14; - this.txtProductVersion.TextChanged += new System.EventHandler(this.txtProductVersion_TextChanged); + this.txtProductVersion.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblProductVersion // @@ -560,7 +560,7 @@ this.txtOriginalFilename.Name = "txtOriginalFilename"; this.txtOriginalFilename.Size = new System.Drawing.Size(201, 22); this.txtOriginalFilename.TabIndex = 12; - this.txtOriginalFilename.TextChanged += new System.EventHandler(this.txtOriginalFilename_TextChanged); + this.txtOriginalFilename.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblOriginalFilename // @@ -577,7 +577,7 @@ this.txtTrademarks.Name = "txtTrademarks"; this.txtTrademarks.Size = new System.Drawing.Size(201, 22); this.txtTrademarks.TabIndex = 10; - this.txtTrademarks.TextChanged += new System.EventHandler(this.txtTrademarks_TextChanged); + this.txtTrademarks.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblTrademarks // @@ -594,7 +594,7 @@ this.txtCopyright.Name = "txtCopyright"; this.txtCopyright.Size = new System.Drawing.Size(201, 22); this.txtCopyright.TabIndex = 8; - this.txtCopyright.TextChanged += new System.EventHandler(this.txtCopyright_TextChanged); + this.txtCopyright.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblCopyright // @@ -611,7 +611,7 @@ this.txtCompanyName.Name = "txtCompanyName"; this.txtCompanyName.Size = new System.Drawing.Size(201, 22); this.txtCompanyName.TabIndex = 6; - this.txtCompanyName.TextChanged += new System.EventHandler(this.txtCompanyName_TextChanged); + this.txtCompanyName.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblCompanyName // @@ -628,7 +628,7 @@ this.txtDescription.Name = "txtDescription"; this.txtDescription.Size = new System.Drawing.Size(201, 22); this.txtDescription.TabIndex = 4; - this.txtDescription.TextChanged += new System.EventHandler(this.txtDescription_TextChanged); + this.txtDescription.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblDescription // @@ -645,7 +645,7 @@ this.txtProductName.Name = "txtProductName"; this.txtProductName.Size = new System.Drawing.Size(201, 22); this.txtProductName.TabIndex = 2; - this.txtProductName.TextChanged += new System.EventHandler(this.txtProductName_TextChanged); + this.txtProductName.TextChanged += new System.EventHandler(this.HasChangedSetting); // // lblProductName // @@ -677,7 +677,7 @@ this.chkKeylogger.TabIndex = 2; this.chkKeylogger.Text = "Enable Keylogger"; this.chkKeylogger.UseVisualStyleBackColor = true; - this.chkKeylogger.CheckedChanged += new System.EventHandler(this.chkKeylogger_CheckedChanged); + this.chkKeylogger.CheckedChanged += new System.EventHandler(this.HasChangedSetting); // // FrmBuilder // @@ -696,7 +696,6 @@ this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "FrmBuilder"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "xRAT 2.0 - Builder"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmBuilder_FormClosing); this.Load += new System.EventHandler(this.FrmBuilder_Load); diff --git a/Server/Forms/FrmBuilder.cs b/Server/Forms/FrmBuilder.cs index 1a07aa0b..29f095ef 100644 --- a/Server/Forms/FrmBuilder.cs +++ b/Server/Forms/FrmBuilder.cs @@ -153,41 +153,6 @@ namespace xServer.Forms e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar)); } - private void txtInstallname_TextChanged(object sender, EventArgs e) - { - HasChanged(); - - RefreshExamplePath(); - } - - private void rbAppdata_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - - RefreshExamplePath(); - } - - private void rbProgramFiles_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - - RefreshExamplePath(); - } - - private void rbSystem_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - - RefreshExamplePath(); - } - - private void txtInstallsub_TextChanged(object sender, EventArgs e) - { - HasChanged(); - - RefreshExamplePath(); - } - private void btnMutex_Click(object sender, EventArgs e) { HasChanged(); @@ -368,94 +333,26 @@ namespace xServer.Forms return match.Success; } - private void txtHost_TextChanged(object sender, EventArgs e) + /// + /// Handles a basic change in setting. + /// + /// + /// + private void HasChangedSetting(object sender, EventArgs e) { HasChanged(); } - private void txtPort_TextChanged(object sender, EventArgs e) + /// + /// Handles a basic change in setting, also refreshing the example file path. + /// + /// + /// + private void HasChangedSettingAndFilePath(object sender, EventArgs e) { HasChanged(); - } - private void txtPassword_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtDelay_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtMutex_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void chkHide_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtRegistryKeyName_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void chkElevation_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void chkIconChange_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtProductName_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtDescription_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtCompanyName_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtCopyright_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtTrademarks_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtOriginalFilename_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtProductVersion_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void txtFileVersion_TextChanged(object sender, EventArgs e) - { - HasChanged(); - } - - private void chkKeylogger_CheckedChanged(object sender, EventArgs e) - { - HasChanged(); + RefreshExamplePath(); } } } \ No newline at end of file From 2083fcbc2ee8e6b1d90974473096994270887240 Mon Sep 17 00:00:00 2001 From: Justin Yanke Date: Mon, 1 Jun 2015 02:04:52 -0400 Subject: [PATCH 2/4] Start Position Fix --- Server/Forms/FrmBuilder.Designer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/Forms/FrmBuilder.Designer.cs b/Server/Forms/FrmBuilder.Designer.cs index b6bac28c..e82e8ab0 100644 --- a/Server/Forms/FrmBuilder.Designer.cs +++ b/Server/Forms/FrmBuilder.Designer.cs @@ -697,6 +697,7 @@ this.MinimizeBox = false; this.Name = "FrmBuilder"; this.Text = "xRAT 2.0 - Builder"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmBuilder_FormClosing); this.Load += new System.EventHandler(this.FrmBuilder_Load); this.groupConnection.ResumeLayout(false); @@ -773,4 +774,4 @@ private System.Windows.Forms.GroupBox groupAdditional; private System.Windows.Forms.CheckBox chkKeylogger; } -} \ No newline at end of file +} From 90f30caafbc677ca9df157fb113e0b3904a0ba10 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Mon, 1 Jun 2015 11:44:48 +0200 Subject: [PATCH 3/4] Improved Download Path Using now "User@PC" instead of "IP". --- Server/Core/Commands/ConnectionHandler.cs | 15 +++++++++++++-- Server/Core/Commands/MiscHandler.cs | 7 +++---- Server/Core/Commands/SurveillanceHandler.cs | 4 ++-- Server/Core/UserState.cs | 2 +- Server/Forms/FrmFileManager.cs | 7 ++----- Server/Forms/FrmKeylogger.cs | 6 ++++-- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Server/Core/Commands/ConnectionHandler.cs b/Server/Core/Commands/ConnectionHandler.cs index 5750e1a6..fa903686 100644 --- a/Server/Core/Commands/ConnectionHandler.cs +++ b/Server/Core/Commands/ConnectionHandler.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Linq; using System.Windows.Forms; using xServer.Core.Packets.ClientPackets; using xServer.Forms; @@ -27,6 +29,15 @@ namespace xServer.Core.Commands client.Value.Username = packet.Username; client.Value.PCName = packet.PCName; + string userAtPc = string.Format("{0}@{1}", client.Value.Username, client.Value.PCName); + char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray(); + bool containsIllegalChar = userAtPc.Count(c => illegal.Contains(c)) > 0; + + if (!containsIllegalChar) + client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + userAtPc + "\\"); + else + client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\"); + if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); @@ -36,8 +47,8 @@ namespace xServer.Core.Commands ListViewItem lvi = new ListViewItem(new string[] { " " + client.EndPoint.Address.ToString(), client.EndPoint.Port.ToString(), - string.Format("{0}@{1}", client.Value.Username, client.Value.PCName), client.Value.Version, - "Connected", "Active", country, client.Value.OperatingSystem, client.Value.AccountType, + userAtPc, client.Value.Version, "Connected", "Active", country, + client.Value.OperatingSystem, client.Value.AccountType }) { Tag = client, ImageIndex = packet.ImageIndex }; diff --git a/Server/Core/Commands/MiscHandler.cs b/Server/Core/Commands/MiscHandler.cs index 19056158..33f8c889 100644 --- a/Server/Core/Commands/MiscHandler.cs +++ b/Server/Core/Commands/MiscHandler.cs @@ -22,11 +22,10 @@ namespace xServer.Core.Commands public static void HandleDownloadFileResponse(Client client, DownloadFileResponse packet) { - string downloadPath = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString()); - if (!Directory.Exists(downloadPath)) - Directory.CreateDirectory(downloadPath); + if (!Directory.Exists(client.Value.DownloadDirectory)) + Directory.CreateDirectory(client.Value.DownloadDirectory); - downloadPath = Path.Combine(downloadPath, packet.Filename); + string downloadPath = Path.Combine(client.Value.DownloadDirectory, packet.Filename); bool Continue = true; if (packet.CurrentBlock == 0 && File.Exists(downloadPath)) diff --git a/Server/Core/Commands/SurveillanceHandler.cs b/Server/Core/Commands/SurveillanceHandler.cs index 01adfcd2..cca63393 100644 --- a/Server/Core/Commands/SurveillanceHandler.cs +++ b/Server/Core/Commands/SurveillanceHandler.cs @@ -124,7 +124,7 @@ namespace xServer.Core.Commands return; } - string downloadPath = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\Logs\\"); + string downloadPath = Path.Combine(client.Value.DownloadDirectory, "Logs\\"); if (!Directory.Exists(downloadPath)) Directory.CreateDirectory(downloadPath); @@ -137,7 +137,7 @@ namespace xServer.Core.Commands if (packet.Index == packet.FileCount && (packet.CurrentBlock + 1) == packet.MaxBlocks) { - FileInfo[] iFiles = new DirectoryInfo(Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\Logs\\")).GetFiles(); + FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.Value.DownloadDirectory, "Logs\\")).GetFiles(); if (iFiles.Length == 0) return; diff --git a/Server/Core/UserState.cs b/Server/Core/UserState.cs index 751ecb60..7d1fb952 100644 --- a/Server/Core/UserState.cs +++ b/Server/Core/UserState.cs @@ -17,6 +17,7 @@ namespace xServer.Core public string Id { get; set; } public string Username { get; set; } public string PCName { get; set; } + public string DownloadDirectory { get; set; } public FrmRemoteDesktop FrmRdp { get; set; } public FrmTaskManager FrmTm { get; set; } @@ -34,7 +35,6 @@ namespace xServer.Core public int LastMonitor { get; set; } public Bitmap LastDesktop { get; set; } public UnsafeStreamCodec StreamCodec { get; set; } - public ReverseProxyServer ProxyServer { get; set; } public UserState() diff --git a/Server/Forms/FrmFileManager.cs b/Server/Forms/FrmFileManager.cs index e9c431dc..c0e147e0 100644 --- a/Server/Forms/FrmFileManager.cs +++ b/Server/Forms/FrmFileManager.cs @@ -265,11 +265,8 @@ namespace xServer.Forms private void btnOpenDLFolder_Click(object sender, EventArgs e) { - string downloadPath = Path.Combine(Application.StartupPath, - "Clients\\" + _connectClient.EndPoint.Address.ToString()); - - if (Directory.Exists(downloadPath)) - Process.Start(downloadPath); + if (Directory.Exists(_connectClient.Value.DownloadDirectory)) + Process.Start(_connectClient.Value.DownloadDirectory); else MessageBox.Show("No files downloaded yet!", "xRAT 2.0 - File Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/Server/Forms/FrmKeylogger.cs b/Server/Forms/FrmKeylogger.cs index 3216cccc..ce53dc70 100644 --- a/Server/Forms/FrmKeylogger.cs +++ b/Server/Forms/FrmKeylogger.cs @@ -16,8 +16,7 @@ namespace xServer.Forms { _connectClient = c; _connectClient.Value.FrmKl = this; - _path = Path.Combine(Application.StartupPath, - "Clients\\" + _connectClient.EndPoint.Address.ToString() + "\\Logs\\"); + _path = Path.Combine(_connectClient.Value.DownloadDirectory, "Logs\\"); InitializeComponent(); _lvwColumnSorter = new ListViewColumnSorter(); @@ -32,7 +31,10 @@ namespace xServer.Forms _connectClient.EndPoint.Port.ToString()); if (!Directory.Exists(_path)) + { Directory.CreateDirectory(_path); + return; + } DirectoryInfo dicInfo = new DirectoryInfo(_path); From 836b77d13ee02f84df2221f2426e4f282afa7b99 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Mon, 1 Jun 2015 18:50:20 +0200 Subject: [PATCH 4/4] Improved check for illegal chars in path --- Server/Core/Commands/ConnectionHandler.cs | 9 +++------ Server/Core/Helper/Helper.cs | 8 ++++++++ Server/Forms/FrmAddToAutostart.cs | 11 +++++------ Server/Forms/FrmBuilder.cs | 13 +++++-------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Server/Core/Commands/ConnectionHandler.cs b/Server/Core/Commands/ConnectionHandler.cs index fa903686..a1800c82 100644 --- a/Server/Core/Commands/ConnectionHandler.cs +++ b/Server/Core/Commands/ConnectionHandler.cs @@ -30,13 +30,10 @@ namespace xServer.Core.Commands client.Value.PCName = packet.PCName; string userAtPc = string.Format("{0}@{1}", client.Value.Username, client.Value.PCName); - char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray(); - bool containsIllegalChar = userAtPc.Count(c => illegal.Contains(c)) > 0; - if (!containsIllegalChar) - client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + userAtPc + "\\"); - else - client.Value.DownloadDirectory = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\"); + client.Value.DownloadDirectory = (!Helper.Helper.CheckPathForIllegalChars(userAtPc)) ? + Path.Combine(Application.StartupPath, "Clients\\" + userAtPc + "\\") : + Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\"); if (!FrmMain.Instance.ListenServer.AllTimeConnectedClients.ContainsKey(client.Value.Id)) FrmMain.Instance.ListenServer.AllTimeConnectedClients.Add(client.Value.Id, DateTime.Now); diff --git a/Server/Core/Helper/Helper.cs b/Server/Core/Helper/Helper.cs index 9edaec8e..1d6b4e8f 100644 --- a/Server/Core/Helper/Helper.cs +++ b/Server/Core/Helper/Helper.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Linq; using System.Text; namespace xServer.Core.Helper @@ -8,6 +10,12 @@ namespace xServer.Core.Helper private const string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; private static readonly Random _rnd = new Random(Environment.TickCount); private static readonly string[] _sizes = {"B", "KB", "MB", "GB"}; + private static readonly char[] _illegalChars = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray(); + + public static bool CheckPathForIllegalChars(string path) + { + return path.Any(c => _illegalChars.Contains(c)); + } public static string GetRandomFilename(int length, string extension) { diff --git a/Server/Forms/FrmAddToAutostart.cs b/Server/Forms/FrmAddToAutostart.cs index ce7eebbc..f8947866 100644 --- a/Server/Forms/FrmAddToAutostart.cs +++ b/Server/Forms/FrmAddToAutostart.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Windows.Forms; +using xServer.Core.Helper; using xServer.Core.Misc; namespace xServer.Forms @@ -52,16 +53,14 @@ namespace xServer.Forms private void txtName_KeyPress(object sender, KeyPressEventArgs e) { - string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()); - if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar)) - e.Handled = true; + e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) && + !char.IsControl(e.KeyChar)); } private void txtPath_KeyPress(object sender, KeyPressEventArgs e) { - string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()); - if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar)) - e.Handled = true; + e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) && + !char.IsControl(e.KeyChar)); } } } \ No newline at end of file diff --git a/Server/Forms/FrmBuilder.cs b/Server/Forms/FrmBuilder.cs index 29f095ef..ba35e40c 100644 --- a/Server/Forms/FrmBuilder.cs +++ b/Server/Forms/FrmBuilder.cs @@ -130,8 +130,7 @@ namespace xServer.Forms private void txtPort_KeyPress(object sender, KeyPressEventArgs e) { - if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) - e.Handled = true; + e.Handled = (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)); } private void txtDelay_KeyPress(object sender, KeyPressEventArgs e) @@ -141,16 +140,14 @@ namespace xServer.Forms private void txtInstallname_KeyPress(object sender, KeyPressEventArgs e) { - char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray(); - - e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar)); + e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) && + !char.IsControl(e.KeyChar)); } private void txtInstallsub_KeyPress(object sender, KeyPressEventArgs e) { - char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray(); - - e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar)); + e.Handled = ((e.KeyChar == '\\' || Helper.CheckPathForIllegalChars(e.KeyChar.ToString())) && + !char.IsControl(e.KeyChar)); } private void btnMutex_Click(object sender, EventArgs e)