Example #1
0
        /// <summary>
        /// Gets the firefox cookies.
        /// </summary>
        /// <returns>get the list of firefox cookies</returns>
        public static List <BrowserCookie_Node> OnGetFirefoxCookies()
        {
            List <string>             Profiles = GetFirefoxProfilePaths();
            List <BrowserCookie_Node> Cookies  = new List <BrowserCookie_Node>();

            foreach (string profile in Profiles)
            {
                string strPath, strTemp, strDb;
                strTemp = string.Empty;

                // Check to see if FireFox Installed
                strPath = profile + "\\cookies.sqlite";
                if (string.Empty == strPath) // Nope, perhaps another browser
                {
                    return(Cookies);
                }
                // First copy the cookie jar so that we can read the cookies
                // from unlocked copy while
                // FireFox is running
                strTemp = strPath + ".temp";
                strDb   = "Data Source=" + strTemp + ";pooling=false";

                File.Copy(strPath, strTemp, true);

                // Now open the temporary cookie jar and extract Value from the cookie if
                // we find it.
                using (SQLiteConnection conn = new SQLiteConnection(strDb))
                {
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM moz_cookies";

                        conn.Open();
                        using (SQLiteDataReader sqlite_datareader = cmd.ExecuteReader())
                        {
                            while (sqlite_datareader.Read())
                            {
                                BrowserCookie_Node cookienode = new BrowserCookie_Node();
                                cookienode.baseDomain   = sqlite_datareader["baseDomain"].ToString();
                                cookienode.name         = sqlite_datareader["name"].ToString();
                                cookienode.value        = sqlite_datareader["value"].ToString();
                                cookienode.expiry       = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["expiry"].ToString()));
                                cookienode.creationTime = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["creationTime"].ToString()));
                                cookienode.lastAccessed = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["lastAccessed"].ToString()));
                                Cookies.Add(cookienode);
                            }
                        }
                        conn.Close();
                    }
                }

                // All done clean up
                if (string.Empty != strTemp)
                {
                    File.Delete(strTemp);
                }
            }
            return(Cookies);
        }
Example #2
0
        /// <summary>
        /// Gets the ie cookies.
        /// </summary>
        ///ie cookie format
        ///Cookie name
        ///Cookie value
        ///Host/path for the web server setting the cookie
        ///Flags
        ///Exirpation time(low)
        ///Expiration time(high)
        ///Creation time(low)
        ///Creation time(high)
        ///Record delimiter(*)
        /// <returns>get the list of ie cookies</returns>
        public static List <BrowserCookie_Node> OnGetIECookies()
        {
            List <BrowserCookie_Node> Cookies = new List <BrowserCookie_Node>();

            string Value = string.Empty;
            bool   fRtn = false;
            string strPath, strCookie;

            string[]     fp;
            StreamReader r;
            int          idx;

            strPath = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
            Version v = Environment.OSVersion.Version;

            if (IsWindows7())
            {
                strPath += @"\low";
            }

            fp = Directory.GetFiles(strPath, "*.txt");

            foreach (string path in fp)
            {
                r = File.OpenText(path);
                FileInfo fileinf = new FileInfo(path);
                strCookie = r.ReadToEnd();
                r.Close();
                string[] SplitedCookieDataByStart = strCookie.Split("*".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string OneFullCookie in SplitedCookieDataByStart)
                {
                    string[] SplitedOneCookieToLines = OneFullCookie.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (SplitedOneCookieToLines.Length > 7)
                    {
                        BrowserCookie_Node cookienode = new BrowserCookie_Node();
                        cookienode.name         = SplitedOneCookieToLines[0];
                        cookienode.value        = SplitedOneCookieToLines[1];
                        cookienode.baseDomain   = SplitedOneCookieToLines[2];
                        cookienode.lastAccessed = fileinf.LastAccessTime;
                        FILETIME ft = new FILETIME();
                        ft.dwLowDateTime        = (int)long.Parse(SplitedOneCookieToLines[4]);
                        ft.dwHighDateTime       = (int)long.Parse(SplitedOneCookieToLines[5]);
                        cookienode.expiry       = FILETIMEToLong(ft);
                        ft.dwLowDateTime        = (int)long.Parse(SplitedOneCookieToLines[6]);
                        ft.dwHighDateTime       = (int)long.Parse(SplitedOneCookieToLines[7]);
                        cookienode.creationTime = FILETIMEToLong(ft);
                        Cookies.Add(cookienode);
                    }
                }
            }
            return(Cookies);
        }
Example #3
0
        /// <summary>
        /// Gets the chrome cookies.
        /// </summary>
        /// <returns>get the list of opera cookies</returns>
        public static List <BrowserCookie_Node> OnGetOperaCookies()
        {
            List <BrowserCookie_Node> Cookies = new List <BrowserCookie_Node>();
            string CookiesPath = GetOperaProfilePaths();

            CookiesPath += "\\Cookies";
            string strDb = "Data Source=" + CookiesPath + ";pooling=false";

            using (SQLiteConnection conn = new SQLiteConnection(strDb))
            {
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM cookies";
                    conn.Open();
                    using (SQLiteDataReader sqlite_datareader = cmd.ExecuteReader())
                    {
                        while (sqlite_datareader.Read())
                        {
                            BrowserCookie_Node cookienode = new BrowserCookie_Node();
                            cookienode.baseDomain = sqlite_datareader["host_key"].ToString();
                            cookienode.name       = sqlite_datareader["name"].ToString();
                            byte[] encrypted_value = (byte[])sqlite_datareader["encrypted_value"];
                            string decoded_value   = Encoding.ASCII.GetString(ProtectedData.Unprotect(encrypted_value, null, System.Security.Cryptography.DataProtectionScope.LocalMachine));
                            cookienode.value        = decoded_value;
                            cookienode.expiry       = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["expires_utc"].ToString()));
                            cookienode.lastAccessed = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["last_access_utc"].ToString()));
                            cookienode.creationTime = BrowserHistory_Node.FromUnixTime(long.Parse(sqlite_datareader["creation_utc"].ToString()));

                            Cookies.Add(cookienode);
                        }
                    }
                    conn.Close();
                }
            }
            return(Cookies);
        }