decrypt_cookies/browser/
firefox.rs1use std::path::PathBuf;
2
3use super::CACHE_PATH;
4
5pub trait FirefoxPath {
6 const BASE: &'static str;
8 const NAME: &'static str;
10 const COOKIES: &str = "cookies.sqlite";
12 const LOGIN_DATA: &str = "logins.json";
14 const KEY: &str = "key4.db";
16
17 fn key(mut base: PathBuf) -> PathBuf {
19 push_exact!(base, Self::KEY);
20
21 base
22 }
23 fn key_temp() -> Option<PathBuf> {
25 push_temp!(cache, Self::KEY);
26
27 cache.into()
28 }
29
30 fn cookies(mut base: PathBuf) -> PathBuf {
32 push_exact!(base, Self::COOKIES);
33
34 base
35 }
36 fn cookies_temp() -> Option<PathBuf> {
38 push_temp!(cache, Self::COOKIES);
39
40 cache.into()
41 }
42
43 fn login_data(mut base: PathBuf) -> PathBuf {
45 push_exact!(base, Self::LOGIN_DATA);
46
47 base
48 }
49 fn login_data_temp() -> Option<PathBuf> {
51 push_temp!(cache, Self::LOGIN_DATA);
52
53 cache.into()
54 }
55}
56
57#[macro_export]
82macro_rules! firefox {
83 (
84 $platform:literal,
85 $browser:ident,
86 base: $base:literal
87 $(, cookies: $cookies:literal)?
88 $(, login_data: $login_data:literal)?
89 $(, key = $key:literal)?
90 ) => {
91 #[cfg(target_os = $platform)]
92 #[derive(Clone, Copy)]
93 #[derive(Debug)]
94 #[derive(Default)]
95 #[derive(PartialEq, Eq, PartialOrd, Ord)]
96 #[expect(clippy::exhaustive_structs, reason = "unit struct")]
97 pub struct $browser;
98
99 #[cfg(target_os = $platform)]
100 impl FirefoxPath for $browser {
101 const BASE: &'static str = $base;
102 const NAME: &'static str = stringify!($browser);
103 $(const COOKIES: &str = $cookies;)?
104 $(const LOGIN_DATA: &str = $login_data;)?
105 $(const KEY: &str = $key;)?
106 }
107
108 #[cfg(target_os = $platform)]
109 impl std::fmt::Display for $browser {
110 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
111 f.write_str(Self::NAME)
112 }
113 }
114 };
115}
116
117firefox!("linux", Firefox , base: ".mozilla/firefox");
118firefox!("linux", Librewolf, base: ".librewolf" );
119firefox!("linux", Floorp , base: ".floorp" );
120firefox!("linux", Zen , base: ".zen" );
121
122firefox!("macos", Firefox , base: "Library/Application Support/Firefox" );
123firefox!("macos", Librewolf, base: "Library/Application Support/librewolf");
124firefox!("macos", Floorp , base: "Library/Application Support/Floorp" );
125firefox!("macos", Zen , base: "Library/Application Support/zen" );
126
127firefox!("windows", Firefox , base: r"AppData\Roaming\Mozilla\Firefox");
128firefox!("windows", Librewolf, base: r"AppData\Roaming\librewolf" );
129firefox!("windows", Floorp , base: r"AppData\Roaming\Floorp" );
130firefox!("windows", Zen , base: r"AppData\Roaming\zen" );