Re: Application that gets URLs with the default browser credentials

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"UL-Tomten" <tomten@xxxxxxxxx> wrote in message
news:1187789687.551519.81950@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Aug 22, 2:52 pm, "pedrito" <pixbypedrito at yahoo.com> wrote:

I have a small library on SourceForge for reading cookie files from IE
and
Firefox:http://ncookiereader.sourceforge.net/

throw new NotImplementedException("No support for finding the cookie path
yet.");

For what it's worth, here's what I did once to find the Firefox cookie
path (using the default profile of the current user):

private const string PATH_PROFILES_INI = @"%APPDATA%\Mozilla\Firefox
\profiles.ini";
private const string PATH_COOKIES_TXT = @"%APPDATA%\Mozilla\Firefox\
%PROFILE%\cookies.txt";
...
string pathAppData =
Environment.GetEnvironmentVariable("APPDATA");
string profilesIniPath = PATH_PROFILES_INI.Replace("%APPDATA%",
pathAppData);
string profileDir = null;
// Find default profile in profiles.ini
Dictionary<string, string>[] firefoxProfilesIni =
ParseIniFile(profilesIniPath);
foreach (Dictionary<string, string> iniGroup in
firefoxProfilesIni) {
if (iniGroup.ContainsKey("Default") && iniGroup["Default"] ==
"1")
profileDir = iniGroup["Path"];
}
_cookiePath = PATH_COOKIES_TXT.Replace("%PROFILE%",
profileDir).Replace("%APPDATA%", pathAppData);
...
const string INI_PATTERN = @"\s*\[([^\]]*)\]\r?\n([^\[]*)";
public static Dictionary<string, string>[] ParseIniFile(string
IniFilePath) {
List<Dictionary<string, string>> dictList = new
List<Dictionary<string, string>>();
string iniContents = File.ReadAllText(IniFilePath);
MatchCollection mc = Regex.Matches(iniContents, INI_PATTERN,
RegexOptions.Singleline);
foreach (Match m in mc) {
Dictionary<string, string> dict = new Dictionary<string,
string>();
string iniGroupName = m.Groups[1].Value.Trim();
dict.Add("_name", iniGroupName);
string[] newlines = { "\n", "\r", "\r\n" };
foreach (string keyvalue in m.Groups[2].Value.Split(newlines,
StringSplitOptions.RemoveEmptyEntries)) {
if (keyvalue.Contains("=")) {
dict.Add(keyvalue.Split('=')[0].Trim(),
keyvalue.Split('=')[1].Trim());
}
}
dictList.Add(dict);
}
return dictList.ToArray();
}


Thanks. I actually know how to do it, just haven't had time to implement it
yet. I have another project that's consumed most of my free time lately.
nCookieReader was a library I originally created as part of the other
project, but thought others might find it useful. The other app is launched
from the browser and the cookie path for firefox is passed as a parameter,
so that's why I didn't bother implementing it at the time. I plan to add it,
however, when I get free time... Somewhere between this other app, work,
school and research.


.


Quantcast