Windows.COPYDATASTRUCT GetEncryptedMasterKeyTransmission() { byte[] encryptedMessage; byte[] iv; using (SecureBytesWrapper sbwKey = new SecureBytesWrapper(App.Settings.PasswordMasterKey, true)) { Encrypt(sbwKey.Bytes, out encryptedMessage, out iv); } Windows.COPYDATASTRUCT cds = new Windows.COPYDATASTRUCT(); cds.cbData = sizeof(int) + iv.Length + encryptedMessage.Length; byte[] combinedMessage = new byte[cds.cbData]; byte[] lengthBytes = BitConverter.GetBytes(iv.Length); Buffer.BlockCopy(lengthBytes, 0, combinedMessage, 0, lengthBytes.Length); Buffer.BlockCopy(iv, 0, combinedMessage, lengthBytes.Length, iv.Length); Buffer.BlockCopy(encryptedMessage, 0, combinedMessage, lengthBytes.Length + iv.Length, encryptedMessage.Length); cds.lpData = Marshal.AllocHGlobal(cds.cbData); Marshal.Copy(combinedMessage, 0, cds.lpData, combinedMessage.Length); cds.dwData = new IntPtr(11); // caller needs to Marshal.FreeHGlobal(cds.lpData); return(cds); }
public void ReceiveEncryptedMasterKeyTransmission(Windows.COPYDATASTRUCT cds) { byte[] combinedMessage = new byte[cds.cbData]; Marshal.Copy(cds.lpData, combinedMessage, 0, cds.cbData); int ivLength = BitConverter.ToInt32(combinedMessage, 0); // validate length... if (ivLength > cds.cbData) { // throw exception .. ? throw new ApplicationException("Master Key transmission failed: Initialization Vector received incorrectly"); } byte[] iv = new byte[ivLength]; Buffer.BlockCopy(combinedMessage, sizeof(int), iv, 0, ivLength); byte[] encryptedMessage = new byte[cds.cbData - (ivLength + sizeof(int))]; Buffer.BlockCopy(combinedMessage, sizeof(int) + ivLength, encryptedMessage, 0, encryptedMessage.Length); using (SecureBytesWrapper sbw = new SecureBytesWrapper()) { Decrypt(encryptedMessage, iv, sbw); if (!App.Settings.TryPasswordMasterKey(sbw.Bytes)) { throw new ApplicationException("Master Key transmission failed: Master Key received incorrectly"); } } }
public void ReceivePublicKeyTransmission(Windows.COPYDATASTRUCT cds) { byte[] remotePublicKey = new byte[cds.cbData]; Marshal.Copy(cds.lpData, remotePublicKey, 0, cds.cbData); SetRemotePublicKey(remotePublicKey); }
public void TransmitEncryptedMasterKey(Windows.MainWindow localWindow) { Windows.COPYDATASTRUCT cds = GetEncryptedMasterKeyTransmission(); HwndSource source = PresentationSource.FromVisual(localWindow) as HwndSource; Windows.MainWindow.SendMessage(this.RemoteWindow, Windows.MainWindow.WM_COPYDATA, source.Handle, ref cds); Marshal.FreeHGlobal(cds.lpData); }
/// <summary> /// Transmit the command-line to an already-running Master instance, if one is available /// </summary> /// <returns></returns> public bool TransmitCommandLine() { // check if it's already running. System.Diagnostics.Process masterInstance = GetMasterInstance(false); if (masterInstance != null) { string joinedCommandLine = string.Empty; foreach (string s in CommandLine) { // if it's another process, don't exit switch (s.ToLowerInvariant()) { case "null": // ignore... break; case "-exit": // the -exit is intended for THIS process, not the other one. break; case "-multiinstance": return(false); } if (!s.Equals("-exit", StringComparison.InvariantCultureIgnoreCase)) { joinedCommandLine += "\"" + s.Replace("\"", "\\\"") + "\" "; } } joinedCommandLine.TrimEnd(); byte[] buff = Encoding.Unicode.GetBytes(joinedCommandLine); Windows.COPYDATASTRUCT cds = new Windows.COPYDATASTRUCT(); cds.cbData = buff.Length; cds.lpData = Marshal.AllocHGlobal(buff.Length); Marshal.Copy(buff, 0, cds.lpData, buff.Length); cds.dwData = IntPtr.Zero; cds.cbData = buff.Length; var ret = ISBoxerEVELauncher.Windows.MainWindow.SendMessage(masterInstance.MainWindowHandle, ISBoxerEVELauncher.Windows.MainWindow.WM_COPYDATA, IntPtr.Zero, ref cds); Marshal.FreeHGlobal(cds.lpData); Shutdown(); return(true); } return(false); }
Windows.COPYDATASTRUCT GetPublicKeyTransmission(bool isRequest) { Windows.COPYDATASTRUCT cds = new Windows.COPYDATASTRUCT(); cds.cbData = LocalPublicKey.Bytes.Length; cds.lpData = Marshal.AllocHGlobal(cds.cbData); Marshal.Copy(LocalPublicKey.Bytes, 0, cds.lpData, LocalPublicKey.Bytes.Length); if (isRequest) { cds.dwData = new IntPtr(10); } else { cds.dwData = new IntPtr(12); } // caller needs to Marshal.FreeHGlobal(cds.lpData); return(cds); }
public static bool ReceiveTransmission(Windows.MainWindow window, IntPtr remoteWindow, System.Diagnostics.Process remoteProcess, Windows.COPYDATASTRUCT cds) { Session session = Sessions.FirstOrDefault(q => q.RemoteWindow == remoteWindow && q.Process.Id == remoteProcess.Id); if (session == null) { session = new Session(remoteWindow, remoteProcess); Sessions.Add(session); } switch ((long)cds.dwData) { case 10: if (!App.Settings.HasPasswordMasterKey) { return(false); } session.ReceivePublicKeyTransmission(cds); session.TransmitPublicKey(window, false); session.TransmitEncryptedMasterKey(window); return(true); case 11: session.ReceiveEncryptedMasterKeyTransmission(cds); return(true); case 12: session.ReceivePublicKeyTransmission(cds); return(true); } return(false); }
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // Handle messages... switch (msg) { /* * case WM_REQUESTMASTERKEY: * { * handled = true; * // lParam should be a window handle to transmit back to * int processId = 0; * GetWindowThreadProcessId(lParam, out processId); * * System.Diagnostics.Process newInstance = System.Diagnostics.Process.GetProcessById(processId); * // ensure this is the same app, otherwise we might be leaking ... * if (newInstance==null || newInstance.MainModule.FileName!=System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) * { * // different thing, sorry. * return IntPtr.Zero; * } * * // do we even have a master key? * if (!App.Settings.HasPasswordMasterKey) * { * // ... no... * return IntPtr.Zero; * } * * // ok i guess we're good. start by sending DH public key * KeyTransmitter.TransmitPublicKey(lParam, newInstance); * return new IntPtr(1); * } * break; * /**/ case WM_COPYDATA: handled = true; COPYDATASTRUCT cds = (COPYDATASTRUCT)Marshal.PtrToStructure(lParam, typeof(COPYDATASTRUCT)); switch ((long)cds.dwData) { case 0: byte[] buff = new byte[cds.cbData]; Marshal.Copy(cds.lpData, buff, 0, cds.cbData); string receivedString = Encoding.Unicode.GetString(buff, 0, cds.cbData); //MessageBox.Show("Processing " + receivedString); App.ProcessCommandLine(receivedString); break; case 10: case 11: case 12: { int processId = 0; GetWindowThreadProcessId(wParam, out processId); if (processId == 0) { return(IntPtr.Zero); } System.Diagnostics.Process newInstance = System.Diagnostics.Process.GetProcessById(processId); // ensure this is the same app, otherwise we might be leaking ... try { if (newInstance == null || newInstance.MainModule.FileName != System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) { // different thing, sorry. return(IntPtr.Zero); } } catch (System.ComponentModel.Win32Exception we) { if (we.NativeErrorCode == 5) { // other instance is Administrator and we are not; cannot confirm main module return(IntPtr.Zero); } MessageBox.Show("Error=" + we.NativeErrorCode); throw; } /**/ KeyTransmitter.ReceiveTransmission(this, wParam, newInstance, cds); } break; } break; } return(IntPtr.Zero); } public string VersionString { get { return(App.AppVersion); } } void Settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { OnPropertyChanged(e.PropertyName); } public ObservableCollection <InnerSpaceGameProfile> GameProfiles { get { return(App.GameProfiles); } } public ObservableCollection <EVEAccount> Accounts { get { return(App.Settings.Accounts); } } public InnerSpaceGameProfile TranquilityGameProfile { get { return(App.Settings.TranquilityGameProfile); } set { App.Settings.TranquilityGameProfile = value; App.Settings.Store(); } } public InnerSpaceGameProfile SingularityGameProfile { get { return(App.Settings.SingularityGameProfile); } set { App.Settings.SingularityGameProfile = value; App.Settings.Store(); } } public string EVESharedCachePath { get { return(App.Settings.EVESharedCachePath); } set { App.Settings.EVESharedCachePath = value; App.Settings.Store(); } } public bool UseSingularity { get { return(App.Settings.UseSingularity); } set { App.Settings.UseSingularity = value; App.Settings.Store(); } } public bool?UseDirectX9 { get { switch (App.Settings.UseDirectXVersion) { case DirectXVersion.Default: return(null); case DirectXVersion.dx11: return(false); case DirectXVersion.dx9: return(true); } return(null); } set { if (!value.HasValue) { App.Settings.UseDirectXVersion = DirectXVersion.Default; } else { if (value.Value) { App.Settings.UseDirectXVersion = DirectXVersion.dx9; } else { App.Settings.UseDirectXVersion = DirectXVersion.dx11; } } App.Settings.Store(); } } public float LaunchDelay { get { return(App.Settings.LaunchDelay); } set { App.Settings.LaunchDelay = value; App.Settings.Store(); } } private void buttonBrowse_Click(object sender, RoutedEventArgs e) { // Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog() { InitialDirectory = EVESharedCachePath, CheckPathExists=true, RestoreDirectory=true, }; var dialog = new System.Windows.Forms.FolderBrowserDialog() { SelectedPath = EVESharedCachePath, ShowNewFolderButton = false, Description = "Please select the EVE SharedCache folder, typically C:\\ProgramData\\EVE\\CCP\\SharedCache" }; System.Windows.Forms.DialogResult result = dialog.ShowDialog(); switch (result) { case System.Windows.Forms.DialogResult.OK: EVESharedCachePath = dialog.SelectedPath; break; } } private void buttonCreateTranquility_Click(object sender, RoutedEventArgs e) { string filepath = App.Settings.GetTranquilityPath(); if (string.IsNullOrEmpty(filepath)) { MessageBox.Show("Please configure Path to EVE's SharedCache first!"); return; } CreateGameProfileWindow cgpw = new CreateGameProfileWindow(false, "EVE Online", "Tranquility (Skip Launcher)"); cgpw.ShowDialog(); if (cgpw.DialogResult.HasValue && cgpw.DialogResult.Value) { App.AddGame(cgpw.Game, cgpw.GameProfile, System.IO.Path.Combine(filepath, "bin"), "exefile.exe", "/noconsole"); App.ReloadGameConfiguration(); App.Settings.TranquilityGameProfile = App.FindGlobalGameProfile(new InnerSpaceGameProfile() { Game = cgpw.Game, GameProfile = cgpw.GameProfile }); } } private void buttonCreateSingularity_Click(object sender, RoutedEventArgs e) { string filepath = App.Settings.GetSingularityPath(); if (string.IsNullOrEmpty(filepath)) { MessageBox.Show("Please configure Path to EVE's SharedCache first!"); return; } CreateGameProfileWindow cgpw = new CreateGameProfileWindow(true, "EVE Online", "Singularity (Skip Launcher)"); cgpw.ShowDialog(); if (cgpw.DialogResult.HasValue && cgpw.DialogResult.Value) { App.AddGame(cgpw.Game, cgpw.GameProfile, System.IO.Path.Combine(filepath, "bin"), "exefile.exe", "/noconsole /server:Singularity"); App.ReloadGameConfiguration(); App.Settings.SingularityGameProfile = App.FindGlobalGameProfile(new InnerSpaceGameProfile() { Game = cgpw.Game, GameProfile = cgpw.GameProfile }); } } private void buttonAddAccount_Click(object sender, RoutedEventArgs e) { EVEAccount newAccount = new EVEAccount(); EVELogin el = new EVELogin(newAccount, false); el.ShowDialog(); if (el.DialogResult.HasValue && el.DialogResult.Value) { // user clicked Go // check password... // string refreshToken; // switch (newAccount.GetRefreshToken(false, out refreshToken)) EVEAccount.Token token; EVEAccount.LoginResult lr = newAccount.GetAccessToken(false, out token); switch (lr) { case EVEAccount.LoginResult.Success: break; case EVEAccount.LoginResult.InvalidUsernameOrPassword: { MessageBox.Show("Invalid Username or Password. Account NOT added."); return; } case EVEAccount.LoginResult.Timeout: { MessageBox.Show("Timed out attempting to log in. Account NOT added."); return; } case EVEAccount.LoginResult.InvalidCharacterChallenge: { MessageBox.Show("Invalid Character Name entered, or Invalid Username or Password. Account NOT added."); return; } case EVEAccount.LoginResult.EmailVerificationRequired: // message already provided return; default: { MessageBox.Show("Failed to log in: " + lr.ToString() + ". Account NOT added."); return; } break; } EVEAccount existingAccount = App.Settings.Accounts.FirstOrDefault(q => q.Username.Equals(newAccount.Username, StringComparison.InvariantCultureIgnoreCase)); if (existingAccount != null) { // update existing account? existingAccount.Username = newAccount.Username; existingAccount.SecurePassword = newAccount.SecurePassword.Copy(); existingAccount.EncryptPassword(); if (newAccount.SecureCharacterName != null && newAccount.SecureCharacterName.Length > 0) { existingAccount.SecureCharacterName = newAccount.SecureCharacterName.Copy(); existingAccount.EncryptCharacterName(); } newAccount.Dispose(); newAccount = existingAccount; } else { // new account App.Settings.Accounts.Add(newAccount); } App.Settings.Store(); } } private void checkSavePasswords_Click(object sender, RoutedEventArgs e) { e.Handled = true; if (checkSavePasswords.IsChecked.HasValue && checkSavePasswords.IsChecked.Value) { SetMasterKeyWindow smkw = new SetMasterKeyWindow(); smkw.ShowDialog(); checkSavePasswords.IsChecked = App.Settings.HasPasswordMasterKey; } else { // clear master key if (App.Settings.UseMasterKey) { switch (MessageBox.Show("By un-checking this box, this launcher will immediately clear out all *saved* passwords. Do you wish to continue?", "Wait! You are about to lose any saved passwords!", MessageBoxButton.YesNo)) { case MessageBoxResult.Yes: App.Settings.ClearPasswordMasterKey(); break; default: checkSavePasswords.IsChecked = true; return; } } } } private void buttonLaunchNonIS_Click(object sender, RoutedEventArgs e) { List <EVEAccount> launchAccounts = new List <EVEAccount>(); foreach (EVEAccount a in listAccounts.SelectedItems) { launchAccounts.Add(a); } if (launchAccounts.Count == 0) { return; } InnerSpaceGameProfile gp; if (string.IsNullOrWhiteSpace(App.Settings.EVESharedCachePath)) { MessageBox.Show("Please set the EVE SharedCache path first!"); return; } Windows.LaunchProgressWindow lpw = new LaunchProgressWindow(launchAccounts, new Launchers.DirectLauncher(App.Settings.EVESharedCachePath, App.Settings.UseDirectXVersion, App.Settings.UseSingularity)); lpw.ShowDialog(); } private void buttonLaunchIS_Click(object sender, RoutedEventArgs e) { List <EVEAccount> launchAccounts = new List <EVEAccount>(); foreach (EVEAccount a in listAccounts.SelectedItems) { launchAccounts.Add(a); } if (launchAccounts.Count == 0) { return; } InnerSpaceGameProfile gp; if (App.Settings.UseSingularity) { gp = App.Settings.SingularityGameProfile; } else { gp = App.Settings.TranquilityGameProfile; } if (gp == null || string.IsNullOrEmpty(gp.Game) || string.IsNullOrEmpty(gp.GameProfile)) { MessageBox.Show("Please select a Game Profile first!"); return; } Windows.LaunchProgressWindow lpw = new LaunchProgressWindow(launchAccounts, new Launchers.InnerSpaceLauncher(gp, App.Settings.UseDirectXVersion, App.Settings.UseSingularity)); lpw.ShowDialog(); /* * foreach(EVEAccount a in launchAccounts) * { * EVEAccount.LoginResult lr = a.Launch(gp.Game, gp.GameProfile, App.Settings.UseSingularity, App.Settings.UseDirectXVersion); * switch(lr) * { * case EVEAccount.LoginResult.Success: * listAccounts.SelectedItems.Remove(a); * break; * case EVEAccount.LoginResult.InvalidUsernameOrPassword: * { * MessageBox.Show("Invalid Username or Password. Account NOT launched."); * return; * } * case EVEAccount.LoginResult.Timeout: * { * MessageBox.Show("Timed out attempting to log in. Account NOT launched."); * return; * } * case EVEAccount.LoginResult.InvalidCharacterChallenge: * { * MessageBox.Show("Invalid Character Name entered, or Invalid Username or Password. Account NOT launched."); * return; * } * default: * { * MessageBox.Show("Failed to log in: " + lr.ToString() + ". Account NOT launched."); * return; * } * * } * } */ } private void buttonDeleteAccount_Click(object sender, RoutedEventArgs e) { List <EVEAccount> deleteAccounts = new List <EVEAccount>(); foreach (EVEAccount a in listAccounts.SelectedItems) { deleteAccounts.Add(a); } if (deleteAccounts.Count == 0) { return; } if (deleteAccounts.Count == 1) { switch (MessageBox.Show("Are you sure you want to delete '" + deleteAccounts[0].Username + "'?", "Wait! You are about to lose an account!", MessageBoxButton.YesNo)) { case MessageBoxResult.Yes: break; default: return; } } else { switch (MessageBox.Show("Are you sure you want to delete " + deleteAccounts.Count + " accounts?", "Wait! You are about to lose some accounts!", MessageBoxButton.YesNo)) { case MessageBoxResult.Yes: break; default: return; } } foreach (EVEAccount toDelete in deleteAccounts) { Accounts.Remove(toDelete); toDelete.Dispose(); } }