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]
84macro_rules! firefox {
85 (
86 $platform:literal,
87 $browser:ident,
88 base: $base:literal
89 $(, cookies: $cookies:literal)?
90 $(, login_data: $login_data:literal)?
91 $(, key = $key:literal)?
92 ) => {
93 #[cfg(feature = "linkme")]
94 $crate::pastey::paste! {
95 #[cfg(target_os = $platform)]
96 #[linkme::distributed_slice($crate::browser::BROWSERS)]
97 static [<$browser:upper _NAME>]: &str = stringify!($browser);
98 }
99
100 #[cfg(target_os = $platform)]
101 #[derive(Clone, Copy)]
102 #[derive(Debug)]
103 #[derive(Default)]
104 #[derive(PartialEq, Eq, PartialOrd, Ord)]
105 #[expect(clippy::exhaustive_structs, reason = "unit struct")]
106 pub struct $browser;
107
108 #[cfg(target_os = $platform)]
109 impl FirefoxPath for $browser {
110 const BASE: &'static str = $base;
111 const NAME: &'static str = stringify!($browser);
112 $(const COOKIES: &str = $cookies;)?
113 $(const LOGIN_DATA: &str = $login_data;)?
114 $(const KEY: &str = $key;)?
115 }
116
117 #[cfg(target_os = $platform)]
118 impl std::fmt::Display for $browser {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 f.write_str(Self::NAME)
121 }
122 }
123 };
124}
125
126firefox!("linux", Firefox , base: ".mozilla/firefox");
127firefox!("linux", Librewolf, base: ".librewolf" );
128firefox!("linux", Floorp , base: ".floorp" );
129firefox!("linux", Zen , base: ".zen" );
130
131firefox!("macos", Firefox , base: "Library/Application Support/Firefox" );
132firefox!("macos", Librewolf, base: "Library/Application Support/librewolf");
133firefox!("macos", Floorp , base: "Library/Application Support/Floorp" );
134firefox!("macos", Zen , base: "Library/Application Support/zen" );
135
136firefox!("windows", Firefox , base: r"AppData\Roaming\Mozilla\Firefox");
137firefox!("windows", Librewolf, base: r"AppData\Roaming\librewolf" );
138firefox!("windows", Floorp , base: r"AppData\Roaming\Floorp" );
139firefox!("windows", Zen , base: r"AppData\Roaming\zen" );