c# - "File opened that is not a database file" opening firefox's cookies.sqlite -
http://www.codeproject.com/articles/330142/cookie-quest-a-quest-to-read-cookies-from-four-pop
i implemented code above link read cookies firefox, internet explorer, , chrome. methods internet explorer , chrome both work. however, sqlite throwing connection firefox method on conn.open()
reads "file opened not database file." file there , everything.
can tell me why might happening?
here methods used firefox throw exception:
private static bool getcookie_firefox(string strhost, string strfield, ref string value) { value = string.empty; bool frtn = false; string strpath, strtemp, strdb; strtemp = string.empty; // check see if firefox installed strpath = getfirefoxcookiepath(); if (string.empty == strpath) // nope, perhaps browser return false; try { // first copy cookie jar can read cookies unlocked copy while // firefox running strtemp = strpath + ".temp"; strdb = "data source=" + strtemp + ";pooling=false"; file.copy(strpath, strtemp, true); // open temporary cookie jar , extract value cookie if // find it. using (sqliteconnection conn = new sqliteconnection(strdb)) { using (sqlitecommand cmd = conn.createcommand()) { cmd.commandtext = "select value moz_cookies host '%" + strhost + "%' , name '%" + strfield + "%';"; conn.open(); using (sqlitedatareader reader = cmd.executereader()) { while (reader.read()) { value = reader.getstring(0); if (!value.equals(string.empty)) { frtn = true; break; } } } conn.close(); } } } catch (exception) { value = string.empty; frtn = false; } // done clean if (string.empty != strtemp) { file.delete(strtemp); } return frtn; } private static string getfirefoxcookiepath() { string s = environment.getfolderpath( environment.specialfolder.applicationdata); s += @"\mozilla\firefox\profiles\"; try { directoryinfo di = new directoryinfo(s); directoryinfo[] dir = di.getdirectories("*.default"); if (dir.length != 1) return string.empty; s += dir[0].name + @"\" + "cookies.sqlite"; } catch (exception) { return string.empty; } if (!file.exists(s)) return string.empty; return s; }
here working chrome methods:
private static bool getcookie_chrome(string strhost, string strfield, ref string value) { value = string.empty; bool frtn = false; string strpath, strdb; // check see if chrome installed strpath = getchromecookiepath(); if (string.empty == strpath) // nope, perhaps browser return false; try { strdb = "data source=" + strpath + ";pooling=false"; using (sqliteconnection conn = new sqliteconnection(strdb)) { using (sqlitecommand cmd = conn.createcommand()) { cmd.commandtext = "select value cookies host_key '%" + strhost + "%' , name '%" + strfield + "%';"; conn.open(); using (sqlitedatareader reader = cmd.executereader()) { while (reader.read()) { value = reader.getstring(0); if (!value.equals(string.empty)) { frtn = true; break; } } } conn.close(); } } } catch (exception) { value = string.empty; frtn = false; } return frtn; } 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; }
Comments
Post a Comment