cfsolve 0.1.3 → 0.1.4
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 +15 -0
- data/README.md +8 -3
- data/UPSTREAM.md +8 -2
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +1 -1
- data/vendor/cfsolve/README.md +53 -5
- data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +110 -7
- data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
- data/vendor/cfsolve/src/session/initial.rs +7 -6
- data/vendor/cfsolve/src/session/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
- data/vendor/cfsolve/src/stage2/benchmark.rs +59 -18
- data/vendor/cfsolve/src/stage2/call_stack.rs +169 -36
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
- data/vendor/cfsolve/src/stage2/probes/dates.rs +44 -0
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
- data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
- data/vendor/cfsolve/src/stage2/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/reference.rs +5 -0
- data/vendor/cfsolve/src/stage2/registry.rs +8 -2
- data/vendor/cfsolve/src/stage2/replay.rs +34 -3
- data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
- data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
- data/vendor/cfsolve/src/stage2/vocabulary.rs +111 -6
- data/vendor/cfsolve/src/stage2.rs +1 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +68 -4
- data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
- data/vendor/cfsolve/src/vm/extract.rs +246 -43
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
- data/vendor/cfsolve/src/vm/interpret/access.rs +8 -2
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +39 -1
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +33 -4
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +14 -6
- data/vendor/cfsolve/src/vm/interpret/run.rs +4 -0
- data/vendor/cfsolve/src/vm/machine.rs +63 -5
- data/vendor/cfsolve/src/vm/output.rs +6 -1
- data/vendor/cfsolve/src/vm/registers.rs +35 -21
- data/vendor/cfsolve/src/vm/session.rs +6 -3
- data/vendor/cfsolve/src/vm.rs +1 -0
- metadata +13 -1
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
}
|
|
@@ -11,7 +11,7 @@ use crate::listing::Index;
|
|
|
11
11
|
use crate::stage2::analysis::recognize::ProbeView;
|
|
12
12
|
use crate::stage2::call_stack::ProbeCalls;
|
|
13
13
|
use crate::stage2::vocabulary;
|
|
14
|
-
use crate::vm::Term;
|
|
14
|
+
use crate::vm::{Effect, Exit, Term};
|
|
15
15
|
|
|
16
16
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
17
17
|
pub struct Fields {
|
|
@@ -61,6 +61,50 @@ fn construction(index: &Index<'_>, entry: u32) -> Option<u8> {
|
|
|
61
61
|
})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/// Some builds put the property read in a one-argument getter. Accept that getter only
|
|
65
|
+
/// when every return path returns `stack`, rather than an unrelated read in its body.
|
|
66
|
+
fn stack_value(index: &Index<'_>, pc: u32, value: &Term) -> bool {
|
|
67
|
+
if index.reads(pc, value, "stack") {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
let Some((
|
|
71
|
+
at,
|
|
72
|
+
Term::Call {
|
|
73
|
+
callee, arguments, ..
|
|
74
|
+
},
|
|
75
|
+
)) = index.dereference(pc, value)
|
|
76
|
+
else {
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
if arguments.len() != 1 {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
let Some((_, Term::Closure { pc: getter, .. })) = index.dereference(at, &callee) else {
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
85
|
+
let mut returns = 0;
|
|
86
|
+
for instruction in index
|
|
87
|
+
.listing()
|
|
88
|
+
.instructions
|
|
89
|
+
.range(index.function_at(getter))
|
|
90
|
+
.map(|(_, instruction)| instruction)
|
|
91
|
+
{
|
|
92
|
+
for path in &instruction.paths {
|
|
93
|
+
if path.exit != Exit::Return {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
let Some(Effect::Set(_, returned)) = path.effects.first() else {
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
if !index.reads(instruction.pc, returned, "stack") {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
returns += 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
returns > 0
|
|
106
|
+
}
|
|
107
|
+
|
|
64
108
|
/// Finds the output field hidden by base64 encoding and a two-byte XOR key. A name that decodes to
|
|
65
109
|
/// `stack` identifies the key. The output field is the remaining name after excluding `stack` and
|
|
66
110
|
/// the record counter from the header. Builds with hex names encode only `stack`.
|
|
@@ -142,17 +186,86 @@ fn result_field(features: &[String], header: &BTreeSet<String>) -> Option<String
|
|
|
142
186
|
}
|
|
143
187
|
|
|
144
188
|
pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
189
|
+
let calls = calls(probe.index, probe.entry);
|
|
145
190
|
result_field(probe.session_features, probe.header)
|
|
146
191
|
.or_else(|| encoded_result_field(probe.session_features, probe.header))
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
192
|
+
.or_else(|| {
|
|
193
|
+
calls?;
|
|
194
|
+
let code = probe.index.reachable(probe.entry);
|
|
195
|
+
let fields: BTreeSet<_> = probe
|
|
196
|
+
.index
|
|
197
|
+
.stores()
|
|
198
|
+
.iter()
|
|
199
|
+
.filter(|store| {
|
|
200
|
+
code.contains(&store.pc) && stack_value(probe.index, store.pc, &store.value)
|
|
201
|
+
})
|
|
202
|
+
.map(|store| store.key.clone())
|
|
203
|
+
.collect();
|
|
204
|
+
candidates::exactly_one(fields, "stack result field").ok()
|
|
150
205
|
})
|
|
206
|
+
.map(|result| Fields { result, calls })
|
|
151
207
|
}
|
|
152
208
|
|
|
153
209
|
#[cfg(test)]
|
|
154
210
|
mod tests {
|
|
155
211
|
use super::*;
|
|
212
|
+
use crate::vm::{Constant, Instruction, Listing, Path, Position};
|
|
213
|
+
|
|
214
|
+
#[test]
|
|
215
|
+
fn follows_stack_getters_but_rejects_other_return_values() {
|
|
216
|
+
let text = |value: &str| Term::Const(Constant::String(value.into()));
|
|
217
|
+
let mut listing = Listing {
|
|
218
|
+
functions: vec![Position::new(0, 0), Position::new(10, 0)],
|
|
219
|
+
..Listing::default()
|
|
220
|
+
};
|
|
221
|
+
let mut insert = |pc, effects, exit| {
|
|
222
|
+
listing.instructions.insert(
|
|
223
|
+
pc,
|
|
224
|
+
Instruction {
|
|
225
|
+
pc,
|
|
226
|
+
key: 0,
|
|
227
|
+
opcode: 0,
|
|
228
|
+
paths: vec![Path {
|
|
229
|
+
conditions: vec![],
|
|
230
|
+
effects,
|
|
231
|
+
exit,
|
|
232
|
+
}],
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
insert(
|
|
237
|
+
0,
|
|
238
|
+
vec![Effect::Set(
|
|
239
|
+
2,
|
|
240
|
+
Term::Closure {
|
|
241
|
+
pc: 10,
|
|
242
|
+
key: 0,
|
|
243
|
+
parameters: vec![1],
|
|
244
|
+
arity: 1,
|
|
245
|
+
},
|
|
246
|
+
)],
|
|
247
|
+
Exit::Next { pc: 1, key: 0 },
|
|
248
|
+
);
|
|
249
|
+
insert(1, vec![], Exit::Return);
|
|
250
|
+
insert(
|
|
251
|
+
10,
|
|
252
|
+
vec![Effect::Set(
|
|
253
|
+
3,
|
|
254
|
+
Term::Get(Box::new(Term::Reg(1)), Box::new(text("stack"))),
|
|
255
|
+
)],
|
|
256
|
+
Exit::Next { pc: 11, key: 0 },
|
|
257
|
+
);
|
|
258
|
+
insert(11, vec![Effect::Set(225, Term::Reg(3))], Exit::Return);
|
|
259
|
+
let call = Term::Call {
|
|
260
|
+
callee: Box::new(Term::Reg(2)),
|
|
261
|
+
this: None,
|
|
262
|
+
arguments: vec![Term::Reg(4)],
|
|
263
|
+
};
|
|
264
|
+
assert!(stack_value(&Index::new(&listing), 1, &call));
|
|
265
|
+
listing.instructions.get_mut(&11).unwrap().paths[0].effects =
|
|
266
|
+
vec![Effect::Set(225, text("unrelated"))];
|
|
267
|
+
assert!(!stack_value(&Index::new(&listing), 1, &call));
|
|
268
|
+
}
|
|
156
269
|
|
|
157
270
|
/// String-table fixtures from `oct07` and `auto07`, with reversed entries, different
|
|
158
271
|
/// separators, record counter `MpnR7`, and output `KtSk9` among checksums.
|
|
@@ -170,12 +170,15 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
|
170
170
|
received: received.clone(),
|
|
171
171
|
opened: opened.clone(),
|
|
172
172
|
round_trips: before(&["JSON", "stringify"])?,
|
|
173
|
-
elapsed: before(&["String", "Date", "now"])
|
|
173
|
+
elapsed: before(&["String", "Date", "now"])
|
|
174
|
+
.or_else(|| before(&["String", "now"]))
|
|
175
|
+
.or_else(|| before(&["now"]))?,
|
|
174
176
|
statuses: Statuses {
|
|
175
177
|
complete: complete.clone(),
|
|
176
178
|
incomplete: incomplete.clone(),
|
|
177
179
|
timed_out: before(&["String", "Math", "round"])
|
|
178
|
-
.or_else(|| before(&["String", "round"]))
|
|
180
|
+
.or_else(|| before(&["String", "round"]))
|
|
181
|
+
.or_else(|| before(&["round"]))?,
|
|
179
182
|
failed_before_open: failed_before_open.clone(),
|
|
180
183
|
failed_after_open: failed_after_open.clone(),
|
|
181
184
|
closed: closed.clone(),
|
|
@@ -200,6 +203,81 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
|
200
203
|
mod tests {
|
|
201
204
|
use super::*;
|
|
202
205
|
|
|
206
|
+
#[test]
|
|
207
|
+
fn recognizes_builtins_loaded_from_the_header() {
|
|
208
|
+
use crate::listing::Index;
|
|
209
|
+
use crate::stage2::analysis::recognize::Strings;
|
|
210
|
+
use crate::stage2::records::WriteOrder;
|
|
211
|
+
use crate::stage2::vocabulary::Vocabulary;
|
|
212
|
+
use crate::vm::Listing;
|
|
213
|
+
use std::collections::BTreeSet;
|
|
214
|
+
|
|
215
|
+
let features: Vec<String> = [
|
|
216
|
+
"rtts",
|
|
217
|
+
"JSON",
|
|
218
|
+
"stringify",
|
|
219
|
+
"elapsed",
|
|
220
|
+
"now",
|
|
221
|
+
"readyState",
|
|
222
|
+
"close",
|
|
223
|
+
"status",
|
|
224
|
+
"sent",
|
|
225
|
+
"received",
|
|
226
|
+
"opened",
|
|
227
|
+
"error",
|
|
228
|
+
"length",
|
|
229
|
+
"complete",
|
|
230
|
+
"incomplete",
|
|
231
|
+
"send",
|
|
232
|
+
"performance",
|
|
233
|
+
"now",
|
|
234
|
+
"timeout",
|
|
235
|
+
"round",
|
|
236
|
+
"performance",
|
|
237
|
+
"now",
|
|
238
|
+
"isFinite",
|
|
239
|
+
"",
|
|
240
|
+
"after",
|
|
241
|
+
"before",
|
|
242
|
+
"closed",
|
|
243
|
+
"WebSocket",
|
|
244
|
+
"platform",
|
|
245
|
+
"/w",
|
|
246
|
+
"onopen",
|
|
247
|
+
"onmessage",
|
|
248
|
+
"onclose",
|
|
249
|
+
]
|
|
250
|
+
.map(str::to_owned)
|
|
251
|
+
.to_vec();
|
|
252
|
+
let writes = WriteOrder {
|
|
253
|
+
fields: ["status", "sent", "received", "opened", "rtts", "elapsed"]
|
|
254
|
+
.map(str::to_owned)
|
|
255
|
+
.to_vec(),
|
|
256
|
+
..WriteOrder::default()
|
|
257
|
+
};
|
|
258
|
+
let listing = Listing::default();
|
|
259
|
+
let index = Index::new(&listing);
|
|
260
|
+
let vocabulary = Vocabulary::infer(&[&features]);
|
|
261
|
+
let empty = BTreeSet::new();
|
|
262
|
+
let fields = recognize(&ProbeView {
|
|
263
|
+
index: &index,
|
|
264
|
+
vocabulary: &vocabulary,
|
|
265
|
+
position: 0,
|
|
266
|
+
header: &empty,
|
|
267
|
+
wrapper: &empty,
|
|
268
|
+
pool: "",
|
|
269
|
+
entry: 0,
|
|
270
|
+
session_features: &features,
|
|
271
|
+
writes: &writes,
|
|
272
|
+
strings: Strings::new(&features, &empty),
|
|
273
|
+
})
|
|
274
|
+
.unwrap();
|
|
275
|
+
assert_eq!(fields.elapsed, "elapsed");
|
|
276
|
+
assert_eq!(fields.round_trips, "rtts");
|
|
277
|
+
assert_eq!(fields.statuses.timed_out, "timeout");
|
|
278
|
+
assert_eq!(fields.statuses.failed_after_open, "after");
|
|
279
|
+
}
|
|
280
|
+
|
|
203
281
|
fn fields() -> Fields {
|
|
204
282
|
Fields {
|
|
205
283
|
platform: "ppebL7".into(),
|
|
@@ -124,6 +124,9 @@ pub(crate) const NETWORK_INFORMATION_OUTPUTS: [&str; 6] = [
|
|
|
124
124
|
];
|
|
125
125
|
|
|
126
126
|
pub(crate) const PARENT_INFO_REFERRER: &str = "_31a6173d1692e77e5a1005d5";
|
|
127
|
+
/// Parent-page values copied by the document-structure probe.
|
|
128
|
+
pub(crate) const DOCUMENT_ROOT_ATTRIBUTES: &str = "_188bd52b36251eaae9a99374";
|
|
129
|
+
pub(crate) const DOCUMENT_CUSTOM_ELEMENTS: &str = "_301060c5326f9477769f5d8b";
|
|
127
130
|
pub(crate) const PARENT_INFO_MISSING: &str = "_10450802c4fb954516e0c07b";
|
|
128
131
|
pub(crate) const PARENT_INFO_REASONS: &str = "_cd7d13df270697c8781d261c";
|
|
129
132
|
pub(crate) const PARENT_INFO_VISIBILITY: &str = "_4172551fe148377bcda1f7b5";
|
|
@@ -200,6 +203,8 @@ mod tests {
|
|
|
200
203
|
(Kind::EnvironmentAudit, ENVIRONMENT_AUDIT_SECURE),
|
|
201
204
|
(Kind::EnvironmentAudit, ENVIRONMENT_AUDIT_PERMISSION),
|
|
202
205
|
(Kind::ErrorMessageLength, ERROR_MESSAGE_LENGTH_RESULT),
|
|
206
|
+
(Kind::DocumentStructure, DOCUMENT_ROOT_ATTRIBUTES),
|
|
207
|
+
(Kind::DocumentStructure, DOCUMENT_CUSTOM_ELEMENTS),
|
|
203
208
|
(Kind::Image, PLATFORM_OPTION),
|
|
204
209
|
(Kind::Image, IMAGE_WIDTH),
|
|
205
210
|
(Kind::Image, IMAGE_HEIGHT),
|
|
@@ -14,8 +14,8 @@ use serde::{Deserialize, Serialize};
|
|
|
14
14
|
use super::analysis::recognize::{Phase, ProbeView};
|
|
15
15
|
use super::probes::{
|
|
16
16
|
clock, dates, dom_mutation, empty, error_message_length, host_reachability, image, media,
|
|
17
|
-
network_information, parent_info, performance, private_token, rects, stack,
|
|
18
|
-
worker_fetch, worker_navigator,
|
|
17
|
+
network_information, parent_info, parent_info_array, performance, private_token, rects, stack,
|
|
18
|
+
websocket_echo, worker_fetch, worker_navigator,
|
|
19
19
|
};
|
|
20
20
|
use super::{benchmark, proof};
|
|
21
21
|
use crate::embedding_page::page::PageSignals;
|
|
@@ -166,6 +166,8 @@ families! {
|
|
|
166
166
|
image, "image", Reference, Computed, [33];
|
|
167
167
|
ParentInfo {} =>
|
|
168
168
|
parent_info, "parent_info", Reference, Computed, [7];
|
|
169
|
+
ParentInfoArray { fields: parent_info_array::Fields } =>
|
|
170
|
+
parent_info_array, "parent_info_array", Structural, Computed, [];
|
|
169
171
|
DateParsingOffsets(dates::Fields) =>
|
|
170
172
|
dates, "date_parsing_offsets", Reference, Computed, [21];
|
|
171
173
|
// The payload publishes the error-message length beside the record.
|
|
@@ -370,6 +372,10 @@ impl Operation {
|
|
|
370
372
|
observed.page_signals.as_ref(),
|
|
371
373
|
"the embedding page's signals",
|
|
372
374
|
)?)),
|
|
375
|
+
Self::ParentInfoArray { fields } => Ok(fields.collect(measured(
|
|
376
|
+
observed.page_signals.as_ref(),
|
|
377
|
+
"the embedding page's signals",
|
|
378
|
+
)?)),
|
|
373
379
|
Self::DateParsingOffsets(fields) => fields.collect(engine),
|
|
374
380
|
Self::NetworkInformation(fields) => {
|
|
375
381
|
let connection = facts.connection.as_ref();
|