示例#1
0
        /// <summary>
        ///     Read the saved Xml to load the hotkey
        /// </summary>
        /// <param name="reader">XmlReader</param>
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();

            if (reader.IsEmptyElement)
            {
                reader.Read();
                return;
            }

            reader.Read();
            while (reader.EOF == false)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "modifiers":
                        Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(
                            Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
                        break;

                    case "key":
                        Key = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(
                            Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
                        break;

                    case "action":
                        Action = (HotKeyActions)Enum.Parse(typeof(HotKeyActions),
                                                           reader.ReadElementContentAsString(), true);
                        break;

                    case "window":
                        Window = reader.ReadElementContentAsString();
                        break;

                    case "advanced":
                        Advanced = reader.ReadElementContentAsString();
                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                    break;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Create a new HotKeySequence from a loaded string
 /// </summary>
 /// <param name="data"></param>
 public HoyKeySequence(string data)
 {
     if (string.IsNullOrEmpty(data) == false)
     {
         Match match = Regex.Match(data, @"([0-9a-fA-F]{8})([0-9a-fA-F]{4})\t([^\t]*)\t(Y|N)(.*)", RegexOptions.Multiline);
         if (match.Success == true)
         {
             Modifiers   = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(match.Groups[1].Value), 0);
             HotKey      = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(match.Groups[2].Value), 0);
             WindowTitle = match.Groups[3].Value;
             Advanced    = (match.Groups[4].Value == "Y");
             if (Advanced == true)
             {
                 AdvancedScript = match.Groups[5].Value;
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Fired when the key selection is changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void keyCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            // clear the modifiers if we have cleared the key
            WinAPI.VirtualKeyCode key = (keyCombo.SelectedItem as KeyItem != null ? ((KeyItem)keyCombo.SelectedItem).Key : default(WinAPI.VirtualKeyCode));
            if (key == 0)
            {
                shiftToggle.Checked = false;
                ctrlToggle.Checked  = false;
                altToggle.Checked   = false;

                this.notifyRadioButton.Enabled   = false;
                this.injectRadioButton.Enabled   = false;
                this.pasteRadioButton.Enabled    = false;
                this.advancedRadioButton.Enabled = false;
            }
            else
            {
                this.notifyRadioButton.Enabled   = true;
                this.injectRadioButton.Enabled   = true;
                this.pasteRadioButton.Enabled    = true;
                this.advancedRadioButton.Enabled = true;
            }
        }
示例#4
0
			/// <summary>
			/// Create the new item
			/// </summary>
			/// <param name="key"></param>
			public KeyItem(WinAPI.VirtualKeyCode key)
			{
				Key = key;
			}
示例#5
0
 /// <summary>
 /// Create the new item
 /// </summary>
 /// <param name="key"></param>
 public KeyItem(WinAPI.VirtualKeyCode key)
 {
     Key = key;
 }
示例#6
0
        /// <summary>
        /// Click the OK button to save the keys
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okButton_Click(object sender, EventArgs e)
        {
            WinAPI.VirtualKeyCode key = (keyCombo.SelectedItem as KeyItem != null ? ((KeyItem)keyCombo.SelectedItem).Key : default(WinAPI.VirtualKeyCode));
            if (key == 0)
            {
                this.Hotkey = null;
            }
            else if (this.Hotkey == null)
            {
                this.Hotkey = new HotKey();
            }

            if (this.Hotkey != null)
            {
                WinAPI.KeyModifiers modifiers = WinAPI.KeyModifiers.None;
                if (shiftToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Shift;
                }
                if (ctrlToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Control;
                }
                if (altToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Alt;
                }

                // check it is available if this is a different hotkey
                if ((key != this.Hotkey.Key || modifiers != this.Hotkey.Modifiers) && KeyboardHook.IsHotkeyAvailable(this, (Keys)key, modifiers) == false)
                {
                    WinAuthForm.ErrorDialog(this, strings.HotKeyNotAvailable);
                    this.DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }

                this.Hotkey.Key       = key;
                this.Hotkey.Modifiers = modifiers;

                if (notifyRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Notify;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = null;
                }
                else if (injectRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Inject;
                    this.Hotkey.Window   = this.injectTextbox.Text;
                    this.Hotkey.Advanced = null;
                }
                else if (pasteRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Copy;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = null;
                }
                else if (advancedRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Advanced;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = this.advancedTextbox.Text;
                }
            }
        }
示例#7
0
 /// <summary>
 /// Create a new HotKeySequence from a loaded string
 /// </summary>
 /// <param name="data"></param>
 public HoyKeySequence(string data)
 {
     if (string.IsNullOrEmpty(data) == false)
     {
         Match match = Regex.Match(data, @"([0-9a-fA-F]{8})([0-9a-fA-F]{4})\t([^\t]*)\t(Y|N)(.*)", RegexOptions.Multiline);
         if (match.Success == true)
         {
             Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(match.Groups[1].Value), 0);
             HotKey = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(match.Groups[2].Value), 0);
             WindowTitle = match.Groups[3].Value;
             Advanced = (match.Groups[4].Value == "Y");
             if (Advanced == true)
             {
                 AdvancedScript = match.Groups[5].Value;
             }
         }
     }
 }
示例#8
0
        /// <summary>
        /// Create a new HotKeySequence from a loaded string
        /// </summary>
        /// <param name="data">XmlNode from config</param>
        public HoyKeySequence(XmlNode autoLoginNode, string password, decimal version)
        {
            bool boolVal = false;
            XmlNode node = autoLoginNode.SelectSingleNode("modifiers");
            if (node != null && node.InnerText.Length != 0)
            {
                Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(node.InnerText), 0);
            }
            node = autoLoginNode.SelectSingleNode("hotkey");
            if (node != null && node.InnerText.Length != 0)
            {
                HotKey = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(node.InnerText), 0);
            }
            node = autoLoginNode.SelectSingleNode("windowtitle");
            if (node != null && node.InnerText.Length != 0)
            {
                WindowTitle = node.InnerText;
            }
            node = autoLoginNode.SelectSingleNode("windowtitleregex");
            if (node != null && bool.TryParse(node.InnerText, out boolVal) == true)
            {
                WindowTitleRegex = boolVal;
            }
            node = autoLoginNode.SelectSingleNode("processname");
            if (node != null && node.InnerText.Length != 0)
            {
                ProcessName = node.InnerText;
            }
            node = autoLoginNode.SelectSingleNode("advanced");
            if (node != null && bool.TryParse(node.InnerText, out boolVal) == true)
            {
                Advanced = boolVal;
            }
            node = autoLoginNode.SelectSingleNode("script");
            if (node != null && node.InnerText.Length != 0)
            {
                string data = node.InnerText;

                XmlAttribute attr = node.Attributes["encrypted"];
                if (attr != null && attr.InnerText.Length != 0)
                {
                    char[] encTypes = attr.InnerText.ToCharArray();
                    // we read the string in reverse order (the order they were encrypted)
                    for (int i = encTypes.Length - 1; i >= 0; i--)
                    {
                        char encryptedType = encTypes[i];
                        switch (encryptedType)
                        {
                            case 'u':
                                {
                                    // we are going to decrypt with the Windows User account key
                                    byte[] cipher = Authenticator.StringToByteArray(data);
                                    byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
                                    data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                                    break;
                                }
                            case 'm':
                                {
                                    // we are going to decrypt with the Windows local machine key
                                    byte[] cipher = Authenticator.StringToByteArray(data);
                                    byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.LocalMachine);
                                    data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                                    break;
                                }
                            case 'y':
                                {
                                    // we use an explicit password to encrypt data
                                    if (string.IsNullOrEmpty(password) == true)
                                    {
                                        throw new EncrpytedSecretDataException();
                                    }
                                    data = Authenticator.Decrypt(data, password, (version >= (decimal)1.7)); // changed encrypted in 1.7
                                    byte[] plain = Authenticator.StringToByteArray(data);
                                    data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                                    break;
                                }
                            default:
                                break;
                        }
                    }
                }
                AdvancedScript = data;
            }
        }
示例#9
0
		/// <summary>
		/// Read the saved Xml to load the hotkey
		/// </summary>
		/// <param name="reader">XmlReader</param>
    public void ReadXml(XmlReader reader)
    {
      reader.MoveToContent();

      if (reader.IsEmptyElement)
      {
        reader.Read();
        return;
      }

      reader.Read();
      while (reader.EOF == false)
      {
        if (reader.IsStartElement())
        {
          switch (reader.Name)
          {
            case "modifiers":
      				Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
              break;

            case "key":
              Key = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
              break;

						case "action":
							Action = (HotKeyActions)Enum.Parse(typeof(HotKeyActions), reader.ReadElementContentAsString(), true);
							break;

						case "window":
							Window = reader.ReadElementContentAsString();
							break;

						case "advanced":
							Advanced = reader.ReadElementContentAsString();
							break;

						default:
              reader.Skip();
              break;
          }
        }
        else
        {
          reader.Read();
          break;
        }
      }
    }
示例#10
0
        public void ReadXml(XmlReader reader, string password = null)
        {
            reader.MoveToContent();

            if (reader.IsEmptyElement)
            {
                reader.Read();
                return;
            }

            reader.Read();
            while (reader.EOF == false)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "modifiers":
                        Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
                        break;

                    case "hotkey":
                        HotKey = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
                        break;

                    case "windowtitle":
                        WindowTitle = reader.ReadElementContentAsString();
                        break;

                    case "windowtitleregex":
                        WindowTitleRegex = reader.ReadElementContentAsBoolean();
                        break;

                    case "processname":
                        ProcessName = reader.ReadElementContentAsString();
                        break;

                    case "advanced":
                        Advanced = reader.ReadElementContentAsBoolean();
                        break;

                    case "script":
                        string encrypted = reader.GetAttribute("encrypted");
                        string data      = reader.ReadElementContentAsString();

                        if (string.IsNullOrEmpty(encrypted) == false)
                        {
                            Authenticator.PasswordTypes passwordType = Authenticator.DecodePasswordTypes(encrypted);
                            data = Authenticator.DecryptSequence(data, passwordType, password, true);
                            //byte[] plain = Authenticator.StringToByteArray(data);
                            //data = Encoding.UTF8.GetString(plain, 0, plain.Length);

/*
 *              char[] encTypes = encrypted.ToCharArray();
 *              // we read the string in reverse order (the order they were encrypted)
 *              for (int i = encTypes.Length - 1; i >= 0; i--)
 *              {
 *                char encryptedType = encTypes[i];
 *                switch (encryptedType)
 *                {
 *                  case 'u':
 *                    {
 *                      // we are going to decrypt with the Windows User account key
 *                      byte[] cipher = Authenticator.StringToByteArray(data);
 *                      byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
 *                      data = Encoding.UTF8.GetString(plain, 0, plain.Length);
 *                      break;
 *                    }
 *                  case 'm':
 *                    {
 *                      // we are going to decrypt with the Windows local machine key
 *                      byte[] cipher = Authenticator.StringToByteArray(data);
 *                      byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.LocalMachine);
 *                      data = Encoding.UTF8.GetString(plain, 0, plain.Length);
 *                      break;
 *                    }
 *                  case 'y':
 *                    {
 *                      // we use an explicit password to encrypt data
 *                      if (string.IsNullOrEmpty(password) == true)
 *                      {
 *                        throw new EncryptedSecretDataException();
 *                      }
 *                      data = Authenticator.Decrypt(data, password, true);
 *                      byte[] plain = Authenticator.StringToByteArray(data);
 *                      data = Encoding.UTF8.GetString(plain, 0, plain.Length);
 *                      break;
 *                    }
 *                  default:
 *                    break;
 *                }
 *              }
 */
                        }

                        AdvancedScript = data;

                        break;

                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                    break;
                }
            }
        }
示例#11
0
        /// <summary>
        /// Create a new HotKeySequence from a loaded string
        /// </summary>
        /// <param name="data">XmlNode from config</param>
        public HoyKeySequence(XmlNode autoLoginNode, string password, decimal version)
        {
            bool    boolVal = false;
            XmlNode node    = autoLoginNode.SelectSingleNode("modifiers");

            if (node != null && node.InnerText.Length != 0)
            {
                Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(node.InnerText), 0);
            }
            node = autoLoginNode.SelectSingleNode("hotkey");
            if (node != null && node.InnerText.Length != 0)
            {
                HotKey = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(node.InnerText), 0);
            }
            node = autoLoginNode.SelectSingleNode("windowtitle");
            if (node != null && node.InnerText.Length != 0)
            {
                WindowTitle = node.InnerText;
            }
            node = autoLoginNode.SelectSingleNode("windowtitleregex");
            if (node != null && bool.TryParse(node.InnerText, out boolVal) == true)
            {
                WindowTitleRegex = boolVal;
            }
            node = autoLoginNode.SelectSingleNode("processname");
            if (node != null && node.InnerText.Length != 0)
            {
                ProcessName = node.InnerText;
            }
            node = autoLoginNode.SelectSingleNode("advanced");
            if (node != null && bool.TryParse(node.InnerText, out boolVal) == true)
            {
                Advanced = boolVal;
            }
            node = autoLoginNode.SelectSingleNode("script");
            if (node != null && node.InnerText.Length != 0)
            {
                string data = node.InnerText;

                XmlAttribute attr = node.Attributes["encrypted"];
                if (attr != null && attr.InnerText.Length != 0)
                {
                    char[] encTypes = attr.InnerText.ToCharArray();
                    // we read the string in reverse order (the order they were encrypted)
                    for (int i = encTypes.Length - 1; i >= 0; i--)
                    {
                        char encryptedType = encTypes[i];
                        switch (encryptedType)
                        {
                        case 'u':
                        {
                            // we are going to decrypt with the Windows User account key
                            byte[] cipher = Authenticator.StringToByteArray(data);
                            byte[] plain  = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
                            data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                            break;
                        }

                        case 'm':
                        {
                            // we are going to decrypt with the Windows local machine key
                            byte[] cipher = Authenticator.StringToByteArray(data);
                            byte[] plain  = ProtectedData.Unprotect(cipher, null, DataProtectionScope.LocalMachine);
                            data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                            break;
                        }

                        case 'y':
                        {
                            // we use an explicit password to encrypt data
                            if (string.IsNullOrEmpty(password) == true)
                            {
                                throw new EncryptedSecretDataException();
                            }
                            data = Authenticator.Decrypt(data, password, (version >= (decimal)1.7));                                             // changed encrypted in 1.7
                            byte[] plain = Authenticator.StringToByteArray(data);
                            data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                AdvancedScript = data;
            }
        }
示例#12
0
    public void ReadXml(XmlReader reader, string password = null)
    {
      reader.MoveToContent();

      if (reader.IsEmptyElement)
      {
        reader.Read();
        return;
      }

      reader.Read();
      while (reader.EOF == false)
      {
        if (reader.IsStartElement())
        {
          switch (reader.Name)
          {
            case "modifiers":
      				Modifiers = (WinAPI.KeyModifiers)BitConverter.ToInt32(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
              break;

            case "hotkey":
              HotKey = (WinAPI.VirtualKeyCode)BitConverter.ToUInt16(Authenticator.StringToByteArray(reader.ReadElementContentAsString()), 0);
              break;

            case "windowtitle":
              WindowTitle = reader.ReadElementContentAsString();
              break;

            case "windowtitleregex":
              WindowTitleRegex = reader.ReadElementContentAsBoolean();
              break;

            case "processname":
              ProcessName = reader.ReadElementContentAsString();
              break;

            case "advanced":
              Advanced = reader.ReadElementContentAsBoolean();
              break;

            case "script":
              string encrypted = reader.GetAttribute("encrypted");
              string data = reader.ReadElementContentAsString();

              if (string.IsNullOrEmpty(encrypted) == false)
              {
                Authenticator.PasswordTypes passwordType = Authenticator.DecodePasswordTypes(encrypted);
								data = Authenticator.DecryptSequence(data, passwordType, password, null, true);
                //byte[] plain = Authenticator.StringToByteArray(data);
                //data = Encoding.UTF8.GetString(plain, 0, plain.Length);

/*
                char[] encTypes = encrypted.ToCharArray();
                // we read the string in reverse order (the order they were encrypted)
                for (int i = encTypes.Length - 1; i >= 0; i--)
                {
                  char encryptedType = encTypes[i];
                  switch (encryptedType)
                  {
                    case 'u':
                      {
                        // we are going to decrypt with the Windows User account key
                        byte[] cipher = Authenticator.StringToByteArray(data);
                        byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
                        data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                        break;
                      }
                    case 'm':
                      {
                        // we are going to decrypt with the Windows local machine key
                        byte[] cipher = Authenticator.StringToByteArray(data);
                        byte[] plain = ProtectedData.Unprotect(cipher, null, DataProtectionScope.LocalMachine);
                        data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                        break;
                      }
                    case 'y':
                      {
                        // we use an explicit password to encrypt data
                        if (string.IsNullOrEmpty(password) == true)
                        {
                          throw new EncrpytedSecretDataException();
                        }
                        data = Authenticator.Decrypt(data, password, true);
                        byte[] plain = Authenticator.StringToByteArray(data);
                        data = Encoding.UTF8.GetString(plain, 0, plain.Length);
                        break;
                      }
                    default:
                      break;
                  }
                }
*/
              }

              AdvancedScript = data;

              break;

            default:
              reader.Skip();
              break;
          }
        }
        else
        {
          reader.Read();
          break;
        }
      }
    }