mardi 5 avril 2016

Read Cookies of chrome by C# and sqlite

now I'm trying to read cooking by use c# to read database sqlite of cookies. but I always have error with message

The database disk image is malformed\r\nmalformed database schema (is_transient) - near \"where\": syntax error"} System.Exception {System.Data.SQLite.SQLiteException}

below is my code

private static string GetChromeCookiePath()
    {
        string s = Environment.GetFolderPath(
            Environment.SpecialFolder.LocalApplicationData);
        s += @"\Google\Chrome\User Data\Default\Cookies";

        if (!File.Exists(s))
            return string.Empty;

        return s;
    }

    public String GetCookie_Chrome()
    {
        String Value = string.Empty;
        bool fRtn = false;
        string strPath, strDb;

        // Check to see if Chrome Installed
        strPath = GetChromeCookiePath();
        if (string.Empty == strPath) // Nope, perhaps another browser
            return "";

        try
        {
            //strDb = "Data Source=" + strPath + ";pooling=false";
            strDb = "data source="+ strPath + "; Version=3";

            using (SQLiteConnection conn = new SQLiteConnection(strDb))
            {
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = "SELECT path FROM cookies WHERE host_key LIKE '%" +
                        "www.facebook.com" + "%' AND name LIKE '%" + "current" + "%';";

                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Value = reader.GetString(0);
                            if (!Value.Equals(string.Empty))
                            {
                                return Value;
                            }
                        }
                    }
                    conn.Close();
                }
            }
        }
        catch (Exception e)
         {
            Value = string.Empty;
            fRtn = false;
        }
        return Value;

    }

Help me, please!

Aucun commentaire:

Enregistrer un commentaire