Beispiel #1
0
        private void InternetExplorerStoreCookie(string profileName, bool isUpdating)
        {
            uint cookieFlags = 2147484672;

            if (this.checkBox1.Checked)
            {
                cookieFlags |= 0x1;
            }
            if (this.checkBox2.Checked)
            {
                cookieFlags |= 0x2000;
            }

            bool storeForProtectedMode = profileName == "Protected";

            if (isUpdating && !(this.comboBox1.Text == this.host && this.textBox1.Text == this.path && this.textBox2.Text == this.name))
            {
                string localAppPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                this.DeleteCookieOfIE(Path.Combine(localAppPath, "Microsoft", "Windows", "INetCookies", storeForProtectedMode ? "Low" : ""), this.host + "/" + this.path, this.name);
            }

            if (storeForProtectedMode)
            {
                try
                {
                    DerivedMethod.CreateSpecificIntegrityProcess(
                        String.Join(" ",
                                    new InternetExplorerCookieStorer.Program().Path,
                                    Convert.ToBase64String(Encoding.UTF8.GetBytes(this.comboBox1.Text + this.textBox1.Text)),
                                    Convert.ToBase64String(Encoding.UTF8.GetBytes(this.textBox2.Text)),
                                    Convert.ToBase64String(Encoding.UTF8.GetBytes(this.textBox3.Text)),
                                    this.dateTimePicker1.Value.Ticks,
                                    cookieFlags
                                    ),
                        NativeMethod.SECURITY_MANDATORY_LOW_RID
                        );

                    Thread.Sleep(1000); // the elegant way would be to create a pipe and wait for output which will be produced when process finishes
                }
                catch (Win32Exception e)
                {
                    MessageBox.Show("Following error has occurred while storing Internet Explorer Protected cookie data: " + e.Message + Environment.NewLine + "Make sure that InternerExplorerCookieStorer has been previously deployed");
                }
            }
            else
            {
                if (!InternetSetCookieEx("http://" + this.comboBox1.Text + this.textBox1.Text, null, this.textBox2.Text + " = " + this.textBox3.Text + "; Expires = " + this.dateTimePicker1.Value.ToString("R"), cookieFlags, IntPtr.Zero))
                {
                    MessageBox.Show("An error with code " + GetLastError() + " has occurred while storing Internet Explorer Non-protected cookie data");
                }

                /* another way to store cookie in Internet Explorer
                 * WebBrowser wb = new WebBrowser();
                 * wb.Navigate(new Uri("http://" + this.comboBox1.Text + this.textBox1.Text));
                 * wb.Navigated += Wb_Navigated;
                 */
            }
        }
        static void Main(string[] args)
        {
            if (DerivedMethod.GetProcessIntegrityLevel() <= MaximumAllowedIntegrityLevel)
            {
                string cookieHostAndPath = Encoding.UTF8.GetString(Convert.FromBase64String(args[0]));
                string cookieName        = Encoding.UTF8.GetString(Convert.FromBase64String(args[1]));
                string cookieValue       = Encoding.UTF8.GetString(Convert.FromBase64String(args[2]));
                string expirationDate    = new DateTime(long.Parse(args[3])).ToString("R");
                uint   cookieFlags       = uint.Parse(args[4]);
                if (!InternetSetCookieEx("http://" + cookieHostAndPath, null, cookieName + " = " + cookieValue + "; Expires = " + expirationDate, cookieFlags, IntPtr.Zero))
                {
                    //MessageBox.Show("An error with code " + GetLastError() + " has occurred while storing cookie data");
                }

                /* another way to store cookie in Internet Explorer
                 * WebBrowser wb = new WebBrowser();
                 * wb.Navigate(new Uri("http://" + this.comboBox1.Text + this.textBox1.Text));
                 * wb.Navigated += Wb_Navigated;
                 */
            }
        }
 static void Main()
 {
     if (DerivedMethod.GetProcessIntegrityLevel() < MinimumRequiredIntegrityLevel)
     {
         try
         {
             // Try to launch a new instance of the current application at the low
             // integrity level.
             DerivedMethod.CreateSpecificIntegrityProcess(Application.ExecutablePath, MinimumRequiredIntegrityLevel);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "CreateSpecificIntegrityProcess Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new MainWindow());
     }
 }