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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +26 -6
  4. data/UPSTREAM.md +23 -8
  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 +22 -11
  9. data/vendor/cfsolve/README.md +5 -53
  10. data/vendor/cfsolve/examples/listing_dump.rs +24 -0
  11. data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
  12. data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
  13. data/vendor/cfsolve/examples/reread_capture.rs +31 -0
  14. data/vendor/cfsolve/examples/turnstile_smoke.rs +24 -3
  15. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
  16. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
  17. data/vendor/cfsolve/src/capture/sessions.rs +88 -4
  18. data/vendor/cfsolve/src/capture.rs +1 -0
  19. data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
  20. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
  21. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
  22. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
  23. data/vendor/cfsolve/src/embedding_page/extra_params.rs +10 -113
  24. data/vendor/cfsolve/src/embedding_page/page.rs +70 -99
  25. data/vendor/cfsolve/src/session/initial.rs +6 -7
  26. data/vendor/cfsolve/src/session/probes.rs +0 -1
  27. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +4 -33
  28. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +9 -17
  29. data/vendor/cfsolve/src/stage2/benchmark.rs +42 -62
  30. data/vendor/cfsolve/src/stage2/call_stack.rs +133 -227
  31. data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
  32. data/vendor/cfsolve/src/stage2/probes/dates.rs +0 -44
  33. data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
  34. data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
  35. data/vendor/cfsolve/src/stage2/probes/stack.rs +45 -117
  36. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +7 -76
  37. data/vendor/cfsolve/src/stage2/probes.rs +0 -1
  38. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  39. data/vendor/cfsolve/src/stage2/reference.rs +70 -115
  40. data/vendor/cfsolve/src/stage2/registry.rs +6 -11
  41. data/vendor/cfsolve/src/stage2/replay.rs +3 -34
  42. data/vendor/cfsolve/src/stage2/stylesheets.rs +0 -35
  43. data/vendor/cfsolve/src/stage2/trace.rs +1 -1
  44. data/vendor/cfsolve/src/stage2/vocabulary.rs +6 -111
  45. data/vendor/cfsolve/src/stage2.rs +0 -1
  46. data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
  47. data/vendor/cfsolve/src/vm/disassemble.rs +5 -68
  48. data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
  49. data/vendor/cfsolve/src/vm/extract.rs +193 -343
  50. data/vendor/cfsolve/src/vm/interpret/access.rs +2 -10
  51. data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
  52. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +28 -43
  53. data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
  54. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
  55. data/vendor/cfsolve/src/vm/interpret/pattern.rs +272 -100
  56. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +259 -36
  57. data/vendor/cfsolve/src/vm/interpret/run.rs +0 -4
  58. data/vendor/cfsolve/src/vm/machine.rs +14 -70
  59. data/vendor/cfsolve/src/vm/output.rs +3 -5
  60. data/vendor/cfsolve/src/vm/registers.rs +26 -46
  61. data/vendor/cfsolve/src/vm/session.rs +11 -9
  62. data/vendor/cfsolve/src/vm.rs +1 -1
  63. metadata +6 -12
  64. data/lib/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
  65. data/lib/cfsolve/profiles/chrome-157-macos.json +0 -613
  66. data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
  67. data/vendor/cfsolve/profiles/chrome-157-macos.json +0 -613
  68. data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +0 -1
  69. data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +0 -326
  70. data/vendor/cfsolve/src/stage2/value_labels.rs +0 -185
  71. data/vendor/cfsolve/src/vm/encoded_names.rs +0 -635
  72. data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +0 -9
  73. data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +0 -7438
  74. data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +0 -1
@@ -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::{Effect, Exit, Term};
14
+ use crate::vm::Term;
15
15
 
16
16
  #[derive(Clone, Debug, Deserialize, Serialize)]
17
17
  pub struct Fields {
@@ -61,50 +61,6 @@ 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
-
108
64
  /// Finds the output field hidden by base64 encoding and a two-byte XOR key. A name that decodes to
109
65
  /// `stack` identifies the key. The output field is the remaining name after excluding `stack` and
110
66
  /// the record counter from the header. Builds with hex names encode only `stack`.
@@ -185,87 +141,34 @@ fn result_field(features: &[String], header: &BTreeSet<String>) -> Option<String
185
141
  None
186
142
  }
187
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
+
188
159
  pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
189
- let calls = calls(probe.index, probe.entry);
190
160
  result_field(probe.session_features, probe.header)
191
161
  .or_else(|| encoded_result_field(probe.session_features, probe.header))
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()
162
+ .or_else(|| decoded_result_field(probe.session_features, probe.header))
163
+ .map(|result| Fields {
164
+ result,
165
+ calls: calls(probe.index, probe.entry),
205
166
  })
206
- .map(|result| Fields { result, calls })
207
167
  }
208
168
 
209
169
  #[cfg(test)]
210
170
  mod tests {
211
171
  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
- }
269
172
 
270
173
  /// String-table fixtures from `oct07` and `auto07`, with reversed entries, different
271
174
  /// separators, record counter `MpnR7`, and output `KtSk9` among checksums.
@@ -287,6 +190,31 @@ mod tests {
287
190
  assert!(result_field(&[TABLES[0].to_owned()], &BTreeSet::new()).is_none());
288
191
  }
289
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
+
290
218
  /// Names captured from c787ce48cf6b sessions with XOR keys 0x91 0xa2 and 0xff 0x75. The second
291
219
  /// key also decodes the plain string `this` to `ImS`, which must be excluded.
292
220
  #[test]
@@ -170,9 +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
+ // 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`.
173
176
  elapsed: before(&["String", "Date", "now"])
174
177
  .or_else(|| before(&["String", "now"]))
175
- .or_else(|| before(&["now"]))?,
178
+ .or_else(|| {
179
+ let elapsed = find(&["JSON", "stringify"])? + 2;
180
+ (strings.get(elapsed + 1)? == "now").then(|| strings[elapsed].clone())
181
+ })?,
176
182
  statuses: Statuses {
177
183
  complete: complete.clone(),
178
184
  incomplete: incomplete.clone(),
@@ -203,81 +209,6 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
203
209
  mod tests {
204
210
  use super::*;
205
211
 
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
-
281
212
  fn fields() -> Fields {
282
213
  Fields {
283
214
  platform: "ppebL7".into(),
@@ -12,7 +12,6 @@ pub(crate) mod image;
12
12
  pub(crate) mod media;
13
13
  pub(super) mod network_information;
14
14
  pub(super) mod parent_info;
15
- pub(super) mod parent_info_array;
16
15
  pub(crate) mod performance;
17
16
  mod platform;
18
17
  pub(crate) mod private_token;