cfsolve 0.1.3 → 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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +30 -5
  4. data/UPSTREAM.md +24 -3
  5. data/lib/cfsolve/profiles/safari-26-ios/answers.json +805 -797
  6. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
  7. data/lib/cfsolve/version.rb +2 -2
  8. data/lib/cfsolve.rb +21 -10
  9. data/vendor/cfsolve/examples/listing_dump.rs +24 -0
  10. data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
  11. data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
  12. data/vendor/cfsolve/examples/reread_capture.rs +31 -0
  13. data/vendor/cfsolve/examples/turnstile_smoke.rs +79 -0
  14. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
  15. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
  16. data/vendor/cfsolve/src/capture/sessions.rs +88 -4
  17. data/vendor/cfsolve/src/capture.rs +1 -0
  18. data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
  19. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
  20. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
  21. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
  22. data/vendor/cfsolve/src/embedding_page/extra_params.rs +3 -3
  23. data/vendor/cfsolve/src/embedding_page/page.rs +76 -65
  24. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +7 -4
  25. data/vendor/cfsolve/src/stage2/benchmark.rs +29 -8
  26. data/vendor/cfsolve/src/stage2/call_stack.rs +134 -95
  27. data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
  28. data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
  29. data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
  30. data/vendor/cfsolve/src/stage2/probes/stack.rs +41 -0
  31. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +11 -2
  32. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  33. data/vendor/cfsolve/src/stage2/reference.rs +70 -110
  34. data/vendor/cfsolve/src/stage2/registry.rs +4 -3
  35. data/vendor/cfsolve/src/stage2/trace.rs +1 -1
  36. data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
  37. data/vendor/cfsolve/src/vm/disassemble.rs +2 -1
  38. data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
  39. data/vendor/cfsolve/src/vm/extract.rs +205 -152
  40. data/vendor/cfsolve/src/vm/interpret/access.rs +0 -2
  41. data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
  42. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +30 -7
  43. data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
  44. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
  45. data/vendor/cfsolve/src/vm/interpret/pattern.rs +268 -67
  46. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +261 -30
  47. data/vendor/cfsolve/src/vm/machine.rs +14 -12
  48. data/vendor/cfsolve/src/vm/output.rs +4 -1
  49. data/vendor/cfsolve/src/vm/registers.rs +17 -23
  50. data/vendor/cfsolve/src/vm/session.rs +9 -4
  51. data/vendor/cfsolve/src/vm.rs +1 -0
  52. metadata +7 -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::stage2::reference::{
7
- PARENT_INFO_DIRECT, PARENT_INFO_FALLBACK, PARENT_INFO_MISSING, PARENT_INFO_PAD,
8
- PARENT_INFO_REASONS, PARENT_INFO_REFERRER, PARENT_INFO_VISIBILITY,
9
- };
10
-
11
- /// Copies the page's parent information: [`PARENT_INFO_DIRECT`] properties as they are,
12
- /// [`PARENT_INFO_FALLBACK`] properties with `""` for falsy values.
13
- #[must_use]
14
- pub(crate) fn collect(signals: &PageSignals) -> JsObject {
15
- let parent = &signals.parent;
16
- // The probe reads properties by their `api.js` names.
17
- let properties = json!(parent);
18
- let mut fields =
19
- JsObject::from_iter([(PARENT_INFO_REFERRER.to_owned(), json!(signals.referrer))]);
20
- for (field, property) in PARENT_INFO_DIRECT {
21
- if let Some(value) = properties.get(property) {
22
- fields.insert(field.to_owned(), value.clone());
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
- for (field, property) in PARENT_INFO_FALLBACK {
26
- let value = properties.get(property).filter(|value| js::truthy(value));
27
- fields.insert(
28
- field.to_owned(),
29
- value.cloned().unwrap_or_else(|| json!("")),
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
- pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<()> {
44
- let strings = &probe.strings;
45
- let outputs = [
46
- PARENT_INFO_REFERRER,
47
- PARENT_INFO_MISSING,
48
- PARENT_INFO_REASONS,
49
- PARENT_INFO_PAD,
50
- ];
51
- let markers = ["pi", "pg.ref", "vDuh", "vDrs", "visibilityState", "pad"];
52
- (strings.stores_all(&outputs) && strings.has_all(&markers)).then_some(())
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 copies_the_page_signals_by_their_api_js_names() {
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 record = collect(&page.signals(&layout, None));
76
- let field = |property: &str| {
77
- let (field, _) = PARENT_INFO_DIRECT
78
- .iter()
79
- .chain(&PARENT_INFO_FALLBACK)
80
- .find(|(_, read)| *read == property)
81
- .unwrap();
82
- &record[*field]
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
- *field("vDmd"),
89
- "",
90
- "a falsy fallback property reads as empty"
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
- let starts = entries.into_iter().map(|pc| (pc, Frame::default()));
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
- if let Some((Term::Get(_, key), [Term::Reg(argument)])) = effect.call()
261
- && is_text(frame, key, "mark")
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)? {
@@ -141,9 +141,25 @@ fn result_field(features: &[String], header: &BTreeSet<String>) -> Option<String
141
141
  None
142
142
  }
143
143
 
144
+ /// Finds the output field of a build with hex names whose `stack` the listing shows decoded (see
145
+ /// `vm::encoded_strings`): the one hex name besides the header's.
146
+ fn decoded_result_field(features: &[String], header: &BTreeSet<String>) -> Option<String> {
147
+ if !features.iter().any(|text| text == "stack") {
148
+ return None;
149
+ }
150
+ let names: BTreeSet<&String> = features
151
+ .iter()
152
+ .filter(|name| vocabulary::is_hex_name(name) && !header.contains(*name))
153
+ .collect();
154
+ candidates::exactly_one(names, "stack result field")
155
+ .ok()
156
+ .cloned()
157
+ }
158
+
144
159
  pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
145
160
  result_field(probe.session_features, probe.header)
146
161
  .or_else(|| encoded_result_field(probe.session_features, probe.header))
162
+ .or_else(|| decoded_result_field(probe.session_features, probe.header))
147
163
  .map(|result| Fields {
148
164
  result,
149
165
  calls: calls(probe.index, probe.entry),
@@ -174,6 +190,31 @@ mod tests {
174
190
  assert!(result_field(&[TABLES[0].to_owned()], &BTreeSet::new()).is_none());
175
191
  }
176
192
 
193
+ /// Decoded `stack` leaves the probe's own hex name as the only one besides the header's.
194
+ #[test]
195
+ fn reads_the_one_hex_name_beside_a_decoded_stack() {
196
+ let [wrapper, result, other] = [
197
+ "_04618571d62ea5518191ecc1",
198
+ "_0221887f312736bd3f6fc9f6",
199
+ "_23ca6c19266245a3e5b8a4c5",
200
+ ]
201
+ .map(str::to_owned);
202
+ let features = [
203
+ wrapper.clone(),
204
+ "atob".into(),
205
+ "stack".into(),
206
+ result.clone(),
207
+ other.clone(),
208
+ ];
209
+ let header = BTreeSet::from([wrapper.clone(), other.clone()]);
210
+ assert_eq!(decoded_result_field(&features, &header), Some(result));
211
+ assert!(decoded_result_field(&features, &BTreeSet::from([wrapper])).is_none());
212
+ assert!(
213
+ decoded_result_field(&features[3..], &header).is_none(),
214
+ "no `stack`"
215
+ );
216
+ }
217
+
177
218
  /// Names captured from c787ce48cf6b sessions with XOR keys 0x91 0xa2 and 0xff 0x75. The second
178
219
  /// key also decodes the plain string `this` to `ImS`, which must be excluded.
179
220
  #[test]
@@ -170,12 +170,21 @@ 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"]).or_else(|| before(&["String", "now"]))?,
173
+ // Builds that call `String` through the header's register leave out its name: the
174
+ // duration then sits between the round trips' `JSON.stringify` and `now`, and the
175
+ // timeout status before `round`.
176
+ elapsed: before(&["String", "Date", "now"])
177
+ .or_else(|| before(&["String", "now"]))
178
+ .or_else(|| {
179
+ let elapsed = find(&["JSON", "stringify"])? + 2;
180
+ (strings.get(elapsed + 1)? == "now").then(|| strings[elapsed].clone())
181
+ })?,
174
182
  statuses: Statuses {
175
183
  complete: complete.clone(),
176
184
  incomplete: incomplete.clone(),
177
185
  timed_out: before(&["String", "Math", "round"])
178
- .or_else(|| before(&["String", "round"]))?,
186
+ .or_else(|| before(&["String", "round"]))
187
+ .or_else(|| before(&["round"]))?,
179
188
  failed_before_open: failed_before_open.clone(),
180
189
  failed_after_open: failed_after_open.clone(),
181
190
  closed: closed.clone(),