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,55 +1,293 @@
|
|
|
1
1
|
//! Builds a probe record from the embedding page's signals.
|
|
2
|
+
//!
|
|
3
|
+
//! The probe reads the `wPr` array the embedding page sent (see [`PageSignals::elements`]),
|
|
4
|
+
//! which the iframe keeps in a `_cf_chl_opt` option, and copies some of its elements into its
|
|
5
|
+
//! record: as they are, with `""` for falsy values, or joined into a string. Recognition follows
|
|
6
|
+
//! the probe's code to recover each output field's element and treatment.
|
|
7
|
+
|
|
8
|
+
use std::collections::BTreeMap;
|
|
9
|
+
use std::convert::Infallible;
|
|
10
|
+
use std::ops::ControlFlow;
|
|
11
|
+
|
|
12
|
+
use indexmap::IndexMap;
|
|
13
|
+
use oxc::syntax::operator::{BinaryOperator, UnaryOperator};
|
|
14
|
+
use serde::{Deserialize, Serialize};
|
|
2
15
|
|
|
3
16
|
use crate::embedding_page::page::PageSignals;
|
|
4
|
-
use crate::js::{self, JsObject, json};
|
|
17
|
+
use crate::js::{self, JsObject, JsValue, json};
|
|
5
18
|
use crate::stage2::analysis::recognize::ProbeView;
|
|
6
|
-
use crate::
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
///
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
use crate::vm::dataflow::{self, Facts};
|
|
20
|
+
use crate::vm::{Constant, Effect, Path, Term};
|
|
21
|
+
|
|
22
|
+
/// The option holding the signals.
|
|
23
|
+
const OPTIONS: &str = "_cf_chl_opt";
|
|
24
|
+
|
|
25
|
+
/// The fewest copied elements that identify the probe. The probe copies 26.
|
|
26
|
+
const MINIMUM_READS: usize = 20;
|
|
27
|
+
|
|
28
|
+
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
29
|
+
pub struct Fields {
|
|
30
|
+
/// Each output field and what it holds, in the order the probe writes them.
|
|
31
|
+
pub reads: IndexMap<String, Read>,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// What an output field holds, from the signals array `signals`.
|
|
35
|
+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
|
36
|
+
#[serde(tag = "kind", rename_all = "snake_case")]
|
|
37
|
+
pub enum Read {
|
|
38
|
+
/// `signals[index]`.
|
|
39
|
+
Element { index: usize },
|
|
40
|
+
/// `signals[index] || ""`.
|
|
41
|
+
OrEmpty { index: usize },
|
|
42
|
+
/// `signals[index] && signals[index].join ? signals[index].join(separator) : ""`.
|
|
43
|
+
Joined { index: usize, separator: String },
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
impl Fields {
|
|
47
|
+
/// The record the probe writes from `signals`. Fields holding `undefined` are left out, as
|
|
48
|
+
/// the payload's JSON leaves them out.
|
|
49
|
+
#[must_use]
|
|
50
|
+
pub(crate) fn collect(&self, signals: &PageSignals) -> JsObject {
|
|
51
|
+
let elements = signals.elements();
|
|
52
|
+
let element = |index: usize| elements.get(index).cloned().unwrap_or(JsValue::Undefined);
|
|
53
|
+
let mut record = JsObject::new();
|
|
54
|
+
for (field, read) in &self.reads {
|
|
55
|
+
let value = match read {
|
|
56
|
+
Read::Element { index } => element(*index),
|
|
57
|
+
Read::OrEmpty { index } => {
|
|
58
|
+
let value = element(*index);
|
|
59
|
+
if js::truthy(&value) { value } else { json!("") }
|
|
60
|
+
}
|
|
61
|
+
// Only arrays have `join`, which writes `null` and `undefined` as empty strings.
|
|
62
|
+
Read::Joined { index, separator } => match element(*index) {
|
|
63
|
+
JsValue::Array(items) => {
|
|
64
|
+
let items: Vec<String> = items
|
|
65
|
+
.iter()
|
|
66
|
+
.map(|item| match item {
|
|
67
|
+
JsValue::Undefined | JsValue::Null => String::new(),
|
|
68
|
+
item => js::string(Some(item)),
|
|
69
|
+
})
|
|
70
|
+
.collect();
|
|
71
|
+
json!(items.join(separator))
|
|
72
|
+
}
|
|
73
|
+
_ => json!(""),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
if !value.is_undefined() {
|
|
77
|
+
record.insert(field.clone(), value);
|
|
78
|
+
}
|
|
23
79
|
}
|
|
80
|
+
record
|
|
24
81
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
85
|
+
let index = probe.index;
|
|
86
|
+
let listing = index.listing();
|
|
87
|
+
// The probe copies the signals in a function it creates.
|
|
88
|
+
let entries = (index.reachable(probe.entry).into_iter())
|
|
89
|
+
.filter(|&pc| pc == probe.entry || index.is_entry(pc))
|
|
90
|
+
.map(|pc| (pc, Registers::default()));
|
|
91
|
+
let ControlFlow::Continue(incoming) = dataflow::forward(listing, entries, |_, path, known| {
|
|
92
|
+
ControlFlow::<Infallible, bool>::Continue(transfer(path, known).is_some())
|
|
93
|
+
});
|
|
94
|
+
// Every read must come from the same option.
|
|
95
|
+
let mut signals = None;
|
|
96
|
+
// Each stored field's read and the first instruction storing it.
|
|
97
|
+
let mut stores: BTreeMap<String, (u32, Read)> = BTreeMap::new();
|
|
98
|
+
for (&pc, known) in &incoming {
|
|
99
|
+
for path in &listing.instructions[&pc].paths {
|
|
100
|
+
let Some(temporaries) = transfer(path, &mut known.clone()) else {
|
|
101
|
+
continue;
|
|
102
|
+
};
|
|
103
|
+
for effect in &path.effects {
|
|
104
|
+
let Effect::SetProperty { key, value, .. } = effect else {
|
|
105
|
+
continue;
|
|
106
|
+
};
|
|
107
|
+
let held = |term| held(term, known, &temporaries);
|
|
108
|
+
let (Some(Held::Text(field)), Some(Held::Read(option, read))) =
|
|
109
|
+
(held(key), held(value))
|
|
110
|
+
else {
|
|
111
|
+
continue;
|
|
112
|
+
};
|
|
113
|
+
if *signals.get_or_insert_with(|| option.clone()) != option {
|
|
114
|
+
return None;
|
|
115
|
+
}
|
|
116
|
+
let (_, stored) = stores.entry(field).or_insert_with(|| (pc, read.clone()));
|
|
117
|
+
if *stored != read {
|
|
118
|
+
return None;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let mut stores: Vec<(String, (u32, Read))> = stores.into_iter().collect();
|
|
124
|
+
stores.sort_by_key(|(_, (pc, _))| *pc);
|
|
125
|
+
let joined = (stores.iter())
|
|
126
|
+
.filter(|(_, (_, read))| matches!(read, Read::Joined { .. }))
|
|
127
|
+
.count();
|
|
128
|
+
if stores.len() < MINIMUM_READS || joined != 1 {
|
|
129
|
+
return None;
|
|
130
|
+
}
|
|
131
|
+
let reads = stores
|
|
132
|
+
.into_iter()
|
|
133
|
+
.map(|(field, (_, read))| (field, read))
|
|
134
|
+
.collect();
|
|
135
|
+
Some(Fields { reads })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/// What a register or temporary holds.
|
|
139
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
140
|
+
enum Held {
|
|
141
|
+
Undefined,
|
|
142
|
+
Text(String),
|
|
143
|
+
Number(f64),
|
|
144
|
+
/// `_cf_chl_opt`.
|
|
145
|
+
Options,
|
|
146
|
+
/// The signals array, by the option holding it.
|
|
147
|
+
Signals(String),
|
|
148
|
+
/// An element or a value made from one, by the option holding the array.
|
|
149
|
+
Read(String, Read),
|
|
150
|
+
/// `signals[index].join`.
|
|
151
|
+
Join(String, usize),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// What registers hold on entry to an instruction.
|
|
155
|
+
#[derive(Clone, Debug, Default, PartialEq)]
|
|
156
|
+
struct Registers(BTreeMap<u8, Held>);
|
|
157
|
+
|
|
158
|
+
impl Facts for Registers {
|
|
159
|
+
/// Keeps what both sides agree on. An element on one side and `""` on the other, where
|
|
160
|
+
/// `x || ""` and its compiled `x ? x : ""` meet, hold `x || ""`.
|
|
161
|
+
fn meet(&mut self, other: &Self) -> bool {
|
|
162
|
+
let before = self.0.clone();
|
|
163
|
+
self.0.retain(|register, held| {
|
|
164
|
+
let Some(other) = other.0.get(register) else {
|
|
165
|
+
return false;
|
|
166
|
+
};
|
|
167
|
+
if held != other {
|
|
168
|
+
let Some(met) = either(held, other) else {
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
*held = met;
|
|
172
|
+
}
|
|
173
|
+
true
|
|
174
|
+
});
|
|
175
|
+
self.0 != before
|
|
31
176
|
}
|
|
32
|
-
fields.insert(
|
|
33
|
-
PARENT_INFO_VISIBILITY.to_owned(),
|
|
34
|
-
json!(parent.viewport.visibility_state),
|
|
35
|
-
);
|
|
36
|
-
fields.insert(
|
|
37
|
-
PARENT_INFO_REASONS.to_owned(),
|
|
38
|
-
json!(parent.reasons.join("~")),
|
|
39
|
-
);
|
|
40
|
-
fields
|
|
41
177
|
}
|
|
42
178
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
179
|
+
/// The value `x || ""` when one side holds `x` and the other `""` or `x || ""`.
|
|
180
|
+
fn either(left: &Held, right: &Held) -> Option<Held> {
|
|
181
|
+
let or_empty = |held: &Held| match held {
|
|
182
|
+
Held::Read(option, Read::Element { index } | Read::OrEmpty { index }) => {
|
|
183
|
+
Some(Held::Read(option.clone(), Read::OrEmpty { index: *index }))
|
|
184
|
+
}
|
|
185
|
+
Held::Read(_, Read::Joined { .. }) => Some(held.clone()),
|
|
186
|
+
_ => None,
|
|
187
|
+
};
|
|
188
|
+
match (left, right) {
|
|
189
|
+
(read, other) | (other, read) if *other == Held::Text(String::new()) => or_empty(read),
|
|
190
|
+
_ => or_empty(left).filter(|met| or_empty(right).as_ref() == Some(met)),
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Applies `path` to `known`, returning its temporaries, or `None` if the path cannot run.
|
|
195
|
+
/// Terms read registers as they were when the instruction started.
|
|
196
|
+
fn transfer(path: &Path, known: &mut Registers) -> Option<BTreeMap<usize, Held>> {
|
|
197
|
+
let mut temporaries = BTreeMap::new();
|
|
198
|
+
let mut writes = Vec::new();
|
|
199
|
+
for effect in &path.effects {
|
|
200
|
+
match effect {
|
|
201
|
+
Effect::Let(temporary, term) => {
|
|
202
|
+
let value = held(term, known, &temporaries);
|
|
203
|
+
dataflow::assign(&mut temporaries, *temporary, value);
|
|
204
|
+
}
|
|
205
|
+
Effect::Set(register, term) => {
|
|
206
|
+
writes.push((*register, held(term, known, &temporaries)));
|
|
207
|
+
}
|
|
208
|
+
_ => {}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (condition, expected) in &path.conditions {
|
|
212
|
+
if undefined(condition, known, &temporaries).is_some_and(|actual| actual != *expected) {
|
|
213
|
+
return None;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (register, value) in writes {
|
|
217
|
+
dataflow::assign(&mut known.0, register, value);
|
|
218
|
+
}
|
|
219
|
+
Some(temporaries)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Decides `x === undefined` and its negations when `x` holds something known. Everything held
|
|
223
|
+
/// besides `undefined` is taken to be defined: the probe reads the options and checks the
|
|
224
|
+
/// signals before copying them, so these comparisons are its call handlers choosing the
|
|
225
|
+
/// receiverless call form, and its missing-signals branch, which copies no elements.
|
|
226
|
+
fn undefined(
|
|
227
|
+
condition: &Term,
|
|
228
|
+
known: &Registers,
|
|
229
|
+
temporaries: &BTreeMap<usize, Held>,
|
|
230
|
+
) -> Option<bool> {
|
|
231
|
+
match condition {
|
|
232
|
+
Term::Unary(UnaryOperator::LogicalNot, inner) => {
|
|
233
|
+
undefined(inner, known, temporaries).map(|value| !value)
|
|
234
|
+
}
|
|
235
|
+
Term::Binary(
|
|
236
|
+
operator @ (BinaryOperator::StrictEquality | BinaryOperator::StrictInequality),
|
|
237
|
+
left,
|
|
238
|
+
right,
|
|
239
|
+
) => {
|
|
240
|
+
let operand = match (&**left, &**right) {
|
|
241
|
+
(operand, Term::Const(Constant::Undefined))
|
|
242
|
+
| (Term::Const(Constant::Undefined), operand) => operand,
|
|
243
|
+
_ => return None,
|
|
244
|
+
};
|
|
245
|
+
let equal = held(operand, known, temporaries)? == Held::Undefined;
|
|
246
|
+
Some(equal == (*operator == BinaryOperator::StrictEquality))
|
|
247
|
+
}
|
|
248
|
+
_ => None,
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn held(term: &Term, known: &Registers, temporaries: &BTreeMap<usize, Held>) -> Option<Held> {
|
|
253
|
+
let held = |term| held(term, known, temporaries);
|
|
254
|
+
Some(match term {
|
|
255
|
+
Term::Const(Constant::Undefined) => Held::Undefined,
|
|
256
|
+
Term::Const(Constant::String(text)) => Held::Text(text.clone()),
|
|
257
|
+
Term::Const(Constant::Number(number)) => Held::Number(*number),
|
|
258
|
+
Term::Reg(register) => known.0.get(register)?.clone(),
|
|
259
|
+
Term::Temp(temporary) => temporaries.get(temporary)?.clone(),
|
|
260
|
+
Term::Get(object, key) => match (held(object), held(key)?) {
|
|
261
|
+
(_, Held::Text(key)) if key == OPTIONS => Held::Options,
|
|
262
|
+
(Some(Held::Options), Held::Text(option)) => Held::Signals(option),
|
|
263
|
+
(Some(Held::Signals(option)), Held::Number(index))
|
|
264
|
+
if index >= 0.0 && index.fract() == 0.0 =>
|
|
265
|
+
{
|
|
266
|
+
Held::Read(
|
|
267
|
+
option,
|
|
268
|
+
Read::Element {
|
|
269
|
+
index: index as usize,
|
|
270
|
+
},
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
(Some(Held::Read(option, Read::Element { index })), Held::Text(key))
|
|
274
|
+
if key == "join" =>
|
|
275
|
+
{
|
|
276
|
+
Held::Join(option, index)
|
|
277
|
+
}
|
|
278
|
+
_ => return None,
|
|
279
|
+
},
|
|
280
|
+
Term::Call {
|
|
281
|
+
callee, arguments, ..
|
|
282
|
+
} => match (held(callee)?, arguments.as_slice()) {
|
|
283
|
+
(Held::Join(option, index), [separator]) => match held(separator)? {
|
|
284
|
+
Held::Text(separator) => Held::Read(option, Read::Joined { index, separator }),
|
|
285
|
+
_ => return None,
|
|
286
|
+
},
|
|
287
|
+
_ => return None,
|
|
288
|
+
},
|
|
289
|
+
_ => return None,
|
|
290
|
+
})
|
|
53
291
|
}
|
|
54
292
|
|
|
55
293
|
#[cfg(test)]
|
|
@@ -60,7 +298,7 @@ mod tests {
|
|
|
60
298
|
use crate::embedding_page::page::{Layout, RenderedPage};
|
|
61
299
|
|
|
62
300
|
#[test]
|
|
63
|
-
fn
|
|
301
|
+
fn copies_elements_as_the_probe_reads_them() {
|
|
64
302
|
let page = RenderedPage::render(
|
|
65
303
|
"<html><body><div class=\"cf-turnstile\" data-sitekey=\"k\"></div></body></html>",
|
|
66
304
|
Url::parse("https://example.com/").unwrap(),
|
|
@@ -72,25 +310,71 @@ mod tests {
|
|
|
72
310
|
referrer: "https://example.com/from".into(),
|
|
73
311
|
..Layout::default()
|
|
74
312
|
};
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
|
|
313
|
+
let mut signals = page.signals(&layout, None);
|
|
314
|
+
signals.parent.reasons = vec!["new".into(), "api".into()];
|
|
315
|
+
let fields = Fields {
|
|
316
|
+
reads: IndexMap::from([
|
|
317
|
+
("referrer".into(), Read::OrEmpty { index: 2 }),
|
|
318
|
+
("hidden".into(), Read::Element { index: 23 }),
|
|
319
|
+
("scripts".into(), Read::Element { index: 10 }),
|
|
320
|
+
("mode".into(), Read::OrEmpty { index: 20 }),
|
|
321
|
+
("mount".into(), Read::OrEmpty { index: 21 }),
|
|
322
|
+
(
|
|
323
|
+
"reasons".into(),
|
|
324
|
+
Read::Joined {
|
|
325
|
+
index: 22,
|
|
326
|
+
separator: "~".into(),
|
|
327
|
+
},
|
|
328
|
+
),
|
|
329
|
+
("past".into(), Read::Element { index: 30 }),
|
|
330
|
+
]),
|
|
83
331
|
};
|
|
84
|
-
assert_eq!(record[PARENT_INFO_REFERRER], "https://example.com/from");
|
|
85
|
-
assert_eq!(*field("vDuh"), false);
|
|
86
|
-
assert_eq!(*field("sL"), 0);
|
|
87
332
|
assert_eq!(
|
|
88
|
-
|
|
89
|
-
"",
|
|
90
|
-
|
|
333
|
+
JsValue::Object(fields.collect(&signals)),
|
|
334
|
+
json!({"referrer": "https://example.com/from", "hidden": false, "scripts": 0,
|
|
335
|
+
"mode": "", "mount": "wrapper", "reasons": "new~api"}),
|
|
336
|
+
"a falsy mode reads as empty, and an element past the end is left out"
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
fn get(object: Term, key: Term) -> Term {
|
|
341
|
+
Term::Get(Box::new(object), Box::new(key))
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
#[test]
|
|
345
|
+
fn an_element_and_an_empty_string_meeting_are_the_element_or_empty() {
|
|
346
|
+
let option = || "_a6e6c612eb1e0cc1f917227c".to_owned();
|
|
347
|
+
let element = Held::Read(option(), Read::Element { index: 21 });
|
|
348
|
+
let mut left = Registers(BTreeMap::from([(1, element.clone()), (2, element.clone())]));
|
|
349
|
+
let right = Registers(BTreeMap::from([
|
|
350
|
+
(1, Held::Text(String::new())),
|
|
351
|
+
(2, Held::Text("x".into())),
|
|
352
|
+
]));
|
|
353
|
+
assert!(left.meet(&right));
|
|
354
|
+
assert_eq!(
|
|
355
|
+
left,
|
|
356
|
+
Registers(BTreeMap::from([(
|
|
357
|
+
1,
|
|
358
|
+
Held::Read(option(), Read::OrEmpty { index: 21 })
|
|
359
|
+
)]))
|
|
360
|
+
);
|
|
361
|
+
let known = Registers(BTreeMap::from([
|
|
362
|
+
(12, Held::Options),
|
|
363
|
+
(13, Held::Text(option())),
|
|
364
|
+
(14, Held::Number(22.0)),
|
|
365
|
+
]));
|
|
366
|
+
let signals = get(Term::Reg(12), Term::Reg(13));
|
|
367
|
+
assert_eq!(
|
|
368
|
+
held(&get(signals, Term::Reg(14)), &known, &BTreeMap::new()),
|
|
369
|
+
Some(Held::Read(option(), Read::Element { index: 22 }))
|
|
370
|
+
);
|
|
371
|
+
assert_eq!(
|
|
372
|
+
held(
|
|
373
|
+
&get(Term::Reg(9), Term::Const(Constant::String(OPTIONS.into()))),
|
|
374
|
+
&known,
|
|
375
|
+
&BTreeMap::new()
|
|
376
|
+
),
|
|
377
|
+
Some(Held::Options)
|
|
91
378
|
);
|
|
92
|
-
assert_eq!(*field("vDmt"), "wrapper");
|
|
93
|
-
assert_eq!(record[PARENT_INFO_VISIBILITY], "visible");
|
|
94
|
-
assert_eq!(record[PARENT_INFO_REASONS], "");
|
|
95
379
|
}
|
|
96
380
|
}
|
|
@@ -11,11 +11,12 @@ use serde::{Deserialize, Serialize};
|
|
|
11
11
|
use crate::engine::Engine;
|
|
12
12
|
use crate::js::{JsObject, JsValue, json};
|
|
13
13
|
use crate::listing::fold::{self, Frame, Known};
|
|
14
|
+
use crate::listing::query;
|
|
14
15
|
use crate::resource_timing::{LoadTiming, NEXT_HOP_PROTOCOL};
|
|
15
16
|
use crate::stage2::analysis::recognize::ProbeView;
|
|
16
17
|
use crate::stage2::records::ProbePlan;
|
|
17
18
|
use crate::stage2::registry::Operation;
|
|
18
|
-
use crate::vm::{Effect, Exit, Listing, Term, dataflow};
|
|
19
|
+
use crate::vm::{Effect, Exit, Instruction, Listing, Term, dataflow};
|
|
19
20
|
|
|
20
21
|
/// How the probe writes the row of one entry type.
|
|
21
22
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
@@ -184,6 +185,8 @@ enum Held {
|
|
|
184
185
|
Duration,
|
|
185
186
|
/// A property of another object, such as the record holding the output list.
|
|
186
187
|
Field(String),
|
|
188
|
+
/// A property of such a property, such as `performance.mark` read from the global object.
|
|
189
|
+
Member(String),
|
|
187
190
|
/// A string starting with this text.
|
|
188
191
|
Prefixed(String),
|
|
189
192
|
}
|
|
@@ -218,7 +221,31 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
|
218
221
|
});
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
|
-
|
|
224
|
+
// Some builds read a property name from a register that an earlier block of the same
|
|
225
|
+
// function loaded. Registers every assignment in a function's own code sets to the same
|
|
226
|
+
// string hold it wherever that function reads them.
|
|
227
|
+
let fixed = |entry: u32| {
|
|
228
|
+
let mut assigned: BTreeMap<u8, Option<String>> = BTreeMap::new();
|
|
229
|
+
let assign = |_, instruction: &Instruction, pending: &mut Vec<u32>| {
|
|
230
|
+
pending.extend(instruction.exits());
|
|
231
|
+
for effect in instruction.effects() {
|
|
232
|
+
if let Effect::Set(register, value) = effect {
|
|
233
|
+
let text = value.string().map(str::to_owned);
|
|
234
|
+
let known = assigned.entry(*register).or_insert_with(|| text.clone());
|
|
235
|
+
if *known != text {
|
|
236
|
+
*known = None;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
query::walk(listing, entry, |_| true, assign);
|
|
242
|
+
let fixed: BTreeMap<u8, String> = assigned
|
|
243
|
+
.into_iter()
|
|
244
|
+
.filter_map(|(register, text)| Some((register, text?)))
|
|
245
|
+
.collect();
|
|
246
|
+
Frame::seeded(&fixed)
|
|
247
|
+
};
|
|
248
|
+
let starts = entries.into_iter().map(|pc| (pc, fixed(pc)));
|
|
222
249
|
let ControlFlow::Continue(incoming) = dataflow::forward(listing, starts, |pc, path, frame| {
|
|
223
250
|
frame.begin();
|
|
224
251
|
let runs = fold::feasible(path, |term| frame.resolve(term));
|
|
@@ -256,9 +283,16 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
|
|
|
256
283
|
}
|
|
257
284
|
}
|
|
258
285
|
frame.follow(pc, &path.effects, evaluate, |frame, effect| {
|
|
259
|
-
// The probe creates its mark with `performance.mark(prefix + ray)`.
|
|
260
|
-
|
|
261
|
-
|
|
286
|
+
// The probe creates its mark with `performance.mark(prefix + ray)`. Some builds
|
|
287
|
+
// load the method well before calling it with its receiver.
|
|
288
|
+
if let Some((callee, [Term::Reg(argument)])) = effect.call()
|
|
289
|
+
&& match callee {
|
|
290
|
+
Term::Get(_, key) => is_text(frame, key, "mark"),
|
|
291
|
+
callee => matches!(
|
|
292
|
+
frame.resolve(callee),
|
|
293
|
+
Some(Known::Ext(Held::Member(name))) if name == "mark"
|
|
294
|
+
),
|
|
295
|
+
}
|
|
262
296
|
&& let Some(Known::Ext(Held::Prefixed(prefix))) = frame.register(*argument)
|
|
263
297
|
{
|
|
264
298
|
mark_prefix = Some(prefix.clone());
|
|
@@ -416,6 +450,9 @@ fn evaluate(frame: &Frame<Held>, term: &Term) -> Option<Known<Held>> {
|
|
|
416
450
|
Known::Ext(Held::Property(name))
|
|
417
451
|
}
|
|
418
452
|
(None, Some(Known::Literal(JsValue::String(name)))) => Known::Ext(Held::Field(name)),
|
|
453
|
+
(Some(Known::Ext(Held::Field(_))), Some(Known::Literal(JsValue::String(name)))) => {
|
|
454
|
+
Known::Ext(Held::Member(name))
|
|
455
|
+
}
|
|
419
456
|
_ => return None,
|
|
420
457
|
},
|
|
421
458
|
Term::Binary(BinaryOperator::Addition, left, _) => match frame.resolve(left)? {
|