Example #1
0
        private void RestoreSessionButton_Click(object sender, EventArgs e)
        {
            if ((File.Exists("session-data")) && (!File.Exists(".saved-session")))
            {
                DataInputBox box = new DataInputBox("Password entry", "Enter password used to secure this session data", true);
                if (box.ShowDialog() == DialogResult.OK)
                {
                    Cryptography.updateSalt();
                    byte[] decrypted = Cryptography.Decrypt(File.ReadAllBytes("session-data"), box.getInputText().Trim());
                    if (decrypted == null)
                    {
                        MessageBox.Show("The inputted credentials were incorrect! Please try again.");
                        return;
                    }
                    int len = BitConverter.ToInt32(decrypted, 0);
                    byte[] data = decrypted.subArray(4, len);
                    byte[] serialized = decrypted.subArray(4 + len, decrypted.Length - (len + 4));
                    List<String> cookieValue = (List<String>)Utils.deserialize(serialized);
                    CookieProcessor processor = new CookieProcessor();
                    byte[] modified = processor.updateData(data, cookieValue);
                    processor.buildWorkingCopy(ChromeHandler.chromeDir + "\\Cookies");
                    byte[] read = File.ReadAllBytes(".working");
                    File.WriteAllBytes(".saved-session", Cryptography.Encrypt(read, box.getInputText().Trim()));
                    MessageBox.Show("Data successfully adapted, please restart Chrome so that the session changes may take effect. You will be notified when the session has been successfully inputted.", "Session success!");
                    while (true)
                    {
                        try
                        {
                            File.WriteAllBytes(ChromeHandler.chromeDir + "\\Cookies", modified);
                            MessageBox.Show("Session successfully inputted into Chrome!", "Input success!");
                            break;
                        }
                        catch
                        {

                        }
                        Thread.Sleep(50);
                    }
                    RestoreSessionButton.Text = "Restore Original Session";
                }
            }
            else if (File.Exists(".saved-session"))
            {
                DataInputBox box = new DataInputBox("Password entry", "Enter password used to secure this session data", true);
                if (box.ShowDialog() == DialogResult.OK)
                {
                    if (MessageBox.Show("Would you like to save your current session back to the session data before reverting to the original session?", "Session query", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        saveSessionWork(box.getInputText().Trim());
                    }
                    Cryptography.updateSalt();
                    byte[] decrypted = Cryptography.Decrypt(File.ReadAllBytes(".saved-session"), box.getInputText().Trim());
                    if (decrypted == null)
                    {
                        MessageBox.Show("The inputted credentials were incorrect! Please try again.");
                        return;
                    }
                    File.Delete(".saved-session");
                    MessageBox.Show("Please restart Chrome so that the session changes may take effect. You will be notified when the session has been successfully inputted.", "Session success!");
                    while (true)
                    {
                        try
                        {
                            File.WriteAllBytes(ChromeHandler.chromeDir + "\\Cookies", decrypted);
                            MessageBox.Show("Session successfully inputted into Chrome!", "Input success!");
                            break;
                        }
                        catch
                        {

                        }
                        Thread.Sleep(50);
                    }
                    RestoreSessionButton.Text = "Restore Saved Session";
                    if (File.Exists("session-data"))
                    {
                        RestoreSessionButton.Enabled = true;
                    }
                    else
                    {
                        RestoreSessionButton.Enabled = false;
                    }
                }
            }
            else
            {
                MessageBox.Show("Session data file not found! Please ensure you have saved a chrome session to this installation.", "Session data error");
            }
        }
Example #2
0
 private void saveSessionWork(String password = null)
 {
     List<String> cookieValue;
     CookieProcessor processor = new CookieProcessor();
     processor.buildWorkingCopy(ChromeHandler.chromeDir + "\\Cookies");
     byte[] data = processor.readCookies(".working", out cookieValue);
     File.Delete(".working");
     byte[] serialized = Utils.serialize(cookieValue);
     byte[] len = BitConverter.GetBytes(data.Length);
     byte[] built = new byte[len.Length + data.Length + serialized.Length];
     len.CopyTo(built, 0);
     data.CopyTo(built, len.Length);
     serialized.CopyTo(built, len.Length + data.Length);
     if (password == null)
     {
         DataInputBox box = new DataInputBox("Password entry", "Create password for securing session data", true);
         if (box.ShowDialog() == DialogResult.OK)
         {
             password = box.getInputText().Trim();
         }
     }
     if (password != null)
     {
         Cryptography.updateSalt();
         byte[] encrypted = Cryptography.Encrypt(built, password);
         if (encrypted == null)
         {
             MessageBox.Show("The inputted credentials were incorrect! Please try again.");
             return;
         }
         File.WriteAllBytes("session-data", encrypted);
         RestoreSessionButton.Enabled = true;
         MessageBox.Show("Data saved and secured at \"" + Environment.CurrentDirectory + "\\session-data\"", "Complete!");
     }
 }