Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 1ef848e

Browse files
committed
firefox cookie extraction. that was a LOT simpler than chrome.
1 parent d89d336 commit 1ef848e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using Microsoft.Data.Sqlite;
4+
5+
namespace PatreonDownloader.CookieExtraction {
6+
public class FirefoxCookieExtractor : CookieExtractor {
7+
public override string Name => "Firefox";
8+
9+
public override string GetPatreonSessionToken() {
10+
string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla", "Firefox", "Profiles");
11+
12+
if (!Directory.Exists(dbPath)) {
13+
throw new CookieExtractorException("Firefox is not installed.");
14+
}
15+
16+
var profiles = Directory.GetDirectories(dbPath);
17+
18+
dbPath = Path.Combine(profiles[Util.ConsoleChoiceMenu("Which profile do you want to use?", profiles)], "Cookies.sqlite");
19+
20+
using var connection = new SqliteConnection($"Data Source={dbPath}");
21+
22+
connection.Open();
23+
SqliteCommand command = connection.CreateCommand();
24+
command.CommandText = "SELECT value FROM moz_cookies\n" +
25+
"WHERE host = '.patreon.com' AND name = 'session_id'\n" +
26+
"LIMIT 1"
27+
;
28+
using SqliteDataReader reader = command.ExecuteReader();
29+
if (reader.Read()) {
30+
return reader.GetString(0);
31+
}
32+
33+
throw new CookieExtractorException("No suitable cookie was found in Firefox' storage.");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)