cfsolve 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +26 -6
- data/UPSTREAM.md +23 -8
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +22 -11
- data/vendor/cfsolve/README.md +5 -53
- data/vendor/cfsolve/examples/listing_dump.rs +24 -0
- data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
- data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
- data/vendor/cfsolve/examples/reread_capture.rs +31 -0
- data/vendor/cfsolve/examples/turnstile_smoke.rs +24 -3
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/vendor/cfsolve/src/capture/sessions.rs +88 -4
- data/vendor/cfsolve/src/capture.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +10 -113
- data/vendor/cfsolve/src/embedding_page/page.rs +70 -99
- data/vendor/cfsolve/src/session/initial.rs +6 -7
- data/vendor/cfsolve/src/session/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +4 -33
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +9 -17
- data/vendor/cfsolve/src/stage2/benchmark.rs +42 -62
- data/vendor/cfsolve/src/stage2/call_stack.rs +133 -227
- data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
- data/vendor/cfsolve/src/stage2/probes/dates.rs +0 -44
- data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
- data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
- data/vendor/cfsolve/src/stage2/probes/stack.rs +45 -117
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +7 -76
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +70 -115
- data/vendor/cfsolve/src/stage2/registry.rs +6 -11
- data/vendor/cfsolve/src/stage2/replay.rs +3 -34
- data/vendor/cfsolve/src/stage2/stylesheets.rs +0 -35
- data/vendor/cfsolve/src/stage2/trace.rs +1 -1
- data/vendor/cfsolve/src/stage2/vocabulary.rs +6 -111
- data/vendor/cfsolve/src/stage2.rs +0 -1
- data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
- data/vendor/cfsolve/src/vm/disassemble.rs +5 -68
- data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
- data/vendor/cfsolve/src/vm/extract.rs +193 -343
- data/vendor/cfsolve/src/vm/interpret/access.rs +2 -10
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +28 -43
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +272 -100
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +259 -36
- data/vendor/cfsolve/src/vm/interpret/run.rs +0 -4
- data/vendor/cfsolve/src/vm/machine.rs +14 -70
- data/vendor/cfsolve/src/vm/output.rs +3 -5
- data/vendor/cfsolve/src/vm/registers.rs +26 -46
- data/vendor/cfsolve/src/vm/session.rs +11 -9
- data/vendor/cfsolve/src/vm.rs +1 -1
- metadata +6 -12
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/lib/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/vendor/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +0 -1
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +0 -326
- data/vendor/cfsolve/src/stage2/value_labels.rs +0 -185
- data/vendor/cfsolve/src/vm/encoded_names.rs +0 -635
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +0 -9
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +0 -7438
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +0 -1
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
//! Parent-page probes reading the loader's positional `wPr` array.
|
|
2
|
-
|
|
3
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
4
|
-
|
|
5
|
-
use serde::{Deserialize, Serialize};
|
|
6
|
-
|
|
7
|
-
use crate::embedding_page::page::PageSignals;
|
|
8
|
-
use crate::js::{self, JsObject, JsValue, json};
|
|
9
|
-
use crate::listing::Index;
|
|
10
|
-
use crate::stage2::analysis::recognize::ProbeView;
|
|
11
|
-
use crate::vm::{Constant, Effect, Term};
|
|
12
|
-
|
|
13
|
-
/// Output names and their source positions in the loader's page-signals array.
|
|
14
|
-
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
15
|
-
pub struct Fields {
|
|
16
|
-
pub properties: BTreeMap<String, usize>,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
impl Fields {
|
|
20
|
-
pub(crate) fn collect(&self, signals: &PageSignals) -> JsObject {
|
|
21
|
-
let values = signals.positional();
|
|
22
|
-
self.properties
|
|
23
|
-
.iter()
|
|
24
|
-
.filter_map(|(field, &slot)| {
|
|
25
|
-
let value = values.get(slot)?.clone();
|
|
26
|
-
let value = match slot {
|
|
27
|
-
22 => json!(signals.parent.reasons.join("~")),
|
|
28
|
-
2 | 15 | 17 | 20 | 21 | 25 if !js::truthy(&value) => json!(""),
|
|
29
|
-
// Absent optional properties are undefined in the loader's message and
|
|
30
|
-
// omitted from the probe's JSON object.
|
|
31
|
-
7 | 8 if value == JsValue::Null => return None,
|
|
32
|
-
_ => value,
|
|
33
|
-
};
|
|
34
|
-
Some((field.clone(), value))
|
|
35
|
-
})
|
|
36
|
-
.collect()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
41
|
-
if !["_cf_chl_opt", "length", "join", "~"]
|
|
42
|
-
.iter()
|
|
43
|
-
.all(|marker| probe.session_features.iter().any(|text| text == marker))
|
|
44
|
-
{
|
|
45
|
-
return None;
|
|
46
|
-
}
|
|
47
|
-
let code = probe.index.reachable(probe.entry);
|
|
48
|
-
let sources = Sources::new(probe.index, &code);
|
|
49
|
-
let mut properties = BTreeMap::new();
|
|
50
|
-
let mut options = BTreeSet::new();
|
|
51
|
-
for store in probe
|
|
52
|
-
.index
|
|
53
|
-
.stores()
|
|
54
|
-
.iter()
|
|
55
|
-
.filter(|store| code.contains(&store.pc) && probe.writes.fields.contains(&store.key))
|
|
56
|
-
{
|
|
57
|
-
let mut reads = sources.reads(store.pc, &store.value);
|
|
58
|
-
let Some((slot, option)) = reads.pop_first() else {
|
|
59
|
-
continue;
|
|
60
|
-
};
|
|
61
|
-
if !reads.is_empty() {
|
|
62
|
-
return None;
|
|
63
|
-
}
|
|
64
|
-
options.insert(option);
|
|
65
|
-
properties.insert(store.key.clone(), slot);
|
|
66
|
-
}
|
|
67
|
-
// All these reads must come from the same `_cf_chl_opt` array. This distinguishes the
|
|
68
|
-
// probe from unrelated indexed fingerprint data and fails closed on changed layouts.
|
|
69
|
-
let expected: BTreeSet<usize> = [
|
|
70
|
-
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 19, 20, 21, 22, 23, 25, 27, 28,
|
|
71
|
-
]
|
|
72
|
-
.into();
|
|
73
|
-
let found: BTreeSet<usize> = properties.values().copied().collect();
|
|
74
|
-
(options.len() == 1 && found == expected && properties.len() == expected.len())
|
|
75
|
-
.then_some(Fields { properties })
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/// Trace reaching register definitions through control flow, including both sides of an
|
|
79
|
-
/// empty-string fallback. The nearest earlier assignment can belong to a branch that never
|
|
80
|
-
/// reaches the call, notably `reasons && reasons.join ? reasons.join("~") : ""`.
|
|
81
|
-
struct Sources<'index, 'listing> {
|
|
82
|
-
index: &'index Index<'listing>,
|
|
83
|
-
incoming: BTreeMap<u32, Vec<(u32, usize)>>,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
impl<'index, 'listing> Sources<'index, 'listing> {
|
|
87
|
-
fn new(index: &'index Index<'listing>, code: &BTreeSet<u32>) -> Self {
|
|
88
|
-
let mut incoming: BTreeMap<u32, Vec<(u32, usize)>> = BTreeMap::new();
|
|
89
|
-
for &pc in code {
|
|
90
|
-
for (path, body) in index.listing().instructions[&pc].paths.iter().enumerate() {
|
|
91
|
-
if let Some(next) = body.exit.continues_at() {
|
|
92
|
-
incoming.entry(next.pc).or_default().push((pc, path));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
Self { index, incoming }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
fn definitions(&self, pc: u32, register: u8) -> Vec<(u32, Term)> {
|
|
100
|
-
let mut pending = vec![pc];
|
|
101
|
-
let mut visited = BTreeSet::new();
|
|
102
|
-
let mut definitions = Vec::new();
|
|
103
|
-
while let Some(next) = pending.pop() {
|
|
104
|
-
if !visited.insert(next) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
for &(at, path) in self.incoming.get(&next).into_iter().flatten() {
|
|
108
|
-
let effects = &self.index.listing().instructions[&at].paths[path].effects;
|
|
109
|
-
if let Some((position, value)) =
|
|
110
|
-
effects
|
|
111
|
-
.iter()
|
|
112
|
-
.enumerate()
|
|
113
|
-
.rev()
|
|
114
|
-
.find_map(|(i, effect)| match effect {
|
|
115
|
-
Effect::Set(target, value) if *target == register => Some((i, value)),
|
|
116
|
-
_ => None,
|
|
117
|
-
})
|
|
118
|
-
{
|
|
119
|
-
let value = if let Term::Temp(temporary) = value {
|
|
120
|
-
effects[..position]
|
|
121
|
-
.iter()
|
|
122
|
-
.rev()
|
|
123
|
-
.find_map(|effect| match effect {
|
|
124
|
-
Effect::Let(target, value) if target == temporary => Some(value),
|
|
125
|
-
_ => None,
|
|
126
|
-
})
|
|
127
|
-
.unwrap_or(value)
|
|
128
|
-
} else {
|
|
129
|
-
value
|
|
130
|
-
};
|
|
131
|
-
if !definitions.contains(&(at, value.clone())) {
|
|
132
|
-
definitions.push((at, value.clone()));
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
pending.push(at);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
definitions
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
fn reads(&self, pc: u32, value: &Term) -> BTreeSet<(usize, String)> {
|
|
143
|
-
let mut reads = BTreeSet::new();
|
|
144
|
-
let mut pending = vec![(pc, value.clone())];
|
|
145
|
-
let mut visited = BTreeSet::new();
|
|
146
|
-
while let Some((at, value)) = pending.pop() {
|
|
147
|
-
match value {
|
|
148
|
-
Term::Reg(register) => {
|
|
149
|
-
if visited.insert((at, register)) {
|
|
150
|
-
pending.extend(self.definitions(at, register));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
Term::Get(object, key) => {
|
|
154
|
-
if let Some((_, Term::Const(Constant::Number(slot)))) =
|
|
155
|
-
self.index.dereference(at, &key)
|
|
156
|
-
&& slot >= 0.0
|
|
157
|
-
&& slot.fract() == 0.0
|
|
158
|
-
&& let Some(option) = self.index.member(at, &object)
|
|
159
|
-
&& self.index.reads(option.pc, &option.object, "_cf_chl_opt")
|
|
160
|
-
{
|
|
161
|
-
reads.insert((slot as usize, option.key));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
Term::Call { callee, this, .. } => {
|
|
165
|
-
if let Some(member) = self.index.member(at, &callee)
|
|
166
|
-
&& member.key == "join"
|
|
167
|
-
{
|
|
168
|
-
pending.push((at, this.map_or(member.object, |value| *value)));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
_ => {}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
reads
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
#[cfg(test)]
|
|
179
|
-
mod tests {
|
|
180
|
-
use super::*;
|
|
181
|
-
use crate::embedding_page::page::{Layout, RenderedPage};
|
|
182
|
-
use crate::vm::{Exit, Instruction, Listing, Path};
|
|
183
|
-
use url::Url;
|
|
184
|
-
|
|
185
|
-
fn text(text: &str) -> Term {
|
|
186
|
-
Term::Const(Constant::String(text.to_owned()))
|
|
187
|
-
}
|
|
188
|
-
fn get(object: Term, key: Term) -> Term {
|
|
189
|
-
Term::Get(Box::new(object), Box::new(key))
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
#[test]
|
|
193
|
-
fn follows_both_sides_of_fallbacks_without_using_an_unreachable_assignment() {
|
|
194
|
-
let option = get(get(Term::Reg(100), text("_cf_chl_opt")), text("page"));
|
|
195
|
-
let mut listing = Listing::default();
|
|
196
|
-
let body = |effects, next| Path {
|
|
197
|
-
effects,
|
|
198
|
-
conditions: vec![],
|
|
199
|
-
exit: Exit::Next { pc: next, key: 0 },
|
|
200
|
-
};
|
|
201
|
-
for (pc, paths) in [
|
|
202
|
-
(0, vec![body(vec![Effect::Set(1, option)], 1)]),
|
|
203
|
-
(
|
|
204
|
-
1,
|
|
205
|
-
vec![body(
|
|
206
|
-
vec![Effect::Set(
|
|
207
|
-
2,
|
|
208
|
-
get(Term::Reg(1), Term::Const(Constant::Number(22.0))),
|
|
209
|
-
)],
|
|
210
|
-
2,
|
|
211
|
-
)],
|
|
212
|
-
),
|
|
213
|
-
(2, vec![body(vec![], 3), body(vec![], 4)]),
|
|
214
|
-
(3, vec![body(vec![Effect::Set(2, text(""))], 6)]),
|
|
215
|
-
(4, vec![body(vec![Effect::Set(3, Term::Reg(2))], 5)]),
|
|
216
|
-
(
|
|
217
|
-
5,
|
|
218
|
-
vec![body(
|
|
219
|
-
vec![
|
|
220
|
-
Effect::Let(
|
|
221
|
-
0,
|
|
222
|
-
Term::Call {
|
|
223
|
-
callee: Box::new(get(Term::Reg(3), text("join"))),
|
|
224
|
-
this: None,
|
|
225
|
-
arguments: vec![text("~")],
|
|
226
|
-
},
|
|
227
|
-
),
|
|
228
|
-
Effect::Set(2, Term::Temp(0)),
|
|
229
|
-
],
|
|
230
|
-
6,
|
|
231
|
-
)],
|
|
232
|
-
),
|
|
233
|
-
(6, vec![]),
|
|
234
|
-
] {
|
|
235
|
-
listing.instructions.insert(
|
|
236
|
-
pc,
|
|
237
|
-
Instruction {
|
|
238
|
-
pc,
|
|
239
|
-
key: 0,
|
|
240
|
-
opcode: 0,
|
|
241
|
-
paths,
|
|
242
|
-
},
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
let index = Index::new(&listing);
|
|
246
|
-
let sources = Sources::new(&index, &(0..=6).collect());
|
|
247
|
-
assert_eq!(
|
|
248
|
-
sources.reads(6, &Term::Reg(2)),
|
|
249
|
-
BTreeSet::from([(22, "page".to_owned())])
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
#[test]
|
|
254
|
-
fn source_walk_has_no_chain_limit_and_terminates_on_cycles() {
|
|
255
|
-
let mut listing = Listing::default();
|
|
256
|
-
for pc in 0..=40 {
|
|
257
|
-
listing.instructions.insert(
|
|
258
|
-
pc,
|
|
259
|
-
Instruction {
|
|
260
|
-
pc,
|
|
261
|
-
key: 0,
|
|
262
|
-
opcode: 0,
|
|
263
|
-
paths: vec![Path {
|
|
264
|
-
conditions: vec![],
|
|
265
|
-
effects: vec![Effect::Set(
|
|
266
|
-
1,
|
|
267
|
-
if pc == 0 {
|
|
268
|
-
get(
|
|
269
|
-
get(get(Term::Reg(100), text("_cf_chl_opt")), text("page")),
|
|
270
|
-
Term::Const(Constant::Number(22.0)),
|
|
271
|
-
)
|
|
272
|
-
} else {
|
|
273
|
-
Term::Reg(1)
|
|
274
|
-
},
|
|
275
|
-
)],
|
|
276
|
-
exit: Exit::Next { pc: pc + 1, key: 0 },
|
|
277
|
-
}],
|
|
278
|
-
},
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
let index = Index::new(&listing);
|
|
282
|
-
let sources = Sources::new(&index, &(0..=40).collect());
|
|
283
|
-
assert_eq!(
|
|
284
|
-
sources.reads(41, &Term::Reg(1)),
|
|
285
|
-
BTreeSet::from([(22, "page".to_owned())])
|
|
286
|
-
);
|
|
287
|
-
listing.instructions.get_mut(&0).unwrap().paths[0]
|
|
288
|
-
.effects
|
|
289
|
-
.clear();
|
|
290
|
-
listing.instructions.get_mut(&40).unwrap().paths[0].exit = Exit::Next { pc: 0, key: 0 };
|
|
291
|
-
let index = Index::new(&listing);
|
|
292
|
-
let sources = Sources::new(&index, &(0..=40).collect());
|
|
293
|
-
assert!(sources.reads(40, &Term::Reg(1)).is_empty());
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
#[test]
|
|
297
|
-
fn collects_positional_fields_and_applies_the_probes_fallbacks() {
|
|
298
|
-
let page = RenderedPage::render(
|
|
299
|
-
"<html><body><div class=\"cf-turnstile\" data-sitekey=\"k\"></div></body></html>",
|
|
300
|
-
Url::parse("https://example.com/").unwrap(),
|
|
301
|
-
"w",
|
|
302
|
-
None,
|
|
303
|
-
)
|
|
304
|
-
.unwrap();
|
|
305
|
-
let mut signals = page.signals(&Layout::default(), None);
|
|
306
|
-
signals.parent.reasons = vec!["one".into(), "two".into()];
|
|
307
|
-
signals.parent.pad = None;
|
|
308
|
-
let fields = Fields {
|
|
309
|
-
properties: BTreeMap::from([
|
|
310
|
-
("mode".into(), 20),
|
|
311
|
-
("reasons".into(), 22),
|
|
312
|
-
("hidden".into(), 23),
|
|
313
|
-
("visibility".into(), 25),
|
|
314
|
-
("pad".into(), 8),
|
|
315
|
-
]),
|
|
316
|
-
};
|
|
317
|
-
assert_eq!(
|
|
318
|
-
json!(fields.collect(&signals)),
|
|
319
|
-
json!({
|
|
320
|
-
"mode":"", "reasons":"one~two", "hidden":false, "visibility":"visible",
|
|
321
|
-
})
|
|
322
|
-
);
|
|
323
|
-
assert_eq!(signals.positional().as_array().unwrap().len(), 30);
|
|
324
|
-
assert_eq!(signals.positional()[19], true);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
//! Session labels replacing stable values in newer fingerprint programs.
|
|
2
|
-
|
|
3
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
4
|
-
|
|
5
|
-
use super::vocabulary;
|
|
6
|
-
use crate::listing::Index;
|
|
7
|
-
use crate::vm::{Constant, Effect, Term};
|
|
8
|
-
|
|
9
|
-
/// Parallel literal arrays hold font names and the labels returned for detected fonts.
|
|
10
|
-
/// Recover both arrays, requiring contiguous indices, equal lengths and unique labels.
|
|
11
|
-
pub(crate) fn fonts(index: &Index<'_>, entry: u32) -> Option<Vec<(String, String)>> {
|
|
12
|
-
let code = index.reachable(entry);
|
|
13
|
-
let mut arrays: BTreeMap<u32, BTreeMap<usize, String>> = BTreeMap::new();
|
|
14
|
-
for pc in code {
|
|
15
|
-
for effect in index.listing().instructions[&pc].effects() {
|
|
16
|
-
let Effect::SetProperty { object, key, value } = effect else {
|
|
17
|
-
continue;
|
|
18
|
-
};
|
|
19
|
-
let Some((created, Term::Array(_))) = index.dereference(pc, object) else {
|
|
20
|
-
continue;
|
|
21
|
-
};
|
|
22
|
-
let Some((_, Term::Const(Constant::Number(slot)))) = index.dereference(pc, key) else {
|
|
23
|
-
continue;
|
|
24
|
-
};
|
|
25
|
-
if slot < 0.0 || slot.fract() != 0.0 {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
let Some(value) = index.text(pc, value) else {
|
|
29
|
-
continue;
|
|
30
|
-
};
|
|
31
|
-
arrays
|
|
32
|
-
.entry(created)
|
|
33
|
-
.or_default()
|
|
34
|
-
.insert(slot as usize, value);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
let arrays: Vec<_> = arrays
|
|
38
|
-
.into_values()
|
|
39
|
-
.filter_map(|values| {
|
|
40
|
-
values
|
|
41
|
-
.keys()
|
|
42
|
-
.copied()
|
|
43
|
-
.eq(0..values.len())
|
|
44
|
-
.then(|| values.into_values().collect::<Vec<_>>())
|
|
45
|
-
})
|
|
46
|
-
.collect();
|
|
47
|
-
let pairs = arrays.windows(2).filter_map(|pair| {
|
|
48
|
-
let [names, labels] = pair else {
|
|
49
|
-
return None;
|
|
50
|
-
};
|
|
51
|
-
let named = ["Arial", "Georgia", "Times New Roman"]
|
|
52
|
-
.iter()
|
|
53
|
-
.all(|name| names.iter().any(|value| value == name));
|
|
54
|
-
(named
|
|
55
|
-
&& names.len() == labels.len()
|
|
56
|
-
&& labels.iter().all(|label| vocabulary::is_hex_name(label))
|
|
57
|
-
&& labels.iter().collect::<BTreeSet<_>>().len() == labels.len())
|
|
58
|
-
.then(|| labels.iter().cloned().zip(names.iter().cloned()).collect())
|
|
59
|
-
});
|
|
60
|
-
crate::candidates::exactly_one(pairs, "font labels").ok()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/// The permission-label object precedes the unchanged array of permissions to query.
|
|
64
|
-
pub(crate) fn permissions(features: &[String]) -> Option<Vec<(String, String)>> {
|
|
65
|
-
let candidates = features.windows(8).filter_map(|window| {
|
|
66
|
-
let names = ["geolocation", "notifications", "camera", "microphone"];
|
|
67
|
-
names
|
|
68
|
-
.iter()
|
|
69
|
-
.enumerate()
|
|
70
|
-
.all(|(i, name)| window[2 * i] == *name && vocabulary::is_hex_name(&window[2 * i + 1]))
|
|
71
|
-
.then_some(())
|
|
72
|
-
.filter(|()| {
|
|
73
|
-
window
|
|
74
|
-
.iter()
|
|
75
|
-
.skip(1)
|
|
76
|
-
.step_by(2)
|
|
77
|
-
.collect::<BTreeSet<_>>()
|
|
78
|
-
.len()
|
|
79
|
-
== names.len()
|
|
80
|
-
})
|
|
81
|
-
.map(|()| {
|
|
82
|
-
names
|
|
83
|
-
.into_iter()
|
|
84
|
-
.enumerate()
|
|
85
|
-
.map(|(i, name)| (window[2 * i + 1].clone(), name.to_owned()))
|
|
86
|
-
.collect()
|
|
87
|
-
})
|
|
88
|
-
});
|
|
89
|
-
crate::candidates::exactly_one(candidates, "permission labels").ok()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
#[cfg(test)]
|
|
93
|
-
mod tests {
|
|
94
|
-
use super::*;
|
|
95
|
-
use crate::vm::{Exit, Instruction, Listing, Path, Position};
|
|
96
|
-
|
|
97
|
-
#[test]
|
|
98
|
-
fn font_labels_require_parallel_complete_arrays() {
|
|
99
|
-
let text = |value: &str| Term::Const(Constant::String(value.into()));
|
|
100
|
-
let mut listing = Listing {
|
|
101
|
-
functions: vec![Position::new(0, 0)],
|
|
102
|
-
..Listing::default()
|
|
103
|
-
};
|
|
104
|
-
let names = ["Arial", "Georgia", "Times New Roman"];
|
|
105
|
-
let labels = [
|
|
106
|
-
"_111111111111111111111111",
|
|
107
|
-
"_222222222222222222222222",
|
|
108
|
-
"_333333333333333333333333",
|
|
109
|
-
];
|
|
110
|
-
let mut effects = Vec::new();
|
|
111
|
-
for (register, values) in [(1, names), (2, labels)] {
|
|
112
|
-
effects.push(Effect::Set(register, Term::Array(vec![])));
|
|
113
|
-
for (slot, value) in values.into_iter().enumerate() {
|
|
114
|
-
effects.push(Effect::SetProperty {
|
|
115
|
-
object: Box::new(Term::Reg(register)),
|
|
116
|
-
key: Box::new(Term::Const(Constant::Number(slot as f64))),
|
|
117
|
-
value: Box::new(text(value)),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
for (pc, effect) in effects.into_iter().enumerate() {
|
|
122
|
-
let pc = pc as u32;
|
|
123
|
-
listing.instructions.insert(
|
|
124
|
-
pc,
|
|
125
|
-
Instruction {
|
|
126
|
-
pc,
|
|
127
|
-
key: 0,
|
|
128
|
-
opcode: 0,
|
|
129
|
-
paths: vec![Path {
|
|
130
|
-
conditions: vec![],
|
|
131
|
-
effects: vec![effect],
|
|
132
|
-
exit: if pc == 7 {
|
|
133
|
-
Exit::Return
|
|
134
|
-
} else {
|
|
135
|
-
Exit::Next { pc: pc + 1, key: 0 }
|
|
136
|
-
},
|
|
137
|
-
}],
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
assert_eq!(
|
|
142
|
-
fonts(&Index::new(&listing), 0),
|
|
143
|
-
Some(
|
|
144
|
-
labels
|
|
145
|
-
.into_iter()
|
|
146
|
-
.zip(names)
|
|
147
|
-
.map(|(label, name)| (label.to_owned(), name.to_owned()))
|
|
148
|
-
.collect()
|
|
149
|
-
)
|
|
150
|
-
);
|
|
151
|
-
if let Effect::SetProperty { value, .. } =
|
|
152
|
-
&mut listing.instructions.get_mut(&6).unwrap().paths[0].effects[0]
|
|
153
|
-
{
|
|
154
|
-
**value = text(labels[0]);
|
|
155
|
-
}
|
|
156
|
-
assert!(
|
|
157
|
-
fonts(&Index::new(&listing), 0).is_none(),
|
|
158
|
-
"duplicate labels are ambiguous"
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
#[test]
|
|
163
|
-
fn permission_labels_must_be_unique() {
|
|
164
|
-
let features = [
|
|
165
|
-
"geolocation",
|
|
166
|
-
"_111111111111111111111111",
|
|
167
|
-
"notifications",
|
|
168
|
-
"_222222222222222222222222",
|
|
169
|
-
"camera",
|
|
170
|
-
"_333333333333333333333333",
|
|
171
|
-
"microphone",
|
|
172
|
-
"_444444444444444444444444",
|
|
173
|
-
]
|
|
174
|
-
.map(str::to_owned);
|
|
175
|
-
assert_eq!(
|
|
176
|
-
permissions(&features).unwrap()[0],
|
|
177
|
-
(features[1].clone(), "geolocation".to_owned())
|
|
178
|
-
);
|
|
179
|
-
let mut duplicate = features.clone();
|
|
180
|
-
duplicate[3] = duplicate[1].clone();
|
|
181
|
-
assert!(permissions(&duplicate).is_none());
|
|
182
|
-
let ambiguous: Vec<_> = features.iter().chain(features.iter()).cloned().collect();
|
|
183
|
-
assert!(permissions(&ambiguous).is_none());
|
|
184
|
-
}
|
|
185
|
-
}
|