Feedback

C# - Google Chrome Browser History

Veröffentlicht von am 9/5/2014
(0 Bewertungen)
Dieses Snippet ermöglicht es die SQLite Datenbank von Google Chrome anzuzapfen & wichtige bzw. interessante Daten zu extrahieren.

Für die Nutzung von SQLiteConnection müsst ihr euch die entsprechende .dll downloaden.

Achtung : !! Der Browser muss geschlossen sein. !!

http://www.sqlite.org/download.html
private string connection = "Data Source=C:\\Users\\" + Environment.UserName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History";
private string examplePath = "C:\\";

private void Init_ChromeBrowserHistory(string from)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(connection))
                {
                    conn.Open();

                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        cmd.Connection = conn;
                        cmd.CommandText = "Select * From " + from;

                        SQLiteDataReader dr = cmd.ExecuteReader();

                        if (!Directory.Exists(examplePath + DateTime.Now.ToShortDateString()))
                            Directory.CreateDirectory(examplePath + DateTime.Now.ToShortDateString());

                        using (StreamWriter sw = new StreamWriter(examplePath + DateTime.Now.ToShortDateString() + "\\BrowserHistory.txt", true))
                        {
                            sw.WriteLine(from.ToUpper() + Environment.NewLine);
                            while (dr.Read())
                            {
                                if (from == "keyword_search_terms")
                                {
                                    sw.WriteLine(dr.GetName(3) + "  :  " + dr[3].ToString());
                                    sw.WriteLine("");
                                }
                                else
                                {
                                    for (int i = 0; i < dr.FieldCount; i++)
                                    {
                                        if (from == "segment_usage" || from == "visits")                    // Filter
                                        { }
                                        else
                                        {
                                            sw.WriteLine(dr.GetName(i) + "  :  " + dr[i].ToString());
                                        }
                                    }
                                    sw.WriteLine("");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            { }
        }

        private List<string> GetTableNames()
        {
            List<string> names = new List<string>();
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(connection))
                {
                    conn.Open();

                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        cmd.Connection = conn;
                        cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";

                        SQLiteDataReader dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            names.Add(dr[0].ToString());
                        }

                    }
                }
                return names;
            }
            catch (Exception e)
            {
                return null;
            }
        }
Abgelegt unter Google, Chrome, Browser, History, sqlite.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!