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
|
@@ -21,14 +21,51 @@ use super::{HashMap, convert};
|
|
|
21
21
|
use crate::candidates;
|
|
22
22
|
use crate::js::ast::{self, Binding, Script};
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
pub
|
|
24
|
+
pub(super) struct MachineScope<'a> {
|
|
25
|
+
pub body: &'a FunctionBody<'a>,
|
|
26
|
+
pub class: &'a Class<'a>,
|
|
27
|
+
pub run: &'a Function<'a>,
|
|
28
|
+
/// Newer scripts pass the machine as the first argument of a free function.
|
|
29
|
+
pub machine: Option<SymbolId>,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Finds the installed VM runner and its class, either a `run` method or a free function,
|
|
33
|
+
/// in the innermost declaring function body.
|
|
34
|
+
pub(super) fn find<'a>(script: Script<'a>) -> Option<MachineScope<'a>> {
|
|
27
35
|
script
|
|
28
36
|
.functions()
|
|
29
37
|
.filter_map(|function| {
|
|
30
38
|
let body = function.body.as_deref()?;
|
|
31
|
-
|
|
39
|
+
let runner = body.statements.iter().find_map(installed_runner)?;
|
|
40
|
+
let Expression::Identifier(class_name) = runner.class else {
|
|
41
|
+
return None;
|
|
42
|
+
};
|
|
43
|
+
let class = body
|
|
44
|
+
.statements
|
|
45
|
+
.iter()
|
|
46
|
+
.find_map(|statement| match statement {
|
|
47
|
+
Statement::ClassDeclaration(class)
|
|
48
|
+
if class.id.as_ref().map(|id| id.symbol_id())
|
|
49
|
+
== script.symbol(class_name) =>
|
|
50
|
+
{
|
|
51
|
+
Some(&**class)
|
|
52
|
+
}
|
|
53
|
+
_ => None,
|
|
54
|
+
})?;
|
|
55
|
+
let (run, machine) = match runner.function {
|
|
56
|
+
Some(Expression::Identifier(name)) => {
|
|
57
|
+
let run = *functions(&body.statements).get(&script.symbol(name)?)?;
|
|
58
|
+
(run, Some(parameter(&run.params, 0)?.symbol_id()))
|
|
59
|
+
}
|
|
60
|
+
None => (method(class, "run")?, None),
|
|
61
|
+
_ => return None,
|
|
62
|
+
};
|
|
63
|
+
Some(MachineScope {
|
|
64
|
+
body,
|
|
65
|
+
class,
|
|
66
|
+
run,
|
|
67
|
+
machine,
|
|
68
|
+
})
|
|
32
69
|
})
|
|
33
70
|
.last()
|
|
34
71
|
}
|
|
@@ -127,6 +164,7 @@ pub(super) fn constructor<'a>(class: &'a Class<'a>) -> Result<&'a [Statement<'a>
|
|
|
127
164
|
/// What a `run` local holds.
|
|
128
165
|
#[derive(Clone)]
|
|
129
166
|
enum Source {
|
|
167
|
+
Machine,
|
|
130
168
|
Parameter(usize),
|
|
131
169
|
/// `this.<name>`.
|
|
132
170
|
Field(String),
|
|
@@ -140,6 +178,7 @@ enum Source {
|
|
|
140
178
|
|
|
141
179
|
/// Register layout and state setup recovered from `run`.
|
|
142
180
|
pub(super) struct RunMethod<'ast> {
|
|
181
|
+
pub access: super::registers::Access<'ast>,
|
|
143
182
|
/// Field containing the register file. Fields on that file identify the program counter and
|
|
144
183
|
/// dispatch key registers.
|
|
145
184
|
pub registers: String,
|
|
@@ -181,6 +220,7 @@ impl DispatchLoop<'_> {
|
|
|
181
220
|
struct Locals<'a> {
|
|
182
221
|
script: Script<'a>,
|
|
183
222
|
sources: HashMap<Binding<'a>, Source>,
|
|
223
|
+
free: bool,
|
|
184
224
|
}
|
|
185
225
|
|
|
186
226
|
/// Tracks assignments in `run`, including copies of register fields and indices, program counter
|
|
@@ -190,17 +230,38 @@ pub(super) fn run_method<'a>(
|
|
|
190
230
|
script: Script<'a>,
|
|
191
231
|
functions: &HashMap<SymbolId, &'a Function<'a>>,
|
|
192
232
|
run: &'a Function<'a>,
|
|
233
|
+
machine: Option<SymbolId>,
|
|
193
234
|
) -> Result<RunMethod<'a>> {
|
|
194
235
|
let body = run.body.as_deref().context("the run method has no body")?;
|
|
195
236
|
let sources = (0..run.params.items.len())
|
|
196
237
|
.filter_map(|index| {
|
|
197
238
|
let name = parameter(&run.params, index)?;
|
|
198
|
-
Some(
|
|
239
|
+
let source = if machine == Some(name.symbol_id()) {
|
|
240
|
+
Source::Machine
|
|
241
|
+
} else {
|
|
242
|
+
Source::Parameter(index - usize::from(machine.is_some()))
|
|
243
|
+
};
|
|
244
|
+
Some((Binding::Symbol(name.symbol_id()), source))
|
|
199
245
|
})
|
|
200
246
|
.collect();
|
|
201
|
-
let mut locals = Locals {
|
|
247
|
+
let mut locals = Locals {
|
|
248
|
+
script,
|
|
249
|
+
sources,
|
|
250
|
+
free: machine.is_some(),
|
|
251
|
+
};
|
|
202
252
|
let mut cells = None;
|
|
203
253
|
let mut loaded = Vec::new();
|
|
254
|
+
let mut reader = None;
|
|
255
|
+
let mut writer = None;
|
|
256
|
+
let function = |expression: &Expression<'a>| {
|
|
257
|
+
let Expression::CallExpression(call) = expression else {
|
|
258
|
+
return None;
|
|
259
|
+
};
|
|
260
|
+
let Expression::Identifier(callee) = &call.callee else {
|
|
261
|
+
return None;
|
|
262
|
+
};
|
|
263
|
+
functions.get(&script.symbol(callee)?).copied()
|
|
264
|
+
};
|
|
204
265
|
for statement in &body.statements {
|
|
205
266
|
let Statement::ExpressionStatement(statement) = statement else {
|
|
206
267
|
continue;
|
|
@@ -215,6 +276,7 @@ pub(super) fn run_method<'a>(
|
|
|
215
276
|
&& let [Some(Source::Field(index)), Some(Source::Parameter(2))] = &arguments[..]
|
|
216
277
|
{
|
|
217
278
|
cells = Some((registers, index.clone()));
|
|
279
|
+
writer = function(expression);
|
|
218
280
|
continue;
|
|
219
281
|
}
|
|
220
282
|
let Expression::AssignmentExpression(assignment) = expression else {
|
|
@@ -229,6 +291,7 @@ pub(super) fn run_method<'a>(
|
|
|
229
291
|
};
|
|
230
292
|
if let Some(Source::Register { registers, index }) = &value {
|
|
231
293
|
loaded.push((registers.clone(), index.clone()));
|
|
294
|
+
reader = function(&assignment.right);
|
|
232
295
|
}
|
|
233
296
|
let binding = script.binding(name);
|
|
234
297
|
match value {
|
|
@@ -252,6 +315,7 @@ pub(super) fn run_method<'a>(
|
|
|
252
315
|
let mut calls = DispatchCall {
|
|
253
316
|
script,
|
|
254
317
|
functions,
|
|
318
|
+
machine,
|
|
255
319
|
found: None,
|
|
256
320
|
};
|
|
257
321
|
calls.visit_function_body(body);
|
|
@@ -264,6 +328,7 @@ pub(super) fn run_method<'a>(
|
|
|
264
328
|
.map(|argument| match ast::argument_expression(argument) {
|
|
265
329
|
Expression::ThisExpression(_) => Argument::Machine,
|
|
266
330
|
Expression::Identifier(name) => match locals.sources.get(&script.binding(name)) {
|
|
331
|
+
Some(Source::Machine) => Argument::Machine,
|
|
267
332
|
Some(Source::Field(field)) if *field == registers => Argument::Registers,
|
|
268
333
|
Some(Source::Register { index, .. }) if *index == program => Argument::Program,
|
|
269
334
|
_ => Argument::Other,
|
|
@@ -272,6 +337,14 @@ pub(super) fn run_method<'a>(
|
|
|
272
337
|
})
|
|
273
338
|
.collect();
|
|
274
339
|
Ok(RunMethod {
|
|
340
|
+
access: if machine.is_some() {
|
|
341
|
+
super::registers::Access::Functions {
|
|
342
|
+
read: reader.context("the free VM runner has no register reader")?,
|
|
343
|
+
write: writer.context("the free VM runner has no register writer")?,
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
super::registers::Access::Methods
|
|
347
|
+
},
|
|
275
348
|
registers,
|
|
276
349
|
cells,
|
|
277
350
|
program,
|
|
@@ -287,6 +360,7 @@ pub(super) fn run_method<'a>(
|
|
|
287
360
|
struct DispatchCall<'functions, 'a> {
|
|
288
361
|
script: Script<'a>,
|
|
289
362
|
functions: &'functions HashMap<SymbolId, &'a Function<'a>>,
|
|
363
|
+
machine: Option<SymbolId>,
|
|
290
364
|
found: Option<(&'a Function<'a>, &'a CallExpression<'a>)>,
|
|
291
365
|
}
|
|
292
366
|
|
|
@@ -294,10 +368,11 @@ impl<'a> Visit<'a> for DispatchCall<'_, 'a> {
|
|
|
294
368
|
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
295
369
|
if self.found.is_none()
|
|
296
370
|
&& call.arguments.first().is_some_and(|first| {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
371
|
+
let first = ast::argument_expression(first);
|
|
372
|
+
matches!(first, Expression::ThisExpression(_))
|
|
373
|
+
|| self
|
|
374
|
+
.machine
|
|
375
|
+
.is_some_and(|machine| self.script.refers_to(first, machine))
|
|
301
376
|
})
|
|
302
377
|
&& let Expression::Identifier(callee) = &call.callee
|
|
303
378
|
&& let Some(symbol) = self.script.symbol(callee)
|
|
@@ -321,7 +396,21 @@ impl<'a> Locals<'a> {
|
|
|
321
396
|
expression: &Expression<'a>,
|
|
322
397
|
name: &str,
|
|
323
398
|
) -> Option<(Source, Vec<Option<Source>>)> {
|
|
324
|
-
let (object, arguments) = ast::method_call(expression, name)
|
|
399
|
+
let (object, arguments) = if let Some(call) = ast::method_call(expression, name) {
|
|
400
|
+
call
|
|
401
|
+
} else if self.free
|
|
402
|
+
&& let Expression::CallExpression(call) = expression
|
|
403
|
+
{
|
|
404
|
+
let [object, arguments @ ..] = &call.arguments[..] else {
|
|
405
|
+
return None;
|
|
406
|
+
};
|
|
407
|
+
if arguments.len() != if name == "read" { 1 } else { 2 } {
|
|
408
|
+
return None;
|
|
409
|
+
}
|
|
410
|
+
(ast::argument_expression(object), arguments)
|
|
411
|
+
} else {
|
|
412
|
+
return None;
|
|
413
|
+
};
|
|
325
414
|
let arguments = arguments
|
|
326
415
|
.iter()
|
|
327
416
|
.map(|argument| self.source(ast::argument_expression(argument)))
|
|
@@ -332,6 +421,7 @@ impl<'a> Locals<'a> {
|
|
|
332
421
|
fn source(&self, expression: &Expression<'a>) -> Option<Source> {
|
|
333
422
|
match expression {
|
|
334
423
|
Expression::Identifier(name) => self.sources.get(&self.script.binding(name)).cloned(),
|
|
424
|
+
Expression::ThisExpression(_) => Some(Source::Machine),
|
|
335
425
|
Expression::ParenthesizedExpression(paren) => self.source(&paren.expression),
|
|
336
426
|
Expression::CallExpression(_) => match self.method_call(expression, "read")? {
|
|
337
427
|
(Source::Field(registers), arguments) => match &arguments[..] {
|
|
@@ -343,7 +433,11 @@ impl<'a> Locals<'a> {
|
|
|
343
433
|
},
|
|
344
434
|
_ => None,
|
|
345
435
|
},
|
|
346
|
-
expression =>
|
|
436
|
+
expression => {
|
|
437
|
+
let member = expression.as_member_expression()?;
|
|
438
|
+
matches!(self.source(member.object()), Some(Source::Machine))
|
|
439
|
+
.then(|| ast::member_str(member).map(|name| Source::Field(name.to_owned())))?
|
|
440
|
+
}
|
|
347
441
|
}
|
|
348
442
|
}
|
|
349
443
|
}
|
|
@@ -362,11 +456,14 @@ pub(super) fn this_field<'a>(expression: &Expression<'a>) -> Option<&'a str> {
|
|
|
362
456
|
pub(super) fn record_decoder<'a>(
|
|
363
457
|
script: Script<'a>,
|
|
364
458
|
body: &'a FunctionBody<'a>,
|
|
459
|
+
access: super::registers::Access<'a>,
|
|
365
460
|
) -> Option<SymbolId> {
|
|
366
461
|
/// Matches `<decoder>(this.<values>[<index>])`.
|
|
367
462
|
struct Decoders<'a> {
|
|
368
463
|
script: Script<'a>,
|
|
369
464
|
index: SymbolId,
|
|
465
|
+
object: Option<SymbolId>,
|
|
466
|
+
access: super::registers::Access<'a>,
|
|
370
467
|
found: Vec<Binding<'a>>,
|
|
371
468
|
}
|
|
372
469
|
|
|
@@ -378,7 +475,14 @@ pub(super) fn record_decoder<'a>(
|
|
|
378
475
|
&& member
|
|
379
476
|
.object()
|
|
380
477
|
.as_member_expression()
|
|
381
|
-
.is_some_and(|values|
|
|
478
|
+
.is_some_and(|values| {
|
|
479
|
+
matches!(values.object(), Expression::ThisExpression(_))
|
|
480
|
+
|| (self.object.is_some_and(|object| {
|
|
481
|
+
self.script.refers_to(values.object(), object)
|
|
482
|
+
}) && ast::member_str(values)
|
|
483
|
+
.and_then(|name| self.access.member(name))
|
|
484
|
+
== Some(super::registers::Member::Values))
|
|
485
|
+
})
|
|
382
486
|
&& let MemberExpression::ComputedMemberExpression(member) = member
|
|
383
487
|
&& self.script.refers_to(&member.expression, self.index)
|
|
384
488
|
{
|
|
@@ -388,37 +492,39 @@ pub(super) fn record_decoder<'a>(
|
|
|
388
492
|
}
|
|
389
493
|
}
|
|
390
494
|
|
|
391
|
-
let read =
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
495
|
+
let (read, object, index) = match access {
|
|
496
|
+
super::registers::Access::Methods => {
|
|
497
|
+
let read = body
|
|
498
|
+
.statements
|
|
499
|
+
.iter()
|
|
500
|
+
.find_map(|statement| match statement {
|
|
501
|
+
Statement::ClassDeclaration(class) if method(class, "write").is_some() => {
|
|
502
|
+
method(class, "read")
|
|
503
|
+
}
|
|
504
|
+
_ => None,
|
|
505
|
+
})?;
|
|
506
|
+
(read, None, 0)
|
|
507
|
+
}
|
|
508
|
+
super::registers::Access::Functions { read, .. } => {
|
|
509
|
+
(read, Some(parameter(&read.params, 0)?.symbol_id()), 1)
|
|
510
|
+
}
|
|
511
|
+
};
|
|
400
512
|
let mut decoders = Decoders {
|
|
401
513
|
script,
|
|
402
|
-
|
|
514
|
+
object,
|
|
515
|
+
access,
|
|
516
|
+
index: parameter(&read.params, index)?.symbol_id(),
|
|
403
517
|
found: Vec::new(),
|
|
404
518
|
};
|
|
405
519
|
decoders.visit_function(read, ScopeFlags::Function);
|
|
520
|
+
decoders.found.sort();
|
|
521
|
+
decoders.found.dedup();
|
|
406
522
|
let [Binding::Symbol(decoder)] = decoders.found[..] else {
|
|
407
523
|
return None;
|
|
408
524
|
};
|
|
409
525
|
Some(decoder)
|
|
410
526
|
}
|
|
411
527
|
|
|
412
|
-
/// The first class declaration with a `run` method.
|
|
413
|
-
fn machine_class<'a>(body: &'a FunctionBody<'a>) -> Option<&'a Class<'a>> {
|
|
414
|
-
body.statements
|
|
415
|
-
.iter()
|
|
416
|
-
.find_map(|statement| match statement {
|
|
417
|
-
Statement::ClassDeclaration(class) if method(class, "run").is_some() => Some(&**class),
|
|
418
|
-
_ => None,
|
|
419
|
-
})
|
|
420
|
-
}
|
|
421
|
-
|
|
422
528
|
/// The method, getter, or setter named `name`, excluding the constructor.
|
|
423
529
|
pub(super) fn method<'a>(class: &'a Class<'a>, name: &str) -> Option<&'a Function<'a>> {
|
|
424
530
|
class.body.body.iter().find_map(|element| match element {
|
|
@@ -510,13 +616,7 @@ pub(super) fn entry(body: &FunctionBody<'_>) -> Result<Position> {
|
|
|
510
616
|
let runner = body
|
|
511
617
|
.statements
|
|
512
618
|
.iter()
|
|
513
|
-
.find_map(
|
|
514
|
-
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
515
|
-
Expression::AssignmentExpression(assignment) => Runner::installed_by(assignment),
|
|
516
|
-
_ => None,
|
|
517
|
-
},
|
|
518
|
-
_ => None,
|
|
519
|
-
})
|
|
619
|
+
.find_map(installed_runner)
|
|
520
620
|
.context("no program runner in the VM's scope")?;
|
|
521
621
|
let pc = convert::position(runner.pc).context("the runner starts at no program position")?;
|
|
522
622
|
let key = convert::byte(runner.key).context("the runner starts with no dispatch key")?;
|
|
@@ -532,10 +632,22 @@ struct Runner<'ast> {
|
|
|
532
632
|
pc: f64,
|
|
533
633
|
/// Initial dispatch key from the source.
|
|
534
634
|
key: f64,
|
|
635
|
+
class: &'ast Expression<'ast>,
|
|
636
|
+
function: Option<&'ast Expression<'ast>>,
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
fn installed_runner<'a>(statement: &'a Statement<'a>) -> Option<Runner<'a>> {
|
|
640
|
+
let Statement::ExpressionStatement(statement) = statement else {
|
|
641
|
+
return None;
|
|
642
|
+
};
|
|
643
|
+
let Expression::AssignmentExpression(assignment) = &statement.expression else {
|
|
644
|
+
return None;
|
|
645
|
+
};
|
|
646
|
+
Runner::installed_by(assignment)
|
|
535
647
|
}
|
|
536
648
|
|
|
537
649
|
impl<'ast> Runner<'ast> {
|
|
538
|
-
fn installed_by(assignment: &AssignmentExpression<'ast>) -> Option<Self> {
|
|
650
|
+
fn installed_by(assignment: &'ast AssignmentExpression<'ast>) -> Option<Self> {
|
|
539
651
|
let target = assignment.left.as_member_expression()?;
|
|
540
652
|
if matches!(target.object(), Expression::Super(_)) {
|
|
541
653
|
return None;
|
|
@@ -551,11 +663,27 @@ impl<'ast> Runner<'ast> {
|
|
|
551
663
|
else {
|
|
552
664
|
return None;
|
|
553
665
|
};
|
|
554
|
-
let
|
|
666
|
+
let expression = returned.argument.as_ref()?;
|
|
667
|
+
let (machine, arguments, function) =
|
|
668
|
+
if let Some((machine, arguments)) = ast::method_call(expression, "run") {
|
|
669
|
+
(machine, arguments, None)
|
|
670
|
+
} else if let Expression::CallExpression(call) = expression {
|
|
671
|
+
let [machine, arguments @ ..] = &call.arguments[..] else {
|
|
672
|
+
return None;
|
|
673
|
+
};
|
|
674
|
+
(
|
|
675
|
+
ast::argument_expression(machine),
|
|
676
|
+
arguments,
|
|
677
|
+
Some(&call.callee),
|
|
678
|
+
)
|
|
679
|
+
} else {
|
|
680
|
+
return None;
|
|
681
|
+
};
|
|
682
|
+
let [pc, key, ..] = arguments else {
|
|
555
683
|
return None;
|
|
556
684
|
};
|
|
557
685
|
let (
|
|
558
|
-
Expression::NewExpression(
|
|
686
|
+
Expression::NewExpression(new),
|
|
559
687
|
Expression::NumericLiteral(pc),
|
|
560
688
|
Expression::NumericLiteral(key),
|
|
561
689
|
) = (
|
|
@@ -570,6 +698,8 @@ impl<'ast> Runner<'ast> {
|
|
|
570
698
|
name: ast::member_str(target)?,
|
|
571
699
|
pc: pc.value,
|
|
572
700
|
key: key.value,
|
|
701
|
+
class: &new.callee,
|
|
702
|
+
function,
|
|
573
703
|
})
|
|
574
704
|
}
|
|
575
705
|
}
|
|
@@ -628,6 +758,7 @@ mod tests {
|
|
|
628
758
|
for source in [
|
|
629
759
|
"function f(O) { O.vlJM8 = function(p) { return new M(p).run(0, 238, []); }; }",
|
|
630
760
|
"function f(O) { O.vlJM8 = function(p) { var a; var b, c; return new M(p).run(0, 238, []); }; }",
|
|
761
|
+
"function f(O) { O.vlJM8 = function(p) { return execute(new M(p), 0, 238, []); }; }",
|
|
631
762
|
] {
|
|
632
763
|
assert_eq!(entry_of(source).unwrap(), Position::new(0, 238), "{source}");
|
|
633
764
|
}
|
|
@@ -638,6 +769,78 @@ mod tests {
|
|
|
638
769
|
);
|
|
639
770
|
}
|
|
640
771
|
|
|
772
|
+
#[test]
|
|
773
|
+
fn extracts_free_runner_and_register_helpers_by_binding() {
|
|
774
|
+
let parsed = ParsedScript::parse("moved VM", r#"
|
|
775
|
+
function scope(global) {
|
|
776
|
+
class Unrelated { run() {} }
|
|
777
|
+
class Registers { constructor() {} }
|
|
778
|
+
class Machine { constructor(program) {} }
|
|
779
|
+
function load(registers, index) { return registers.H[index]; }
|
|
780
|
+
function store(registers, index, value) { registers.H[index] = value; }
|
|
781
|
+
function opcode(machine) {}
|
|
782
|
+
function dispatch(machine, registers, pending, program) {
|
|
783
|
+
while (true) { switch (program[0]) { case 42: opcode(machine); break; } }
|
|
784
|
+
}
|
|
785
|
+
function execute(machine, pc, key, cells) {
|
|
786
|
+
var registers, index, program;
|
|
787
|
+
registers = machine.registers;
|
|
788
|
+
index = machine.cells;
|
|
789
|
+
store(registers, index, cells);
|
|
790
|
+
index = machine.program;
|
|
791
|
+
program = load(registers, index);
|
|
792
|
+
dispatch(machine, registers, null, program);
|
|
793
|
+
}
|
|
794
|
+
global.start = function(program) { return execute(new Machine(program), 0, 231, []); };
|
|
795
|
+
}
|
|
796
|
+
"#).unwrap();
|
|
797
|
+
let script = parsed.script();
|
|
798
|
+
assert_eq!(runner_name(script).as_deref(), Some("start"));
|
|
799
|
+
let found = find(script).unwrap();
|
|
800
|
+
assert_eq!(found.class.id.as_ref().unwrap().name, "Machine");
|
|
801
|
+
assert_eq!(entry(found.body).unwrap(), Position::new(0, 231));
|
|
802
|
+
let functions = functions(&found.body.statements);
|
|
803
|
+
let layout = run_method(script, &functions, found.run, found.machine).unwrap();
|
|
804
|
+
assert_eq!(
|
|
805
|
+
(&*layout.registers, &*layout.cells, &*layout.program),
|
|
806
|
+
("registers", "cells", "program")
|
|
807
|
+
);
|
|
808
|
+
let super::super::registers::Access::Functions { read, write } = layout.access else {
|
|
809
|
+
panic!("expected free register accessors");
|
|
810
|
+
};
|
|
811
|
+
assert_eq!(read.id.as_ref().unwrap().name, "load");
|
|
812
|
+
assert_eq!(write.id.as_ref().unwrap().name, "store");
|
|
813
|
+
assert_eq!(
|
|
814
|
+
layout.dispatch.arguments,
|
|
815
|
+
vec![
|
|
816
|
+
Argument::Machine,
|
|
817
|
+
Argument::Registers,
|
|
818
|
+
Argument::Other,
|
|
819
|
+
Argument::Program
|
|
820
|
+
]
|
|
821
|
+
);
|
|
822
|
+
let handlers = handlers(script, &functions, &layout.dispatch).unwrap();
|
|
823
|
+
assert_eq!(handlers[&42].id.as_ref().unwrap().name, "opcode");
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
#[test]
|
|
827
|
+
fn method_runner_selects_its_constructed_class() {
|
|
828
|
+
let parsed = ParsedScript::parse(
|
|
829
|
+
"two classes",
|
|
830
|
+
r#"
|
|
831
|
+
function scope(global) {
|
|
832
|
+
class Unrelated { run() {} }
|
|
833
|
+
class Machine { run() {} }
|
|
834
|
+
global.start = function(program) { return new Machine(program).run(0, 1, []); };
|
|
835
|
+
}
|
|
836
|
+
"#,
|
|
837
|
+
)
|
|
838
|
+
.unwrap();
|
|
839
|
+
let found = find(parsed.script()).unwrap();
|
|
840
|
+
assert_eq!(found.class.id.as_ref().unwrap().name, "Machine");
|
|
841
|
+
assert!(found.machine.is_none());
|
|
842
|
+
}
|
|
843
|
+
|
|
641
844
|
#[test]
|
|
642
845
|
fn names_the_runner_its_callers_call() {
|
|
643
846
|
let parsed = ParsedScript::parse(
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
This fixture is the isolated VM scope and initial bytecode from Cloudflare build
|
|
2
|
+
`7c7fee70a876`, served by the public Hellenic Heritage sign-in page on 2026-11-12.
|
|
3
|
+
It excludes the page, challenge options, session URLs, request/response payloads,
|
|
4
|
+
credentials and solved tokens. `machine.js` retains its public deobfuscated VM
|
|
5
|
+
scope and only the global aliases that scope needs.
|
|
6
|
+
|
|
7
|
+
The unmodified solver cannot find its runner. The regression checks the complete
|
|
8
|
+
initial disassembly, exercising free register reads, writes, saves, field layout,
|
|
9
|
+
dispatch, string decryption and both normal and exceptional handler paths.
|